forked from ebhomengo/niki
1
0
Fork 0

minor change & delete description field from param.KindBoxReqAcceptRequest

This commit is contained in:
Abolfazl Nourzad 2024-01-22 14:13:16 +03:30
parent e3109b1972
commit 12a8e0ecf5
Signed by: abolfazl
GPG Key ID: 183534166EB62E0B
6 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package adminkindboxreqhandler package adminkindboxreqhandler
import ( import (
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
"net/http" "net/http"
"strconv" "strconv"
@ -14,7 +15,10 @@ func (h Handler) Accept(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) 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) req.ID = uint(num)
// if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetRequest(req); err != nil { // if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetRequest(req); err != nil {
// msg, code := httpmsg.Error(err) // msg, code := httpmsg.Error(err)

View File

@ -7,9 +7,8 @@ import (
) )
type KindBoxReqAcceptRequest struct { type KindBoxReqAcceptRequest struct {
ID uint `json:"id"` ID uint `json:"id"`
Description string `json:"description"` CountAccepted uint `json:"count_accepted"`
CountAccepted uint `json:"count_accepted"`
} }
type KindBoxReqAcceptResponse struct { type KindBoxReqAcceptResponse struct {

View File

@ -25,15 +25,15 @@ func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (en
return kindBoxReq, nil 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") op := richerror.Op("mysqlkindboxreq.AcceptKindBoxReq")
statement, err := d.conn.Conn(). 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 { if err != nil {
return richerror.New(op).WithErr(err). return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) 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 { if eErr != nil {
return richerror.New(op).WithErr(eErr). return richerror.New(op).WithErr(eErr).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)

View File

@ -8,7 +8,7 @@ import (
func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) (param.KindBoxReqAcceptResponse, error) { func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) (param.KindBoxReqAcceptResponse, error) {
const op = "adminkindboxreqservice.Accept" 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 { if err != nil {
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err) return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err)
} }

View File

@ -12,7 +12,7 @@ type Repository interface {
// DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error // DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error
// GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error) // GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error)
// GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (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) FindByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
} }

View File

@ -9,7 +9,7 @@ package adminkindboxreqservice
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" // 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: can benefactor update its request ?
// // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ? // // 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 // // TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected