feat: start develop a comment logic
This commit is contained in:
@@ -7,7 +7,8 @@ CREATE TABLE IF NOT EXISTS posts(
|
||||
published BOOLEAN DEFAULT 0,
|
||||
content TEXT NOT NULL,
|
||||
CREATED_AT DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME
|
||||
updated_at DATETIME,
|
||||
tags TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
@@ -17,4 +18,14 @@ CREATE TABLE IF NOT EXISTS users(
|
||||
github_login TEXT,
|
||||
avatar_url TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS comments(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
user_id INTEGER,
|
||||
content TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
);
|
||||
`
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package storage
|
||||
|
||||
// Post
|
||||
type Post struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
Title string `db:"title" json:"title"`
|
||||
Published bool `db:"published" json:"published"`
|
||||
Content string `db:"content" json:"content"`
|
||||
CreatedAt string `db:"created_at" json:"created_at"`
|
||||
Tags string `db:"tags" json:"tags"`
|
||||
}
|
||||
|
||||
type PostReq struct {
|
||||
@@ -13,14 +15,17 @@ type PostReq struct {
|
||||
Title string `db:"title" json:"title"`
|
||||
Content string `db:"content" json:"content"`
|
||||
CreatedAt string `db:"created" json:"created_at"`
|
||||
Tags string `db:"tags" json:"tags"`
|
||||
}
|
||||
|
||||
type PostCreate struct {
|
||||
Title string `db:"title" json:"title"`
|
||||
Published bool `db:"published" json:"published"`
|
||||
Content string `db:"content" json:"content"`
|
||||
Tags string `db:"tags" json:"tags"`
|
||||
}
|
||||
|
||||
// User
|
||||
type User struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
Email string `db:"email" json:"email"`
|
||||
@@ -35,3 +40,26 @@ type UserReg struct {
|
||||
GithubLogin string `json:"login"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
// Comment
|
||||
type Comment struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
PostID int `db:"post_id" json:"post_id"`
|
||||
UserID int `db:"user_id" json:"user_id"`
|
||||
Content string `db:"content" json:"content"`
|
||||
CreatedAt string `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
type CommentReq struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
PostID int `db:"post_id" json:"post_id"`
|
||||
UserID int `db:"user_id" json:"user_id"`
|
||||
Content string `db:"content" json:"content"`
|
||||
CreatedAt string `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
type CommentCreate struct {
|
||||
PostID int `db:"post_id" json:"post_id"`
|
||||
UserID int `db:"user_id" json:"user_id"`
|
||||
Content string `db:"content" json:"content"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user