Add contractors by residence endpoint and Bruno API collection

- Add GET /contractors/by-residence/:residence_id/ endpoint
- Create comprehensive Bruno API collection (89 endpoints)
- Collection covers all API endpoints with Local and Dev environments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-01 20:38:57 -06:00
parent 0c86611a10
commit c72741fd5f
89 changed files with 1622 additions and 0 deletions

View File

@@ -181,6 +181,27 @@ func (h *ContractorHandler) GetContractorTasks(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// ListContractorsByResidence handles GET /api/contractors/by-residence/:residence_id/
func (h *ContractorHandler) ListContractorsByResidence(c *gin.Context) {
user := c.MustGet(middleware.AuthUserKey).(*models.User)
residenceID, err := strconv.ParseUint(c.Param("residence_id"), 10, 32)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid residence ID"})
return
}
response, err := h.contractorService.ListContractorsByResidence(uint(residenceID), user.ID)
if err != nil {
if errors.Is(err, services.ErrResidenceAccessDenied) {
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, response)
}
// GetSpecialties handles GET /api/contractors/specialties/
func (h *ContractorHandler) GetSpecialties(c *gin.Context) {
specialties, err := h.contractorService.GetSpecialties()

View File

@@ -270,6 +270,7 @@ func setupContractorRoutes(api *gin.RouterGroup, contractorHandler *handlers.Con
{
contractors.GET("/", contractorHandler.ListContractors)
contractors.POST("/", contractorHandler.CreateContractor)
contractors.GET("/by-residence/:residence_id/", contractorHandler.ListContractorsByResidence)
contractors.GET("/:id/", contractorHandler.GetContractor)
contractors.PUT("/:id/", contractorHandler.UpdateContractor)
contractors.PATCH("/:id/", contractorHandler.UpdateContractor)

View File

@@ -294,6 +294,25 @@ func (s *ContractorService) GetContractorTasks(contractorID, userID uint) ([]res
return responses.NewTaskListResponse(tasks), nil
}
// ListContractorsByResidence lists all contractors for a specific residence
func (s *ContractorService) ListContractorsByResidence(residenceID, userID uint) ([]responses.ContractorResponse, error) {
// Check user has access to the residence
hasAccess, err := s.residenceRepo.HasAccess(residenceID, userID)
if err != nil {
return nil, err
}
if !hasAccess {
return nil, ErrResidenceAccessDenied
}
contractors, err := s.contractorRepo.FindByResidence(residenceID)
if err != nil {
return nil, err
}
return responses.NewContractorListResponse(contractors), nil
}
// GetSpecialties returns all contractor specialties
func (s *ContractorService) GetSpecialties() ([]responses.ContractorSpecialtyResponse, error) {
specialties, err := s.contractorRepo.GetAllSpecialties()