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