forked from ebhomengo/niki
This commit is contained in:
parent
5526088b35
commit
0703319928
|
@ -3021,7 +3021,11 @@ const docTemplate = `{
|
|||
},
|
||||
"deliver_refer_date": {
|
||||
"type": "string",
|
||||
"example": "2025-01-02 15:04:05"
|
||||
"example": "2025-01-02T15:04:05Z"
|
||||
},
|
||||
"deliver_refer_time_id": {
|
||||
"type": "integer",
|
||||
"example": 1
|
||||
},
|
||||
"kind_box_type": {
|
||||
"allOf": [
|
||||
|
|
|
@ -3010,7 +3010,11 @@
|
|||
},
|
||||
"deliver_refer_date": {
|
||||
"type": "string",
|
||||
"example": "2025-01-02 15:04:05"
|
||||
"example": "2025-01-02T15:04:05Z"
|
||||
},
|
||||
"deliver_refer_time_id": {
|
||||
"type": "integer",
|
||||
"example": 1
|
||||
},
|
||||
"kind_box_type": {
|
||||
"allOf": [
|
||||
|
|
|
@ -327,8 +327,11 @@ definitions:
|
|||
example: 1
|
||||
type: integer
|
||||
deliver_refer_date:
|
||||
example: "2025-01-02 15:04:05"
|
||||
example: "2025-01-02T15:04:05Z"
|
||||
type: string
|
||||
deliver_refer_time_id:
|
||||
example: 1
|
||||
type: integer
|
||||
kind_box_type:
|
||||
allOf:
|
||||
- $ref: '#/definitions/entity.KindBoxType'
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package adminkindboxreqparam
|
||||
|
||||
import entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
import (
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
type KindBoxReqAddRequest struct {
|
||||
BenefactorID uint `json:"benefactor_id" example:"1"`
|
||||
KindBoxType entity.KindBoxType `json:"kind_box_type" example:"on-table"`
|
||||
DeliverAddressID uint `json:"deliver_address_id" example:"1"`
|
||||
DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
|
||||
CountRequested uint `json:"count_requested" example:"2"`
|
||||
BenefactorID uint `json:"benefactor_id" example:"1"`
|
||||
KindBoxType entity.KindBoxType `json:"kind_box_type" example:"on-table"`
|
||||
DeliverAddressID uint `json:"deliver_address_id" example:"1"`
|
||||
DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02T15:04:05Z"`
|
||||
DeliverReferTimeID uint `json:"deliver_refer_time_id" example:"1"`
|
||||
CountRequested uint `json:"count_requested" example:"2"`
|
||||
}
|
||||
|
||||
type KindBoxReqAddResponse struct {
|
||||
|
|
|
@ -2,7 +2,6 @@ package mysqlkindboxreq
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
@ -26,7 +25,7 @@ func (d *DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (e
|
|||
kindBoxReq.DeliverReferTimeID, kindBoxReq.Status)
|
||||
if err != nil {
|
||||
return entity.KindBoxReq{}, richerror.New(op).WithErr(err).
|
||||
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)
|
||||
WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
//nolint
|
||||
|
|
|
@ -2,8 +2,6 @@ package adminkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
@ -14,17 +12,14 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
|
|||
if fieldErrors, vErr := s.vld.ValidateAddRequest(ctx, req); vErr != nil {
|
||||
return param.KindBoxReqAddResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
date, tErr := time.Parse(time.DateTime, req.DeliverReferDate)
|
||||
if tErr != nil {
|
||||
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(tErr).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
||||
BenefactorID: req.BenefactorID,
|
||||
KindBoxType: req.KindBoxType,
|
||||
DeliverAddressID: req.DeliverAddressID,
|
||||
DeliverReferDate: date,
|
||||
CountRequested: req.CountRequested,
|
||||
Status: entity.KindBoxReqPendingStatus,
|
||||
BenefactorID: req.BenefactorID,
|
||||
KindBoxType: req.KindBoxType,
|
||||
DeliverAddressID: req.DeliverAddressID,
|
||||
DeliverReferDate: req.DeliverReferDate,
|
||||
DeliverReferTimeID: req.DeliverReferTimeID,
|
||||
CountRequested: req.CountRequested,
|
||||
Status: entity.KindBoxReqPendingStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
|
|
|
@ -38,6 +38,11 @@ func (v Validator) ValidateAddRequest(ctx context.Context, req param.KindBoxReqA
|
|||
validation.Required,
|
||||
validation.By(v.isDateValid),
|
||||
),
|
||||
|
||||
validation.Field(&req.DeliverReferTimeID,
|
||||
validation.Required,
|
||||
validation.By(v.isReferTimeIDValid(ctx)),
|
||||
),
|
||||
); err != nil {
|
||||
|
||||
fieldErrors := make(map[string]string)
|
||||
|
@ -112,6 +117,7 @@ func (v Validator) isDateValid(value interface{}) error {
|
|||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
|
||||
if date.Before(time.Now()) {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxR
|
|||
validation.Max(uint(MaxKindBoxReq)),
|
||||
),
|
||||
validation.Field(&req.CountAccepted,
|
||||
validation.Min(MinKindBoxReq),
|
||||
validation.Max(MaxKindBoxReq),
|
||||
validation.Min(uint(MinKindBoxReq)),
|
||||
validation.Max(uint(MaxKindBoxReq)),
|
||||
validation.When(req.CountRequested > 0, validation.Max(req.CountRequested)),
|
||||
validation.By(v.checkCountAcceptedMustBeLessThanCountRequested(ctx, req.ID)),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue