Add Blog Posts CRUD with SQLite

- Add modernc.org/sqlite (pure Go, no CGO)
- Create models package with Post struct
- Implement SQLite connection and schema auto-creation
- Add CRUD methods to database package
- Create post handlers with JSON API
- Register API routes: GET/POST/PUT/DELETE /api/v1/posts
- Set default DBURL to file:./data.db with WAL mode
This commit is contained in:
2025-12-27 12:43:30 +07:00
parent fb347b96df
commit f7ab09c2c3
8 changed files with 474 additions and 10 deletions

29
internal/models/models.go Normal file
View File

@@ -0,0 +1,29 @@
package models
import (
"time"
)
type Post struct {
ID int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Author string `json:"author"`
Published bool `json:"published"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type CreatePostRequest struct {
Title string `json:"title"`
Body string `json:"body"`
Author string `json:"author"`
Published bool `json:"published"`
}
type UpdatePostRequest struct {
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Author *string `json:"author,omitempty"`
Published *bool `json:"published,omitempty"`
}