Compare commits

...

2 Commits

Author SHA1 Message Date
d3m0k1d
a96ef069cc feat: add published at db models and fix repo for this update 2026-02-15 00:51:29 +03:00
d3m0k1d
ea8fa90a31 fix: redirect 2026-02-15 00:22:48 +03:00
4 changed files with 10 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ func NewPostRepository(db *sql.DB) PostRepository {
} }
func (p *postRepository) GetAll(ctx context.Context) ([]storage.PostReq, error) { func (p *postRepository) GetAll(ctx context.Context) ([]storage.PostReq, error) {
var result []storage.PostReq 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 { if err != nil {
p.logger.Error(err.Error()) p.logger.Error(err.Error())
return nil, err 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) { func (p *postRepository) GetByID(ctx context.Context, id int) (storage.PostReq, error) {
var result storage.PostReq 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 title string
var content string var content string
err := row.Scan(&title, &content) err := row.Scan(&title, &content)
@@ -122,3 +122,5 @@ func (p *postRepository) IsExist(ctx context.Context, id int) bool {
} }
return true return true
} }
// TODO: Add query for change published status

View File

@@ -4,6 +4,7 @@ const Migrations = `
CREATE TABLE IF NOT EXISTS posts( CREATE TABLE IF NOT EXISTS posts(
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL, title TEXT NOT NULL,
published BOOLEAN DEFAULT 0,
content TEXT NOT NULL, content TEXT NOT NULL,
CREATED_AT DATETIME DEFAULT CURRENT_TIMESTAMP CREATED_AT DATETIME DEFAULT CURRENT_TIMESTAMP
); );

View File

@@ -3,6 +3,7 @@ package storage
type Post struct { type Post struct {
ID int `db:"id" json:"id"` ID int `db:"id" json:"id"`
Title string `db:"title" json:"title"` Title string `db:"title" json:"title"`
Published bool `db:"published" json:"published"`
Content string `db:"content" json:"content"` Content string `db:"content" json:"content"`
CreatedAt string `db:"created_at" json:"created_at"` CreatedAt string `db:"created_at" json:"created_at"`
} }
@@ -15,6 +16,7 @@ type PostReq struct {
type PostCreate struct { type PostCreate struct {
Title string `db:"title" json:"title"` Title string `db:"title" json:"title"`
Published bool `db:"published" json:"published"`
Content string `db:"content" json:"content"` Content string `db:"content" json:"content"`
} }

View File

@@ -18,7 +18,7 @@ export default function AuthCallback() {
await checkAuth(); await checkAuth();
navigate("/", { replace: true }); window.location.href = "/";
} else { } else {
console.error("No token in URL"); console.error("No token in URL");
navigate("/login?error=no_token"); navigate("/login?error=no_token");