Added authorization

This commit is contained in:
KamilM1205 2025-09-25 09:01:00 +04:00
parent c3c3d65d32
commit b96dd39795
50 changed files with 685 additions and 410 deletions

View file

@ -5,21 +5,24 @@ import (
"time"
"github.com/google/uuid"
"github.com/lib/pq"
)
const PostTable = "post"
type Post struct {
Id uuid.UUID `db:"id"`
UserId uuid.UUID `db:"userid"`
Title string `db:"title"`
Description string `db:"description"`
Content string `db:"content"`
CreatedAt time.Time `db:"createdat"`
UpdatedAt time.Time `db:"updatedat"`
Id uuid.UUID `db:"id"`
UserId uuid.UUID `db:"userid"`
Title string `db:"title"`
Description string `db:"description"`
Content string `db:"content"`
CreatedAt time.Time `db:"createdat"`
UpdatedAt time.Time `db:"updatedat"`
Category string `db:"category"`
Tags pq.StringArray `db:"tags"` // TODO: rewrite it to many2many
}
func CreatePost(userId uuid.UUID, title string, description string, content string) (post Post, err error) {
func CreatePost(userId uuid.UUID, title string, description string, content string, category string, tags []string) (post Post, err error) {
post = Post{
Id: uuid.New(),
UserId: userId,
@ -28,6 +31,8 @@ func CreatePost(userId uuid.UUID, title string, description string, content stri
Content: content,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Category: category,
Tags: tags,
}
err = post.Validate()