43 lines
765 B
Go
43 lines
765 B
Go
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
|
|
}
|