forked from ebhomengo/niki
Merge branch 'develop' into stage/ruhollahh01/implement-refresh-access-token-endpoints
This commit is contained in:
commit
061db253fe
|
@ -3117,7 +3117,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": [
|
||||
|
|
|
@ -3106,7 +3106,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,12 +1,16 @@
|
|||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
|
|
|
@ -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,15 +12,12 @@ 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,
|
||||
DeliverReferDate: req.DeliverReferDate,
|
||||
DeliverReferTimeID: req.DeliverReferTimeID,
|
||||
CountRequested: req.CountRequested,
|
||||
Status: entity.KindBoxReqPendingStatus,
|
||||
})
|
||||
|
|
|
@ -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