forked from ebhomengo/niki
Merge branch 'develop' into stage/erfan/fix-makefile-format-skipping-vendor
This commit is contained in:
commit
d37253c0db
|
@ -10,7 +10,12 @@ import (
|
|||
)
|
||||
|
||||
type HTTPServer struct {
|
||||
Port int `koanf:"port"`
|
||||
Port int `koanf:"port"`
|
||||
Cors Cors `koanf:"cors"`
|
||||
}
|
||||
|
||||
type Cors struct {
|
||||
AllowOrigins []string `koanf:"allow_origins"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
|
|
@ -67,6 +67,9 @@ func (s Server) Serve() {
|
|||
func (s Server) RegisterRoutes() {
|
||||
s.Router.Use(middleware.RequestID())
|
||||
s.Router.Use(middleware.Recover())
|
||||
s.Router.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
AllowOrigins: s.config.HTTPServer.Cors.AllowOrigins,
|
||||
}))
|
||||
registerSwagger(s.Router)
|
||||
|
||||
// Routes
|
||||
|
|
|
@ -3,6 +3,9 @@ type: yml
|
|||
|
||||
http_server:
|
||||
port: 1313
|
||||
cors:
|
||||
allow_origins:
|
||||
- "*"
|
||||
|
||||
benefactor_service:
|
||||
length_of_otp_code: 5
|
||||
|
|
|
@ -35,5 +35,6 @@ const (
|
|||
ErrorMsgSortDirectionShouldBeAscOrDesc = "sort direction should be asc or desc"
|
||||
ErrorMsgSortFieldIsNotValid = "sort field is not valid"
|
||||
ErrorMsgAssignReceiverAgentKindBoxStatus = "only ready to return kindboxes can be assigned to a receiver agent"
|
||||
ErrorMsgReturnKindBoxStatus = "only returned kindboxes can be enumerated"
|
||||
ErrorMsgInvalidSerialNumberRange = "invalid serial number range"
|
||||
)
|
||||
|
|
|
@ -14,11 +14,12 @@ func (v Validator) ValidateEnumerate(ctx context.Context, req param.EnumerateKin
|
|||
const op = "adminkindboxvalidator.ValidateEnumerate"
|
||||
|
||||
if err := validation.ValidateStruct(&req,
|
||||
|
||||
validation.Field(&req.KindBoxID, validation.Required,
|
||||
validation.By(v.doesKindBoxExist(ctx))),
|
||||
validation.By(v.doesKindBoxExist(ctx)),
|
||||
validation.By(v.CheckKindBoxStatusForEnumeration(ctx))),
|
||||
|
||||
validation.Field(&req.Amount, validation.Required),
|
||||
|
||||
); err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
|
|
|
@ -81,3 +81,21 @@ func (v Validator) doesAgentExist(ctx context.Context) validation.RuleFunc {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) CheckKindBoxStatusForEnumeration(ctx context.Context) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
kindBoxID, ok := value.(uint)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
kindBox, err := v.repo.GetKindBox(ctx, kindBoxID)
|
||||
if err != nil {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if kindBox.Status != entity.KindBoxReturnedStatus {
|
||||
return fmt.Errorf(errmsg.ErrorMsgReturnKindBoxStatus)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue