mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-8] add: repo layer
This commit is contained in:
22
comments/internal/domain/model/comment.go
Normal file
22
comments/internal/domain/model/comment.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Comment struct {
|
||||
ID int64 `validate:"gt=0"`
|
||||
UserID int64 `validate:"gt=0"`
|
||||
SKU int64 `validate:"gt=0"`
|
||||
CreatedAt time.Time
|
||||
Text string `validate:"lte=255,gt=0"`
|
||||
}
|
||||
|
||||
func (c *Comment) Validate() error {
|
||||
if err := validate.Struct(c); err != nil {
|
||||
return fmt.Errorf("invalid requested values: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
5
comments/internal/domain/model/errors.go
Normal file
5
comments/internal/domain/model/errors.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrCommentNotFound = errors.New("comment not found")
|
||||
9
comments/internal/domain/model/validate.go
Normal file
9
comments/internal/domain/model/validate.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
import "github.com/go-playground/validator/v10"
|
||||
|
||||
var validate *validator.Validate
|
||||
|
||||
func init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
Reference in New Issue
Block a user