feat: start develop a comment logic
This commit is contained in:
@@ -70,9 +70,10 @@ func (p *postRepository) GetByID(ctx context.Context, id int) (storage.PostReq,
|
||||
|
||||
func (p *postRepository) Create(ctx context.Context, post storage.Post) error {
|
||||
query, err := p.db.Exec(
|
||||
"INSERT INTO posts(title, content) VALUES(?, ?)",
|
||||
"INSERT INTO posts(title, content) VALUES(?, ?, ?)",
|
||||
post.Title,
|
||||
post.Content,
|
||||
post.Tags,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -94,7 +95,10 @@ func (p *postRepository) Update(ctx context.Context, id int, post storage.Post)
|
||||
updates = append(updates, "title = ?")
|
||||
args = append(args, post.Title)
|
||||
}
|
||||
|
||||
if post.Tags != "" {
|
||||
updates = append(updates, "tags = ?")
|
||||
args = append(args, post.Tags)
|
||||
}
|
||||
if post.Content != "" {
|
||||
updates = append(updates, "content = ?")
|
||||
args = append(args, post.Content)
|
||||
@@ -145,7 +149,7 @@ func (p *postRepository) IsExist(ctx context.Context, id int) bool {
|
||||
|
||||
func (p *postRepository) GetAllAdmin(ctx context.Context) ([]storage.PostReq, error) {
|
||||
result := []storage.PostReq{}
|
||||
rows, err := p.db.Query("SELECT id, title, content FROM posts")
|
||||
rows, err := p.db.Query("SELECT id, title, content, tags, CREATED_AT FROM posts")
|
||||
if err != nil {
|
||||
p.logger.Error(err.Error())
|
||||
return nil, err
|
||||
@@ -154,14 +158,18 @@ func (p *postRepository) GetAllAdmin(ctx context.Context) ([]storage.PostReq, er
|
||||
var title string
|
||||
var content string
|
||||
var id int
|
||||
err := rows.Scan(&id, &title, &content)
|
||||
var tags string
|
||||
var createdAt string
|
||||
err := rows.Scan(&id, &title, &content, &tags, &createdAt)
|
||||
if err != nil {
|
||||
p.logger.Error("error scan: " + err.Error())
|
||||
}
|
||||
result = append(result, storage.PostReq{
|
||||
ID: id,
|
||||
Title: title,
|
||||
Content: content,
|
||||
ID: id,
|
||||
Title: title,
|
||||
Content: content,
|
||||
Tags: tags,
|
||||
CreatedAt: createdAt,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user