74cd2ec84d
Implement all missing endpoints for full habit management:
- GET /api/v1/habits - List all user habits
- GET /api/v1/habits/{id} - Get specific habit
- PUT /api/v1/habits/{id} - Update habit
- DELETE /api/v1/habits/{id} - Archive habit (soft delete)
- GET /api/v1/habits/{id}/entries - Get habit entry history
- DELETE /api/v1/habits/{id}/entries/{date} - Unmark habit (soft delete entry)
All endpoints include:
- TDD approach with comprehensive test coverage
- JWT authentication and ownership validation
- Proper error handling (404, 403, 400, 500)
- Clean architecture with separated commands/queries
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
package http
|
|
|
|
import "time"
|
|
|
|
type CreateHabitRequest struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Type string `json:"type"`
|
|
Frequency string `json:"frequency"`
|
|
SpecificDays []int `json:"specific_days,omitempty"`
|
|
SpecificDates []int `json:"specific_dates,omitempty"`
|
|
CarryOver bool `json:"carry_over"`
|
|
TargetValue *float64 `json:"target_value,omitempty"`
|
|
}
|
|
|
|
type UpdateHabitRequest struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
SpecificDays []int `json:"specific_days,omitempty"`
|
|
SpecificDates []int `json:"specific_dates,omitempty"`
|
|
CarryOver bool `json:"carry_over"`
|
|
TargetValue *float64 `json:"target_value,omitempty"`
|
|
}
|
|
|
|
type HabitResponse struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Type string `json:"type"`
|
|
Frequency string `json:"frequency"`
|
|
SpecificDays []int `json:"specific_days,omitempty"`
|
|
SpecificDates []int `json:"specific_dates,omitempty"`
|
|
CarryOver bool `json:"carry_over"`
|
|
TargetValue *float64 `json:"target_value,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
ArchivedAt *time.Time `json:"archived_at,omitempty"`
|
|
}
|
|
|
|
type MarkHabitRequest struct {
|
|
ScheduledDate string `json:"scheduled_date"`
|
|
Value *float64 `json:"value,omitempty"`
|
|
}
|
|
|
|
type TodaysHabitResponse struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
TargetValue *float64 `json:"target_value,omitempty"`
|
|
ScheduledDate time.Time `json:"scheduled_date"`
|
|
IsCarriedOver bool `json:"is_carried_over"`
|
|
}
|
|
|
|
type UserHabitResponse struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Frequency string `json:"frequency"`
|
|
SpecificDays []int `json:"specific_days,omitempty"`
|
|
TargetValue *float64 `json:"target_value,omitempty"`
|
|
CarryOver bool `json:"carry_over"`
|
|
}
|
|
|
|
type HabitEntryResponse struct {
|
|
ID string `json:"id"`
|
|
HabitID string `json:"habit_id"`
|
|
ScheduledDate time.Time `json:"scheduled_date"`
|
|
CompletedAt time.Time `json:"completed_at"`
|
|
Value *float64 `json:"value,omitempty"`
|
|
}
|
|
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
}
|