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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user