forked from ebhomengo/niki
				
			minor change & delete description field from param.KindBoxReqAcceptRequest
This commit is contained in:
		
							parent
							
								
									e3109b1972
								
							
						
					
					
						commit
						12a8e0ecf5
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue