- Create CreatePlanModal component with Headless UI Dialog - Implement dark mode support throughout plans UI - Update plans/page.tsx with professional card layout - Update plans/[id]/page.tsx with consistent styling - Add proper spacing, typography, and color consistency - Implement smooth animations and transitions - Add success/error message feedback - Improve form UX with better input styling
109 lines
2.8 KiB
Go
109 lines
2.8 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"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)
|
|
}
|
|
|
|
// CheckExists returns 200 if tenant exists by subdomain, otherwise 404
|
|
func (h *TenantHandler) CheckExists(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
subdomain := r.URL.Query().Get("subdomain")
|
|
if subdomain == "" {
|
|
http.Error(w, "subdomain is required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
_, err := h.tenantService.GetBySubdomain(subdomain)
|
|
if err != nil {
|
|
if err == service.ErrTenantNotFound {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
|
}
|
|
|
|
// GetPublicConfig returns public branding info for a tenant by subdomain
|
|
func (h *TenantHandler) GetPublicConfig(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
subdomain := r.URL.Query().Get("subdomain")
|
|
if subdomain == "" {
|
|
http.Error(w, "subdomain is required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
tenant, err := h.tenantService.GetBySubdomain(subdomain)
|
|
if err != nil {
|
|
if err == service.ErrTenantNotFound {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
// Return only public info
|
|
response := map[string]string{
|
|
"name": tenant.Name,
|
|
"primary_color": tenant.PrimaryColor,
|
|
"secondary_color": tenant.SecondaryColor,
|
|
"logo_url": tenant.LogoURL,
|
|
"logo_horizontal_url": tenant.LogoHorizontalURL,
|
|
}
|
|
|
|
log.Printf("📤 Returning tenant config for %s: logo_url=%s", subdomain, tenant.LogoURL)
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
json.NewEncoder(w).Encode(response)
|
|
}
|