Compare commits
2 Commits
5a375d67c7
...
bb987b1f8b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb987b1f8b | ||
|
|
3fcaefba1b |
@@ -21,15 +21,55 @@ func NewCommentsRepository(db *sql.DB) CommentRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commentsRepository) CreateComment(ctx context.Context, comment *storage.Comment) error {
|
func (c *commentsRepository) CreateComment(
|
||||||
|
ctx context.Context,
|
||||||
|
comment *storage.CommentCreate,
|
||||||
|
) error {
|
||||||
|
_, err := c.db.Exec(
|
||||||
|
"INSERT INTO comments(content, post_id) VALUES(?, ?, ?)",
|
||||||
|
comment.Content,
|
||||||
|
comment.PostID,
|
||||||
|
comment.UserID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Error("error insert: " + err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commentsRepository) GetAllComments(ctx context.Context) ([]storage.Comment, error) {
|
func (c *commentsRepository) GetAllComments(ctx context.Context) ([]storage.Comment, error) {
|
||||||
return nil, nil
|
var result []storage.Comment
|
||||||
|
rows, err := c.db.Query("SELECT id, content, post_id, user_id, created_at FROM comments")
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Error("error scan " + err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for rows.Next() {
|
||||||
|
var id int
|
||||||
|
var content string
|
||||||
|
var postID int
|
||||||
|
var userID int
|
||||||
|
var createdAt string
|
||||||
|
err := rows.Scan(&id, &content, &postID, &userID, &createdAt)
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Error("error scan: " + err.Error())
|
||||||
|
}
|
||||||
|
result = append(result, storage.Comment{
|
||||||
|
ID: id,
|
||||||
|
Content: content,
|
||||||
|
PostID: postID,
|
||||||
|
UserID: userID,
|
||||||
|
CreatedAt: createdAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commentsRepository) GetCommentsOfPost(ctx context.Context, id int) ([]storage.Comment, error) {
|
func (c *commentsRepository) GetCommentsOfPost(
|
||||||
|
ctx context.Context,
|
||||||
|
id int,
|
||||||
|
) ([]storage.Comment, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +77,10 @@ func (c *commentsRepository) DeleteComment(ctx context.Context, id int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commentsRepository) UpdateComment(ctx context.Context, id int, comment *storage.Comment) error {
|
func (c *commentsRepository) UpdateComment(
|
||||||
|
ctx context.Context,
|
||||||
|
id int,
|
||||||
|
comment *storage.Comment,
|
||||||
|
) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type AuthRepository interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CommentRepository interface {
|
type CommentRepository interface {
|
||||||
CreateComment(ctx context.Context, comment *storage.Comment) error
|
CreateComment(ctx context.Context, comment *storage.CommentCreate) error
|
||||||
GetAllComments(ctx context.Context) ([]storage.Comment, error)
|
GetAllComments(ctx context.Context) ([]storage.Comment, error)
|
||||||
GetCommentsOfPost(ctx context.Context, id int) ([]storage.Comment, error)
|
GetCommentsOfPost(ctx context.Context, id int) ([]storage.Comment, error)
|
||||||
DeleteComment(ctx context.Context, id int) error
|
DeleteComment(ctx context.Context, id int) error
|
||||||
|
|||||||
Reference in New Issue
Block a user