send all files
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package productdto
|
||||
|
||||
import (
|
||||
"api/libs/logger"
|
||||
"errors"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type DeleteProductDto struct {
|
||||
Codigo string `json:"codigo" validate:"required"`
|
||||
}
|
||||
|
||||
func (d *DeleteProductDto) Validate() error {
|
||||
|
||||
validate := validator.New()
|
||||
|
||||
err := validate.Struct(d)
|
||||
if err != nil {
|
||||
if _, ok := err.(*validator.InvalidValidationError); ok {
|
||||
logger.Development.Info(err.Error())
|
||||
}
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
err = errors.New(e.Field() + " " + e.Tag())
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package productdto
|
||||
|
||||
import (
|
||||
"api/libs/logger"
|
||||
"errors"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type ProductDto struct {
|
||||
Nome string `json:"nome" validate:"required"`
|
||||
Codigo string `json:"codigo" validate:"required"`
|
||||
EstoqueTotal int64 `json:"estoqueTotal" validate:"required"`
|
||||
EstoqueCorte int64 `json:"estoqueCorte" validate:"required"`
|
||||
PrecoDe float32 `json:"precoDe" validate:"required"`
|
||||
PrecoPor float32 `json:"precoPor" validate:"required"`
|
||||
}
|
||||
|
||||
func (d *ProductDto) Validate() error {
|
||||
|
||||
validate := validator.New()
|
||||
|
||||
err := validate.Struct(d)
|
||||
if err != nil {
|
||||
if _, ok := err.(*validator.InvalidValidationError); ok {
|
||||
logger.Development.Info(err.Error())
|
||||
}
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
err = errors.New(e.Field() + " " + e.Tag())
|
||||
}
|
||||
}
|
||||
|
||||
if d.PrecoPor > d.PrecoDe {
|
||||
err = errors.New(`o "preço de" não pode ser inferior ao "preço por"`)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package productdto
|
||||
|
||||
import (
|
||||
"api/libs/logger"
|
||||
"errors"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type ValidateCodeDto struct {
|
||||
Codigo string `json:"codigo" validate:"required"`
|
||||
}
|
||||
|
||||
func (d *ValidateCodeDto) Validate() error {
|
||||
|
||||
validate := validator.New()
|
||||
|
||||
err := validate.Struct(d)
|
||||
if err != nil {
|
||||
if _, ok := err.(*validator.InvalidValidationError); ok {
|
||||
logger.Development.Info(err.Error())
|
||||
}
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
err = errors.New(e.Field() + " " + e.Tag())
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user