Add habit HTTP endpoints
- Create DTOs for HTTP requests and responses
- Implement habit handlers (create, get today's, mark)
- Register routes in router: POST /habits, GET /habits/today, POST /habits/{id}/mark
- Add missing repository methods (FindByID, FindByHabitID, FindPendingByHabitID, Delete)
- Wire up dependencies in main.go
- Tested with curl: create, list, mark habits work correctly
This commit is contained in:
+12
-1
@@ -5,6 +5,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"habit-tracker-api/internal/application/commands"
|
||||
"habit-tracker-api/internal/application/queries"
|
||||
"habit-tracker-api/internal/infrastructure/config"
|
||||
httpInfra "habit-tracker-api/internal/infrastructure/http"
|
||||
"habit-tracker-api/internal/infrastructure/persistence/sqlite"
|
||||
@@ -22,7 +24,16 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
router := httpInfra.NewRouter(cfg.CORSOrigins)
|
||||
habitRepo := sqlite.NewHabitRepository(db.Conn())
|
||||
entryRepo := sqlite.NewHabitEntryRepository(db.Conn())
|
||||
|
||||
createHandler := commands.NewCreateHabitHandler(habitRepo)
|
||||
getTodaysHandler := queries.NewGetTodaysHabitsHandler(habitRepo, entryRepo)
|
||||
markHandler := commands.NewMarkHabitHandler(entryRepo, habitRepo)
|
||||
|
||||
habitHandlers := httpInfra.NewHabitHandlers(createHandler, getTodaysHandler, markHandler)
|
||||
|
||||
router := httpInfra.NewRouter(cfg.CORSOrigins, habitHandlers)
|
||||
|
||||
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
|
||||
log.Printf("Server starting on %s", addr)
|
||||
|
||||
Reference in New Issue
Block a user