♻️ Return Entry instead map after creation

This commit is contained in:
Maxim Lebedev 2023-09-29 13:05:24 +06:00
parent 4ca6dc7f9f
commit 9240cd15cb
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 6 additions and 12 deletions

View File

@ -266,17 +266,11 @@ func (h *Handler) handleCreate(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set(common.HeaderLocation, out["self"].String())
if len(out)-1 <= 0 {
w.WriteHeader(http.StatusCreated)
return
}
w.Header().Set(common.HeaderLocation, out.URL.String())
links := make([]string, 0)
for rel, value := range out {
links = append(links, `<`+value.String()+`>; rel="`+rel+`"`)
for i := range out.Syndications {
links = append(links, `<`+out.Syndications[i].String()+`>; rel="syndication"`)
}
w.Header().Set(common.HeaderLink, strings.Join(links, ", "))

View File

@ -11,7 +11,7 @@ type (
UseCase interface {
// Create creates a new entry. Returns map or rel links, like Permalink
// or created post, shortcode and syndication.
Create(ctx context.Context, e domain.Entry) (map[string]*url.URL, error)
Create(ctx context.Context, e domain.Entry) (*domain.Entry, error)
// Update updates exist entry properties on provided u.
//
@ -61,8 +61,8 @@ func NewStubUseCase(err error, e *domain.Entry, ok bool) *stubUseCase {
}
}
func (ucase *stubUseCase) Create(ctx context.Context, e domain.Entry) (map[string]*url.URL, error) {
return map[string]*url.URL{"self": ucase.entry.URL}, ucase.err
func (ucase *stubUseCase) Create(ctx context.Context, e domain.Entry) (*domain.Entry, error) {
return ucase.entry, ucase.err
}
func (ucase *stubUseCase) Update(ctx context.Context, u *url.URL, e domain.Entry) (*domain.Entry, error) {