Closed mehdihadeli closed 1 year ago
u mean use custom validator.go file to replace all the validator package right?
btw, I'm new to this project and really interested to help, do you think this issue is great for me to start contribute?
Maybe we could put it in same command file and replacing validate
attribute and validator pkg with ozzo, for example for create_product_command it will be something like this:
type CreateProduct struct {
ProductID uuid.UUID
Name string
Description string
Price float64
CreatedAt time.Time
}
func NewCreateProduct(name string, description string, price float64) (*CreateProduct, error) {
command := &CreateProduct{
ProductID: uuid.NewV4(),
Name: name,
Description: description,
Price: price,
CreatedAt: time.Now(),
}
err := validator.Validate(command)
if err != nil {
return nil, err
}
return command, nil
}
// using ozzo
func (c *CreateProduct) Validate() error {
return validation.ValidateStruct(&c,
validation.Field(&c.ProductID, validation.Required),
validation.Field(&c.Name, validation.Required, validation.Length(3, 255)),
///...
)
}
If you like, feel free to contribute.
thank you for the tips, let me see what I can do .
You're welcome :)
I've already made some changes on command/query level, could you please review them before I go further? btw it seems like I don't have permission to create new branch/ create PR. @mehdihadeli
Yes, sure. Did you fork the project? You should put your changes in your fork, and after that you can send a pull request to my main branch. Please follow contribution guide.
Currently, I use tags for validating inputs with go-playground/validator package, maybe it's cleaner that we move them to
validator.go
file in each slice.