-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add validate to command/query level (#74)
Co-authored-by: Alan-maqing <maqing@dongyu-technology.com> Fix #7
- Loading branch information
Showing
28 changed files
with
181 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 16 additions & 3 deletions
19
...g_read_service/internal/products/features/deleting_products/v1/commands/delete_product.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
package commands | ||
|
||
import uuid "github.com/satori/go.uuid" | ||
import ( | ||
validation "github.com/go-ozzo/ozzo-validation" | ||
"github.com/go-ozzo/ozzo-validation/is" | ||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
type DeleteProduct struct { | ||
ProductId uuid.UUID `validate:"required"` | ||
} | ||
|
||
func NewDeleteProduct(productId uuid.UUID) *DeleteProduct { | ||
return &DeleteProduct{ProductId: productId} | ||
func NewDeleteProduct(productId uuid.UUID) (*DeleteProduct, error) { | ||
delProduct := &DeleteProduct{ProductId: productId} | ||
if err := delProduct.Validate(); err != nil { | ||
return nil, err | ||
} | ||
return delProduct, nil | ||
} | ||
|
||
func (p *DeleteProduct) Validate() error { | ||
return validation.ValidateStruct(p, | ||
validation.Field(&p.ProductId, validation.Required, is.UUIDv4)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
...read_service/internal/products/features/get_product_by_id/v1/queries/get_product_by_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
package queries | ||
|
||
import ( | ||
validation "github.com/go-ozzo/ozzo-validation" | ||
"github.com/go-ozzo/ozzo-validation/is" | ||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
type GetProductById struct { | ||
Id uuid.UUID `validate:"required"` | ||
} | ||
|
||
func NewGetProductById(id uuid.UUID) *GetProductById { | ||
return &GetProductById{Id: id} | ||
func NewGetProductById(id uuid.UUID) (*GetProductById, error) { | ||
product := &GetProductById{Id: id} | ||
if err := product.Validate(); err != nil { | ||
return nil, err | ||
} | ||
return product, nil | ||
} | ||
|
||
func (p *GetProductById) Validate() error { | ||
return validation.ValidateStruct(p, validation.Field(&p.Id, validation.Required, is.UUIDv4)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
..._read_service/internal/products/features/searching_products/v1/queries/search_products.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
package queries | ||
|
||
import "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/utils" | ||
import ( | ||
validation "github.com/go-ozzo/ozzo-validation" | ||
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/utils" | ||
) | ||
|
||
type SearchProducts struct { | ||
SearchText string `validate:"required"` | ||
*utils.ListQuery | ||
} | ||
|
||
func (s *SearchProducts) Validate() error { | ||
return validation.ValidateStruct(s, validation.Field(&s.SearchText, validation.Required)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.