Prepara versao dev 1.0
This commit is contained in:
42
backend/internal/api/handlers/tenant.go
Normal file
42
backend/internal/api/handlers/tenant.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"aggios-app/backend/internal/domain"
|
||||
"aggios-app/backend/internal/service"
|
||||
)
|
||||
|
||||
// TenantHandler handles tenant/agency listing endpoints
|
||||
type TenantHandler struct {
|
||||
tenantService *service.TenantService
|
||||
}
|
||||
|
||||
// NewTenantHandler creates a new tenant handler
|
||||
func NewTenantHandler(tenantService *service.TenantService) *TenantHandler {
|
||||
return &TenantHandler{
|
||||
tenantService: tenantService,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAll lists all agencies/tenants (SUPERADMIN only)
|
||||
func (h *TenantHandler) ListAll(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
tenants, err := h.tenantService.ListAll()
|
||||
if err != nil {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if tenants == nil {
|
||||
tenants = []*domain.Tenant{}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
json.NewEncoder(w).Encode(tenants)
|
||||
}
|
||||
Reference in New Issue
Block a user