diff --git a/backend/internal/repositories/post_repository.go b/backend/internal/repositories/post_repository.go index d248b14..5216441 100644 --- a/backend/internal/repositories/post_repository.go +++ b/backend/internal/repositories/post_repository.go @@ -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 diff --git a/backend/internal/storage/migrations.go b/backend/internal/storage/migrations.go index 50cd1c3..19015d6 100644 --- a/backend/internal/storage/migrations.go +++ b/backend/internal/storage/migrations.go @@ -4,6 +4,7 @@ const Migrations = ` CREATE TABLE IF NOT EXISTS posts( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, + published BOOLEAN DEFAULT 0, content TEXT NOT NULL, CREATED_AT DATETIME DEFAULT CURRENT_TIMESTAMP ); diff --git a/backend/internal/storage/models.go b/backend/internal/storage/models.go index ea70986..c974685 100644 --- a/backend/internal/storage/models.go +++ b/backend/internal/storage/models.go @@ -3,6 +3,7 @@ package storage 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"` } @@ -14,8 +15,9 @@ type PostReq struct { } type PostCreate struct { - Title string `db:"title" json:"title"` - Content string `db:"content" json:"content"` + Title string `db:"title" json:"title"` + Published bool `db:"published" json:"published"` + Content string `db:"content" json:"content"` } type User struct {