From 0effdea072f79b7452da082d85e788d2d6d2fc74 Mon Sep 17 00:00:00 2001 From: Yonathan Setiadi Date: Thu, 3 Jun 2021 10:21:20 +0700 Subject: [PATCH 1/5] #45 use admin as default and update request validation on endpoint --- endpoint/request.go | 10 +++++----- transport/http/handler.go | 1 - usecase/usecase.go | 1 + 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/endpoint/request.go b/endpoint/request.go index bd6e731..cd529db 100644 --- a/endpoint/request.go +++ b/endpoint/request.go @@ -48,21 +48,21 @@ func Validate(in interface{}) error { var err error if obj, ok := in.(*CreateNewPostRequest); ok { err = validation.ValidateStruct(in, - validation.Field(&obj.Title, validation.Required, validation.Length(0, 10)), - validation.Field(obj.Images, validation.Required, validation.By(validationImages(obj.Images))), + validation.Field(&obj.Title, validation.Required, validation.Length(10, 0)), + validation.Field(&obj.Images, validation.Required, validation.By(validationImages(obj.Images))), validation.Field(&obj.Tags, validation.Required), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } else if obj, ok := in.(*UpdateStatusOrTitle); ok { err = validation.ValidateStruct(in, validation.Field(obj.ID, validation.Required), - validation.Field(&obj.Title, validation.Required, validation.Length(0, 10)), + validation.Field(&obj.Title, validation.Required, validation.Length(10, 0)), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } else if obj, ok := in.(*CreateCommentRequest); ok { err = validation.ValidateStruct(in, validation.Field(obj.UserPostID, validation.Required), - validation.Field(obj.Comment, validation.Required, validation.Length(0, 10)), + validation.Field(obj.Comment, validation.Required, validation.Length(10, 0)), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } @@ -75,7 +75,7 @@ func validationImages(in []*Image) validation.RuleFunc { images := value.([]*Image) for _, v := range images { err = validation.ValidateStruct(v, - validation.Field(v.Path, is.URL), + validation.Field(&v.Path, is.URL), ) } return err diff --git a/transport/http/handler.go b/transport/http/handler.go index d2aee74..0efb197 100644 --- a/transport/http/handler.go +++ b/transport/http/handler.go @@ -100,7 +100,6 @@ func decodeCreatePost(ctx context.Context, r *http.Request) (interface{}, error) if err := json.NewDecoder(r.Body).Decode(reqBody); err != nil { return nil, err } - return reqBody, nil } diff --git a/usecase/usecase.go b/usecase/usecase.go index fcebf3c..a4589b0 100644 --- a/usecase/usecase.go +++ b/usecase/usecase.go @@ -164,6 +164,7 @@ func (p *Post) CreateNewPost(ctx context.Context, requestBody *model.CreateNewPo Tags: requestBody.Tags, Status: requestBody.Status, // ActorID: actor["id"].(int64), + ActorID: 1, // for now use default as admin }); err != nil { level.Error(logger).Log("error_create_post", err) return err From 180dacdd520560ca1b31fc0899941774b9b4c0e8 Mon Sep 17 00:00:00 2001 From: Yonathan Setiadi Date: Thu, 3 Jun 2021 10:41:55 +0700 Subject: [PATCH 2/5] #45 update response body for created by and updated by on comments --- mocks/testcases/get-list-user-post.go | 4 ++-- mocks/testcases/get_comments.go | 8 ++++---- model/usecase_response.go | 14 +++++++------- usecase/parser.go | 4 ++-- usecase/usecase.go | 8 +++++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/mocks/testcases/get-list-user-post.go b/mocks/testcases/get-list-user-post.go index dfbdde0..a496586 100644 --- a/mocks/testcases/get-list-user-post.go +++ b/mocks/testcases/get-list-user-post.go @@ -153,8 +153,8 @@ var ( Text: commentResponse.Comment, CreatedAt: commentResponse.CreatedAt, UpdatedAt: commentResponse.UpdatedAt, - CreatedBy: actorResponse, - UpdatedBy: actorResponse, + CreatedBy: actor, + UpdatedBy: actor, } totalComment = helper.SetPointerInt64(1) userPostResponse = []*model.UserPostResponse{ diff --git a/mocks/testcases/get_comments.go b/mocks/testcases/get_comments.go index 002264b..ef42c59 100644 --- a/mocks/testcases/get_comments.go +++ b/mocks/testcases/get_comments.go @@ -53,16 +53,16 @@ var ( Text: "comment", CreatedAt: current, UpdatedAt: current, - CreatedBy: actorResponse, - UpdatedBy: actorResponse, + CreatedBy: actor, + UpdatedBy: actor, }, { ID: 2, UserPostID: 1, Text: "ini juga comment", CreatedAt: current, UpdatedAt: current, - CreatedBy: actorResponse, - UpdatedBy: actorResponse, + CreatedBy: actor, + UpdatedBy: actor, }, } ) diff --git a/model/usecase_response.go b/model/usecase_response.go index 50b1e76..b3d1333 100644 --- a/model/usecase_response.go +++ b/model/usecase_response.go @@ -33,13 +33,13 @@ type Metadata struct { } type Comment struct { - ID int64 `json:"id"` - UserPostID int64 `json:"user_post_id"` - Text string `json:"comment"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - CreatedBy *UserResponse `json:"created_by"` - UpdatedBy *UserResponse `json:"updated_by"` + ID int64 `json:"id"` + UserPostID int64 `json:"user_post_id"` + Text string `json:"comment"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + CreatedBy *Actor `json:"created_by"` + UpdatedBy *Actor `json:"updated_by"` } type Actor struct { diff --git a/usecase/parser.go b/usecase/parser.go index 099295a..9722306 100644 --- a/usecase/parser.go +++ b/usecase/parser.go @@ -77,13 +77,13 @@ func (p *Post) getDetailComment(ctx context.Context, comment *model.CommentRespo level.Error(logger).Log("error_get_actor_created", err) return nil, err } - commentResp.CreatedBy = actorCreated + commentResp.CreatedBy = p.parsingUserResponse(ctx, actorCreated) actorUpdated, err := p.repoPost.GetActor(ctx, comment.UpdatedBy) if err != nil { level.Error(logger).Log("error_get_actor_updated", err) return nil, err } - commentResp.UpdatedBy = actorUpdated + commentResp.UpdatedBy = p.parsingUserResponse(ctx, actorUpdated) return commentResp, nil } diff --git a/usecase/usecase.go b/usecase/usecase.go index a4589b0..9a0b786 100644 --- a/usecase/usecase.go +++ b/usecase/usecase.go @@ -28,7 +28,6 @@ func NewPost(repoPost repository.PostI, repoComment repository.CommentI, logger func (p *Post) GetListPost(ctx context.Context, params *model.GetListRequest) (*model.UserPostWithMetadata, error) { logger := kitlog.With(p.logger, "method", "GetListPost") var limit, offset int64 = 10, 0 - if params.Page != nil && params.Limit != nil { limit = helper.GetInt64FromPointer(params.Limit) offset = (helper.GetInt64FromPointer(params.Page) - 1) * limit @@ -56,16 +55,19 @@ func (p *Post) GetListPost(ctx context.Context, params *model.GetListRequest) (* level.Error(logger).Log("error_append_list", err) return nil, err } - total, err := p.repoPost.GetMetadataPost(ctx, req) if err != nil { level.Error(logger).Log("error_get_metadata", err) return nil, err } + offsetPage := helper.GetInt64FromPointer(total) % limit + if offsetPage > 0 { + offsetPage = 1 + } metadata := &model.Metadata{ Page: helper.GetInt64FromPointer(params.Page), - TotalPage: helper.GetInt64FromPointer(total) / limit, + TotalPage: helper.GetInt64FromPointer(total)/limit + offsetPage, Total: helper.GetInt64FromPointer(total), } From 86d93d1db9e1e9e4caa42ff94906ec24cc04fa79 Mon Sep 17 00:00:00 2001 From: Yonathan Setiadi Date: Thu, 3 Jun 2021 11:40:09 +0700 Subject: [PATCH 3/5] #45 upgrade unit test --- endpoint/endpoint.go | 1 + endpoint/request.go | 6 +++--- mocks/testcases/create-new-post.go | 2 +- mocks/testcases/get-list-user-post.go | 3 ++- model/repository_request.go | 1 + model/usecase_request.go | 1 + repository/mysql/comment.go | 5 +++-- usecase/usecase.go | 7 +++++-- usecase/usecase_test.go | 1 + 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 8b87e7a..9ab5109 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -149,6 +149,7 @@ func MakeCreateComment(ctx context.Context, usecase usecase.UsecaseI) endpoint.E if err = usecase.CreateCommentOnPost(ctx, &model.CreateCommentRequest{ UserPostID: req.UserPostID, Text: req.Comment, + Status: helper.GetInt64FromPointer(req.Status), }); err != nil { return nil, err } diff --git a/endpoint/request.go b/endpoint/request.go index cd529db..f790335 100644 --- a/endpoint/request.go +++ b/endpoint/request.go @@ -55,14 +55,14 @@ func Validate(in interface{}) error { ) } else if obj, ok := in.(*UpdateStatusOrTitle); ok { err = validation.ValidateStruct(in, - validation.Field(obj.ID, validation.Required), + validation.Field(&obj.ID, validation.Required), validation.Field(&obj.Title, validation.Required, validation.Length(10, 0)), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } else if obj, ok := in.(*CreateCommentRequest); ok { err = validation.ValidateStruct(in, - validation.Field(obj.UserPostID, validation.Required), - validation.Field(obj.Comment, validation.Required, validation.Length(10, 0)), + validation.Field(&obj.UserPostID, validation.Required), + validation.Field(&obj.Comment, validation.Required, validation.Length(10, 0)), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } diff --git a/mocks/testcases/create-new-post.go b/mocks/testcases/create-new-post.go index dae92f2..b3887d7 100644 --- a/mocks/testcases/create-new-post.go +++ b/mocks/testcases/create-new-post.go @@ -23,7 +23,7 @@ var newRepositoryRequest = &model.CreateNewPostRequestRepository{ Images: "[{\"path\":\"http://localhost\"}]", Tags: tags, Status: helper.ACTIVED, - // ActorID: 1, + ActorID: 1, } type CreateNewUserPost struct { diff --git a/mocks/testcases/get-list-user-post.go b/mocks/testcases/get-list-user-post.go index a496586..cec9434 100644 --- a/mocks/testcases/get-list-user-post.go +++ b/mocks/testcases/get-list-user-post.go @@ -119,12 +119,13 @@ var ( actorResponse = &model.UserResponse{ ID: 1, Name: sql.NullString{String: "John Doe", Valid: true}, - PhotoURL: sql.NullString{String: "sample", Valid: true}, + PhotoURL: sql.NullString{String: "www.instagram.com/htm-medium=?p9878y2y3", Valid: true}, Role: sql.NullInt64{Int64: 99, Valid: true}, Regency: sql.NullString{String: "regency", Valid: true}, District: sql.NullString{String: "district", Valid: true}, Village: sql.NullString{String: "village", Valid: true}, RW: sql.NullString{String: "rw", Valid: true}, + Status: 10, } actor = &model.Actor{ ID: 1, diff --git a/model/repository_request.go b/model/repository_request.go index 16b842b..0d45c28 100644 --- a/model/repository_request.go +++ b/model/repository_request.go @@ -20,6 +20,7 @@ type CreateCommentRequestRepository struct { UserPostID int64 Text string ActorID int64 + Status int64 } type CreateNewPostRequestRepository struct { diff --git a/model/usecase_request.go b/model/usecase_request.go index 2a57ab6..ddb8150 100644 --- a/model/usecase_request.go +++ b/model/usecase_request.go @@ -28,6 +28,7 @@ type UpdatePostRequest struct { type CreateCommentRequest struct { UserPostID int64 `json:"user_post_id"` Text string `json:"comment"` + Status int64 `json:"status"` } type ActorFromContext struct { diff --git a/repository/mysql/comment.go b/repository/mysql/comment.go index 48077b7..d2a45e6 100644 --- a/repository/mysql/comment.go +++ b/repository/mysql/comment.go @@ -92,13 +92,14 @@ func (r *Comment) Create(ctx context.Context, req *model.CreateCommentRequestRep var err error _, unixTime := helper.GetCurrentTimeUTC() - query.WriteString("INSERT INTO user_post_comments (user_post_id, `text`, status, created_by, updated_by, created_at, updated_at)") - query.WriteString("VALUES(:user_post_id. :comment, :status, :actor, :actor, :current, :current)") + query.WriteString("INSERT INTO user_post_comments (user_post_id, `text`, status, created_by, updated_by, created_at, updated_at) ") + query.WriteString("VALUES(:user_post_id, :comment, :status, :actor, :actor, :current, :current)") params := map[string]interface{}{ "user_post_id": req.UserPostID, "comment": req.Text, "actor": req.ActorID, "current": unixTime, + "status": req.Status, } if ctx != nil { diff --git a/usecase/usecase.go b/usecase/usecase.go index 9a0b786..04d3a25 100644 --- a/usecase/usecase.go +++ b/usecase/usecase.go @@ -226,12 +226,15 @@ func (p *Post) GetCommentsByPostID(ctx context.Context, id int64) ([]*model.Comm } func (p *Post) CreateCommentOnPost(ctx context.Context, req *model.CreateCommentRequest) error { + // TODO: implement authorization and authenticationn logger := kitlog.With(p.logger, "method", "CreateCommentOnPost") - actor := ctx.Value(helper.ACTORKEY).(*model.ActorFromContext).Data + // actor := ctx.Value(helper.ACTORKEY).(*model.ActorFromContext).Data if err := p.repoComment.Create(ctx, &model.CreateCommentRequestRepository{ UserPostID: req.UserPostID, Text: req.Text, - ActorID: actor["id"].(int64), + Status: req.Status, + // ActorID: actor["id"].(int64), + ActorID: 1, // TODO: actor not existed yet using admin as default }); err != nil { level.Error(logger).Log("error_create_comment", err) return err diff --git a/usecase/usecase_test.go b/usecase/usecase_test.go index 4afed54..e2d1787 100644 --- a/usecase/usecase_test.go +++ b/usecase/usecase_test.go @@ -124,6 +124,7 @@ var _ = Describe("Usecase", func() { Expect(err).NotTo(BeNil()) Expect(resp).To(BeNil()) } else { + fmt.Println(resp) Expect(resp).To(Equal(data.ResponseUsecase.Result)) } } From 797c73997c4f8229db2f573f238335fabfafcfe6 Mon Sep 17 00:00:00 2001 From: Yonathan Setiadi Date: Thu, 3 Jun 2021 11:51:00 +0700 Subject: [PATCH 4/5] #45 update query for update user post and add decoder of handler http --- repository/mysql/userpost.go | 4 ++-- transport/http/handler.go | 14 +++++++++++++- usecase/usecase.go | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/repository/mysql/userpost.go b/repository/mysql/userpost.go index c88e6cd..2a40659 100644 --- a/repository/mysql/userpost.go +++ b/repository/mysql/userpost.go @@ -263,9 +263,9 @@ func (r *UserPost) UpdateStatusOrTitle(ctx context.Context, request *model.Updat var err error _, unixTime := helper.GetCurrentTimeUTC() - query.WriteString("UPDATE user_posts") + query.WriteString("UPDATE user_posts SET ") if request.Status != nil { - query.WriteString("status` = :status") + query.WriteString("status = :status") params["status"] = request.Status first = false } diff --git a/transport/http/handler.go b/transport/http/handler.go index 0efb197..d7c6f37 100644 --- a/transport/http/handler.go +++ b/transport/http/handler.go @@ -43,7 +43,7 @@ func MakeHTTPHandler(ctx context.Context, fs usecase.UsecaseI, logger kitlog.Log processCreatePost := kithttp.NewServer(endpoint.MakeCreateNewPost(ctx, fs), decodeCreatePost, encodeResponse, opts...) processCreateComment := kithttp.NewServer(endpoint.MakeCreateComment(ctx, fs), decodeCreateComment, encodeResponse, opts...) processLikeDislike := kithttp.NewServer(endpoint.MakeLikeOrDislikePost(ctx, fs), decodeGetByID, encodeResponse, opts...) - processUpdate := kithttp.NewServer(endpoint.MakeUpdateStatusOrTitle(ctx, fs), decodeGetByID, encodeResponse, opts...) + processUpdate := kithttp.NewServer(endpoint.MakeUpdateStatusOrTitle(ctx, fs), decodeUpdateStatusOrTitle, encodeResponse, opts...) r := mux.NewRouter() @@ -114,6 +114,18 @@ func decodeCreateComment(ctx context.Context, r *http.Request) (interface{}, err return reqBody, nil } +func decodeUpdateStatusOrTitle(ctx context.Context, r *http.Request) (interface{}, error) { + params := mux.Vars(r) + _, id := helper.ConvertFromStringToInt64(params["id"]) + reqBody := &endpoint.UpdateStatusOrTitle{} + if err := json.NewDecoder(r.Body).Decode(reqBody); err != nil { + return nil, err + } + + reqBody.ID = id + return reqBody, nil +} + func decodeNoRequest(ctx context.Context, r *http.Request) (interface{}, error) { return r, nil } diff --git a/usecase/usecase.go b/usecase/usecase.go index 04d3a25..a9c6c00 100644 --- a/usecase/usecase.go +++ b/usecase/usecase.go @@ -176,7 +176,7 @@ func (p *Post) CreateNewPost(ctx context.Context, requestBody *model.CreateNewPo } func (p *Post) UpdateTitleOrStatus(ctx context.Context, requestBody *model.UpdatePostRequest) error { - logger := kitlog.With(p.logger, "method", "UpdateTItleOrStatus") + logger := kitlog.With(p.logger, "method", "UpdateTitleOrStatus") _, err := p.repoPost.GetDetailPost(ctx, requestBody.ID) if err != nil { level.Error(logger).Log("error_get_detail", err) From 224db27bddca98ebc3e2d968483464f377e4298a Mon Sep 17 00:00:00 2001 From: Yonathan Setiadi Date: Thu, 3 Jun 2021 13:45:13 +0700 Subject: [PATCH 5/5] #45 fix maintainability for using single object, remove duplication --- endpoint/endpoint.go | 8 ++++---- endpoint/request.go | 16 ++-------------- transport/grpc/transport.go | 10 +++++----- transport/http/handler.go | 14 +------------- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 9ab5109..7a50597 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -106,15 +106,15 @@ func MakeCreateNewPost(ctx context.Context, usecase usecase.UsecaseI) endpoint.E func MakeUpdateStatusOrTitle(ctx context.Context, usecase usecase.UsecaseI) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req := request.(*UpdateStatusOrTitle) + req := request.(*CreateCommentRequest) if err := Validate(req); err != nil { return nil, err } if err = usecase.UpdateTitleOrStatus(ctx, &model.UpdatePostRequest{ - ID: req.ID, + ID: req.UserPostID, Status: req.Status, - Title: req.Title, + Title: helper.SetPointerString(req.Text), }); err != nil { return nil, err } @@ -148,7 +148,7 @@ func MakeCreateComment(ctx context.Context, usecase usecase.UsecaseI) endpoint.E if err = usecase.CreateCommentOnPost(ctx, &model.CreateCommentRequest{ UserPostID: req.UserPostID, - Text: req.Comment, + Text: req.Text, Status: helper.GetInt64FromPointer(req.Status), }); err != nil { return nil, err diff --git a/endpoint/request.go b/endpoint/request.go index f790335..92aa23f 100644 --- a/endpoint/request.go +++ b/endpoint/request.go @@ -32,15 +32,9 @@ type Image struct { Path string `json:"path"` } -type UpdateStatusOrTitle struct { - ID int64 `json:"id"` - Status *int64 `json:"status"` - Title *string `json:"title"` -} - type CreateCommentRequest struct { UserPostID int64 `json:"user_post_id"` - Comment string `json:"comment"` + Text string `json:"text"` Status *int64 `json:"status"` } @@ -53,16 +47,10 @@ func Validate(in interface{}) error { validation.Field(&obj.Tags, validation.Required), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) - } else if obj, ok := in.(*UpdateStatusOrTitle); ok { - err = validation.ValidateStruct(in, - validation.Field(&obj.ID, validation.Required), - validation.Field(&obj.Title, validation.Required, validation.Length(10, 0)), - validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), - ) } else if obj, ok := in.(*CreateCommentRequest); ok { err = validation.ValidateStruct(in, validation.Field(&obj.UserPostID, validation.Required), - validation.Field(&obj.Comment, validation.Required, validation.Length(10, 0)), + validation.Field(&obj.Text, validation.Required, validation.Length(10, 0)), validation.Field(&obj.Status, validation.Required, validation.In(helper.ACTIVED, helper.DELETED, helper.INACTIVED)), ) } diff --git a/transport/grpc/transport.go b/transport/grpc/transport.go index c568bc5..b3a27ac 100644 --- a/transport/grpc/transport.go +++ b/transport/grpc/transport.go @@ -241,10 +241,10 @@ func encodeStatusResponse(ctx context.Context, r interface{}) (interface{}, erro func decodeUpdateUserPost(ctx context.Context, r interface{}) (interface{}, error) { req := r.(*transportUserPost.UpdateUserPostRequest) - return &endpoint.UpdateStatusOrTitle{ - ID: req.GetId(), - Status: helper.SetPointerInt64(req.GetStatus()), - Title: helper.SetPointerString(req.GetTitle()), + return &endpoint.CreateCommentRequest{ + UserPostID: req.GetId(), + Status: helper.SetPointerInt64(req.GetStatus()), + Text: req.GetTitle(), }, nil } @@ -277,7 +277,7 @@ func decodeCreateCommentRequest(ctx context.Context, r interface{}) (interface{} return &endpoint.CreateCommentRequest{ UserPostID: req.GetUserPostId(), - Comment: req.GetComment(), + Text: req.GetComment(), Status: helper.SetPointerInt64(req.GetStatus()), }, nil } diff --git a/transport/http/handler.go b/transport/http/handler.go index d7c6f37..8e812cb 100644 --- a/transport/http/handler.go +++ b/transport/http/handler.go @@ -43,7 +43,7 @@ func MakeHTTPHandler(ctx context.Context, fs usecase.UsecaseI, logger kitlog.Log processCreatePost := kithttp.NewServer(endpoint.MakeCreateNewPost(ctx, fs), decodeCreatePost, encodeResponse, opts...) processCreateComment := kithttp.NewServer(endpoint.MakeCreateComment(ctx, fs), decodeCreateComment, encodeResponse, opts...) processLikeDislike := kithttp.NewServer(endpoint.MakeLikeOrDislikePost(ctx, fs), decodeGetByID, encodeResponse, opts...) - processUpdate := kithttp.NewServer(endpoint.MakeUpdateStatusOrTitle(ctx, fs), decodeUpdateStatusOrTitle, encodeResponse, opts...) + processUpdate := kithttp.NewServer(endpoint.MakeUpdateStatusOrTitle(ctx, fs), decodeCreateComment, encodeResponse, opts...) r := mux.NewRouter() @@ -114,18 +114,6 @@ func decodeCreateComment(ctx context.Context, r *http.Request) (interface{}, err return reqBody, nil } -func decodeUpdateStatusOrTitle(ctx context.Context, r *http.Request) (interface{}, error) { - params := mux.Vars(r) - _, id := helper.ConvertFromStringToInt64(params["id"]) - reqBody := &endpoint.UpdateStatusOrTitle{} - if err := json.NewDecoder(r.Body).Decode(reqBody); err != nil { - return nil, err - } - - reqBody.ID = id - return reqBody, nil -} - func decodeNoRequest(ctx context.Context, r *http.Request) (interface{}, error) { return r, nil }