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)