# TODO: Blog Posts CRUD Implementation ## Completed - [x] Add SQLite dependency (`modernc.org/sqlite` - pure Go, no CGO) - [x] Create models package (`internal/models/models.go`) - Post struct with JSON tags - CreatePostRequest and UpdatePostRequest structs - [x] Update database package (`internal/database/database.go`) - SQLite connection with WAL mode - Schema auto-creation on startup - CRUD methods: CreatePost, GetPost, ListPosts, UpdatePost, DeletePost - [x] Create post handlers (`internal/handlers/posts.go`) - HandleListPosts, HandleGetPost, HandleCreatePost, HandleUpdatePost, HandleDeletePost - [x] Register API routes (`internal/server/routes.go`) - GET /api/v1/posts - POST /api/v1/posts - GET /api/v1/posts/{id} - PUT /api/v1/posts/{id} - DELETE /api/v1/posts/{id} - [x] Set default DBURL (`internal/config/config.go`) - Default: `file:./data.db?_journal_mode=WAL` ## Optional (Future Enhancements) - [ ] Add HTML templates for web UI - `templates/posts.html` - List all posts - `templates/post.html` - View single post - `templates/post_form.html` - Create/edit form - [ ] Add web routes for HTML views - GET /posts - List page - GET /posts/new - Create form - GET /posts/{id} - View page - GET /posts/{id}/edit - Edit form - [ ] Add authentication for create/update/delete operations - [ ] Add pagination for list endpoint - [ ] Add unit tests ## Testing the API ```bash # Create a post curl -X POST http://localhost:8080/api/v1/posts \ -H "Content-Type: application/json" \ -d '{"title":"Hello","body":"World","author":"me"}' # List all posts curl http://localhost:8080/api/v1/posts # Get a single post curl http://localhost:8080/api/v1/posts/1 # Update a post curl -X PUT http://localhost:8080/api/v1/posts/1 \ -H "Content-Type: application/json" \ -d '{"title":"Updated Title","published":true}' # Delete a post curl -X DELETE http://localhost:8080/api/v1/posts/1 ``` ## Files Modified/Created | File | Status | |------|--------| | `go.mod` | Modified - added modernc.org/sqlite | | `internal/models/models.go` | Created | | `internal/database/database.go` | Modified - added SQLite and CRUD | | `internal/handlers/posts.go` | Created | | `internal/server/routes.go` | Modified - added post routes | | `internal/config/config.go` | Modified - added default DBURL |