9f673bfca3
Remove soft delete from HabitEntry: - Eliminate DeletedAt field from entity and database - Change UnmarkHabit from soft delete to hard delete - Simplify all queries removing deleted_at checks - Update migration to remove deleted_at column Add date filtering and smart pagination to GetHabitEntries: - Support optional from/to date parameters - Implement intelligent pagination rules: * No date range: pagination required * Date range > 1 year: pagination required * Date range ≤ 1 year: pagination optional - Pagination defaults (page=1, limit=50) only when required - Return metadata with total count, page, and limit Technical improvements: - Cleaner codebase without soft delete complexity - Better performance (no filtering in queries) - More intuitive API with flexible pagination - Comprehensive test coverage for validation rules
82 lines
2.6 KiB
Go
82 lines
2.6 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 HabitEntriesResponse struct {
|
|
Entries []HabitEntryResponse `json:"entries"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
Limit int `json:"limit"`
|
|
}
|
|
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
}
|