feat: add published at db models and fix repo for this update

This commit is contained in:
d3m0k1d
2026-02-15 00:51:29 +03:00
parent ea8fa90a31
commit a96ef069cc
3 changed files with 9 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ func NewPostRepository(db *sql.DB) PostRepository {
}
func (p *postRepository) GetAll(ctx context.Context) ([]storage.PostReq, error) {
var result []storage.PostReq
rows, err := p.db.Query("SELECT id, title, content FROM posts")
rows, err := p.db.Query("SELECT id, title, content FROM posts WHERE published = 1")
if err != nil {
p.logger.Error(err.Error())
return nil, err
@@ -45,7 +45,7 @@ func (p *postRepository) GetAll(ctx context.Context) ([]storage.PostReq, error)
func (p *postRepository) GetByID(ctx context.Context, id int) (storage.PostReq, error) {
var result storage.PostReq
row := p.db.QueryRow("SELECT title, content FROM posts WHERE id = ?", id)
row := p.db.QueryRow("SELECT title, content FROM posts WHERE id = ? AND published = 1", id)
var title string
var content string
err := row.Scan(&title, &content)
@@ -122,3 +122,5 @@ func (p *postRepository) IsExist(ctx context.Context, id int) bool {
}
return true
}
// TODO: Add query for change published status