2021-08-29 16:37:20 +02:00
|
|
|
package goddit
|
|
|
|
|
|
|
|
import "github.com/google/uuid"
|
|
|
|
|
|
|
|
type Thread struct {
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
Title string `db:"title"`
|
|
|
|
Description string `db:"description"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Post struct {
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
ThreadID uuid.UUID `db:"thread_id"`
|
|
|
|
Title string `db:"title"`
|
|
|
|
Content string `db:"content"`
|
|
|
|
Votes int `db:"votes"`
|
|
|
|
CommentsCount int `db:"comments_count"`
|
|
|
|
ThreadTitle string `db:"thread_title"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Comment struct {
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
PostID uuid.UUID `db:"post_id"`
|
|
|
|
Content string `db:"content"`
|
|
|
|
Votes int `db:"votes"`
|
|
|
|
}
|
|
|
|
|
2021-08-29 19:26:01 +02:00
|
|
|
type User struct {
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
Username string `db:"username"`
|
|
|
|
Password string `db:"password"`
|
|
|
|
}
|
2021-08-29 16:37:20 +02:00
|
|
|
type ThreadStore interface {
|
|
|
|
Thread(id uuid.UUID) (Thread, error)
|
|
|
|
Threads() ([]Thread, error)
|
|
|
|
CreateThread(t *Thread) error
|
|
|
|
UpdateThread(t *Thread) error
|
|
|
|
DeleteThread(id uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type PostStore interface {
|
|
|
|
Post(id uuid.UUID) (Post, error)
|
|
|
|
Posts() ([]Post, error)
|
|
|
|
PostsByThread(threadID uuid.UUID) ([]Post, error)
|
|
|
|
CreatePost(p *Post) error
|
|
|
|
UpdatePost(p *Post) error
|
|
|
|
DeletePost(id uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type CommentStore interface {
|
|
|
|
Comment(id uuid.UUID) (Comment, error)
|
|
|
|
CommentsByPost(postID uuid.UUID) ([]Comment, error)
|
|
|
|
CreateComment(c *Comment) error
|
|
|
|
UpdateComment(c *Comment) error
|
|
|
|
DeleteComment(id uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
2021-08-29 19:26:01 +02:00
|
|
|
type UserStore interface {
|
|
|
|
User(id uuid.UUID) (User, error)
|
|
|
|
UserByUsername(username string) (User, error)
|
|
|
|
CreateUser(u *User) error
|
|
|
|
UpdateUser(u *User) error
|
|
|
|
DeleteUser(id uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
2021-08-29 16:37:20 +02:00
|
|
|
type Store interface {
|
|
|
|
ThreadStore
|
|
|
|
PostStore
|
|
|
|
CommentStore
|
2021-08-29 19:26:01 +02:00
|
|
|
UserStore
|
2021-08-29 16:37:20 +02:00
|
|
|
}
|