Initial commit
This commit is contained in:
commit
c0cb826917
63 changed files with 2069 additions and 0 deletions
43
internal/domain/entities/posts.go
Normal file
43
internal/domain/entities/posts.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const PostsTable = "posts"
|
||||
|
||||
type Posts struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
UserId uuid.UUID `db:"user_id"`
|
||||
PostId uuid.UUID `db:"post_id"`
|
||||
}
|
||||
|
||||
func CreatePosts(userId uuid.UUID, postId uuid.UUID) (posts Posts, err error) {
|
||||
posts = Posts{
|
||||
Id: uuid.New(),
|
||||
UserId: userId,
|
||||
PostId: postId,
|
||||
}
|
||||
|
||||
err = posts.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Posts) Validate() error {
|
||||
if err := uuid.Validate(p.Id.String()); err != nil {
|
||||
return errors.New("Invalid posts.id")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(p.UserId.String()); err != nil {
|
||||
return errors.New("Invalid posts.userId")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(p.PostId.String()); err != nil {
|
||||
return errors.New("Invalid posts.postId")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue