From 9240cd15cb16d31aefe63b26dcc2c86a46fd653b Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Fri, 29 Sep 2023 13:05:24 +0600 Subject: [PATCH] :recycle: Return Entry instead map after creation --- internal/entry/delivery/http/entry_http.go | 12 +++--------- internal/entry/usecase.go | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/internal/entry/delivery/http/entry_http.go b/internal/entry/delivery/http/entry_http.go index d4ea83d..1411b86 100644 --- a/internal/entry/delivery/http/entry_http.go +++ b/internal/entry/delivery/http/entry_http.go @@ -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, ", ")) diff --git a/internal/entry/usecase.go b/internal/entry/usecase.go index 79850b2..3d759e9 100644 --- a/internal/entry/usecase.go +++ b/internal/entry/usecase.go @@ -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) {