chore: coded post req for create posts on db
All checks were successful
Backend ci / build (push) Successful in 7m43s
All checks were successful
Backend ci / build (push) Successful in 7m43s
This commit is contained in:
@@ -58,7 +58,19 @@ 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(?, ?)",
|
||||
post.Title,
|
||||
post.Content,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := query.LastInsertId()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.logger.Info("Post created:", "id", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user