From 12a8e0ecf5b8983ee963bb81977e3cc7ce99d8c4 Mon Sep 17 00:00:00 2001 From: Abolfazl Norzad Date: Mon, 22 Jan 2024 14:13:16 +0330 Subject: [PATCH] minor change & delete description field from param.KindBoxReqAcceptRequest --- delivery/http_server/admin/kind_box_req/accept.go | 6 +++++- param/admin/kind_box_req/accept.go | 5 ++--- repository/mysql/kind_box_req/kind_box_req.go | 6 +++--- service/admin/kind_box_req/accept.go | 2 +- service/admin/kind_box_req/service.go | 2 +- service/admin/kind_box_req/update.go | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/delivery/http_server/admin/kind_box_req/accept.go b/delivery/http_server/admin/kind_box_req/accept.go index 1e3f7d4..b5f3075 100644 --- a/delivery/http_server/admin/kind_box_req/accept.go +++ b/delivery/http_server/admin/kind_box_req/accept.go @@ -1,6 +1,7 @@ package adminkindboxreqhandler import ( + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" "net/http" "strconv" @@ -14,7 +15,10 @@ func (h Handler) Accept(c echo.Context) error { if bErr := c.Bind(&req); bErr != nil { return echo.NewHTTPError(http.StatusBadRequest) } - num, _ := strconv.ParseUint(c.Param("id"), 36, 10) + num, cErr := strconv.ParseUint(c.Param("id"), 10, 64) + if cErr != nil { + return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput) + } req.ID = uint(num) // if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetRequest(req); err != nil { // msg, code := httpmsg.Error(err) diff --git a/param/admin/kind_box_req/accept.go b/param/admin/kind_box_req/accept.go index ad480bb..60573b9 100644 --- a/param/admin/kind_box_req/accept.go +++ b/param/admin/kind_box_req/accept.go @@ -7,9 +7,8 @@ import ( ) type KindBoxReqAcceptRequest struct { - ID uint `json:"id"` - Description string `json:"description"` - CountAccepted uint `json:"count_accepted"` + ID uint `json:"id"` + CountAccepted uint `json:"count_accepted"` } type KindBoxReqAcceptResponse struct { diff --git a/repository/mysql/kind_box_req/kind_box_req.go b/repository/mysql/kind_box_req/kind_box_req.go index 88291e2..cbe7fea 100644 --- a/repository/mysql/kind_box_req/kind_box_req.go +++ b/repository/mysql/kind_box_req/kind_box_req.go @@ -25,15 +25,15 @@ func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (en return kindBoxReq, nil } -func (d DB) AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint, description string) error { +func (d DB) AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint) error { op := richerror.Op("mysqlkindboxreq.AcceptKindBoxReq") statement, err := d.conn.Conn(). - Prepare(`update kind_box_reqs set count_accepted = ? , description = ? , status = ? where id = ?`) + Prepare(`update kind_box_reqs set count_accepted = ? , status = ? where id = ?`) if err != nil { return richerror.New(op).WithErr(err). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) } - _, eErr := statement.ExecContext(ctx, countAccepted, description, entity.KindBoxReqAcceptedStatus.String(), kindBoxReqID) + _, eErr := statement.ExecContext(ctx, countAccepted, entity.KindBoxReqAcceptedStatus.String(), kindBoxReqID) if eErr != nil { return richerror.New(op).WithErr(eErr). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) diff --git a/service/admin/kind_box_req/accept.go b/service/admin/kind_box_req/accept.go index dc8efb9..54f3960 100644 --- a/service/admin/kind_box_req/accept.go +++ b/service/admin/kind_box_req/accept.go @@ -8,7 +8,7 @@ import ( func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) (param.KindBoxReqAcceptResponse, error) { const op = "adminkindboxreqservice.Accept" - err := s.repo.AcceptKindBoxReq(ctx, req.ID, req.CountAccepted, req.Description) + err := s.repo.AcceptKindBoxReq(ctx, req.ID, req.CountAccepted) if err != nil { return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err) } diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index 118707a..878b03e 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -12,7 +12,7 @@ type Repository interface { // DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error // GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error) // GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error) - AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint, description string) error + AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint) error FindByID(ctx context.Context, id uint) (entity.KindBoxReq, error) } diff --git a/service/admin/kind_box_req/update.go b/service/admin/kind_box_req/update.go index 72f6998..0cd9d0e 100644 --- a/service/admin/kind_box_req/update.go +++ b/service/admin/kind_box_req/update.go @@ -9,7 +9,7 @@ package adminkindboxreqservice // richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" //) // -// func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) { +//func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) { // // TODO: can benefactor update its request ? // // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ? // // TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected