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:
2025-11-26 00:41:05 +01:00
parent 76893bd114
commit 3e8883d878
6 changed files with 341 additions and 2 deletions
+7 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/go-chi/cors"
)
func NewRouter(corsOrigins string) *chi.Mux {
func NewRouter(corsOrigins string, habitHandlers *HabitHandlers) *chi.Mux {
r := chi.NewRouter()
r.Use(middleware.Logger)
@@ -25,5 +25,11 @@ func NewRouter(corsOrigins string) *chi.Mux {
w.Write([]byte(`{"status":"ok"}`))
})
r.Route("/api/v1/habits", func(r chi.Router) {
r.Post("/", habitHandlers.CreateHabit)
r.Get("/today", habitHandlers.GetTodaysHabits)
r.Post("/{id}/mark", habitHandlers.MarkHabit)
})
return r
}