Implement remaining handlers and fix admin login
- Fix admin login bcrypt hash in database migrations - Add static data handler (GET /api/static_data/, POST /api/static_data/refresh/) - Add user handler (list users, get user, list profiles in shared residences) - Add generate tasks report endpoint for residences - Remove all placeholder handlers from router - Add seeding documentation to README New files: - internal/handlers/static_data_handler.go - internal/handlers/user_handler.go - internal/services/user_service.go - internal/dto/responses/user.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -379,3 +379,102 @@ func (s *ResidenceService) GetResidenceTypes() ([]responses.ResidenceTypeRespons
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// TaskReportData represents task data for a report
|
||||
type TaskReportData struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Priority string `json:"priority"`
|
||||
Status string `json:"status"`
|
||||
DueDate *time.Time `json:"due_date,omitempty"`
|
||||
IsCompleted bool `json:"is_completed"`
|
||||
IsCancelled bool `json:"is_cancelled"`
|
||||
IsArchived bool `json:"is_archived"`
|
||||
}
|
||||
|
||||
// TasksReportResponse represents the generated tasks report
|
||||
type TasksReportResponse struct {
|
||||
ResidenceID uint `json:"residence_id"`
|
||||
ResidenceName string `json:"residence_name"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
TotalTasks int `json:"total_tasks"`
|
||||
Completed int `json:"completed"`
|
||||
Pending int `json:"pending"`
|
||||
Overdue int `json:"overdue"`
|
||||
Tasks []TaskReportData `json:"tasks"`
|
||||
}
|
||||
|
||||
// GenerateTasksReport generates a report of all tasks for a residence
|
||||
func (s *ResidenceService) GenerateTasksReport(residenceID, userID uint) (*TasksReportResponse, error) {
|
||||
// Check access
|
||||
hasAccess, err := s.residenceRepo.HasAccess(residenceID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !hasAccess {
|
||||
return nil, ErrResidenceAccessDenied
|
||||
}
|
||||
|
||||
// Get residence details
|
||||
residence, err := s.residenceRepo.FindByIDSimple(residenceID)
|
||||
if err != nil {
|
||||
return nil, ErrResidenceNotFound
|
||||
}
|
||||
|
||||
// Get all tasks for the residence
|
||||
tasks, err := s.residenceRepo.GetTasksForReport(residenceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
report := &TasksReportResponse{
|
||||
ResidenceID: residence.ID,
|
||||
ResidenceName: residence.Name,
|
||||
GeneratedAt: now,
|
||||
TotalTasks: len(tasks),
|
||||
Tasks: make([]TaskReportData, len(tasks)),
|
||||
}
|
||||
|
||||
for i, task := range tasks {
|
||||
// Determine if task is completed (has completions)
|
||||
isCompleted := len(task.Completions) > 0
|
||||
|
||||
taskData := TaskReportData{
|
||||
ID: task.ID,
|
||||
Title: task.Title,
|
||||
Description: task.Description,
|
||||
IsCompleted: isCompleted,
|
||||
IsCancelled: task.IsCancelled,
|
||||
IsArchived: task.IsArchived,
|
||||
}
|
||||
|
||||
if task.Category != nil {
|
||||
taskData.Category = task.Category.Name
|
||||
}
|
||||
if task.Priority != nil {
|
||||
taskData.Priority = task.Priority.Name
|
||||
}
|
||||
if task.Status != nil {
|
||||
taskData.Status = task.Status.Name
|
||||
}
|
||||
if task.DueDate != nil {
|
||||
taskData.DueDate = task.DueDate
|
||||
}
|
||||
|
||||
report.Tasks[i] = taskData
|
||||
|
||||
if isCompleted {
|
||||
report.Completed++
|
||||
} else if !task.IsCancelled && !task.IsArchived {
|
||||
report.Pending++
|
||||
if task.DueDate != nil && task.DueDate.Before(now) {
|
||||
report.Overdue++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return report, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user