chore(release): snapshot 1.4.2
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"aggios-app/backend/internal/config"
|
||||
"aggios-app/backend/internal/domain"
|
||||
"aggios-app/backend/internal/repository"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -15,14 +16,16 @@ type AgencyService struct {
|
||||
userRepo *repository.UserRepository
|
||||
tenantRepo *repository.TenantRepository
|
||||
cfg *config.Config
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// NewAgencyService creates a new agency service
|
||||
func NewAgencyService(userRepo *repository.UserRepository, tenantRepo *repository.TenantRepository, cfg *config.Config) *AgencyService {
|
||||
func NewAgencyService(userRepo *repository.UserRepository, tenantRepo *repository.TenantRepository, cfg *config.Config, db *sql.DB) *AgencyService {
|
||||
return &AgencyService{
|
||||
userRepo: userRepo,
|
||||
tenantRepo: tenantRepo,
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +183,43 @@ func (s *AgencyService) GetAgencyDetails(id uuid.UUID) (*domain.AgencyDetails, e
|
||||
details.Admin = admin
|
||||
}
|
||||
|
||||
// Buscar subscription e soluções
|
||||
var subscription domain.AgencySubscriptionInfo
|
||||
query := `
|
||||
SELECT
|
||||
s.plan_id,
|
||||
p.name as plan_name,
|
||||
s.status
|
||||
FROM agency_subscriptions s
|
||||
JOIN plans p ON s.plan_id = p.id
|
||||
WHERE s.agency_id = $1
|
||||
LIMIT 1
|
||||
`
|
||||
err = s.db.QueryRow(query, id).Scan(&subscription.PlanID, &subscription.PlanName, &subscription.Status)
|
||||
if err == nil {
|
||||
// Buscar soluções do plano
|
||||
solutionsQuery := `
|
||||
SELECT sol.id, sol.name, sol.slug, sol.icon
|
||||
FROM solutions sol
|
||||
JOIN plan_solutions ps ON sol.id = ps.solution_id
|
||||
WHERE ps.plan_id = $1
|
||||
ORDER BY sol.name
|
||||
`
|
||||
rows, err := s.db.Query(solutionsQuery, subscription.PlanID)
|
||||
if err == nil {
|
||||
defer rows.Close()
|
||||
var solutions []domain.Solution
|
||||
for rows.Next() {
|
||||
var solution domain.Solution
|
||||
if err := rows.Scan(&solution.ID, &solution.Name, &solution.Slug, &solution.Icon); err == nil {
|
||||
solutions = append(solutions, solution)
|
||||
}
|
||||
}
|
||||
subscription.Solutions = solutions
|
||||
details.Subscription = &subscription
|
||||
}
|
||||
}
|
||||
|
||||
return details, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,14 @@ var (
|
||||
// TenantService handles tenant business logic
|
||||
type TenantService struct {
|
||||
tenantRepo *repository.TenantRepository
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// NewTenantService creates a new tenant service
|
||||
func NewTenantService(tenantRepo *repository.TenantRepository) *TenantService {
|
||||
func NewTenantService(tenantRepo *repository.TenantRepository, db *sql.DB) *TenantService {
|
||||
return &TenantService{
|
||||
tenantRepo: tenantRepo,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +81,84 @@ func (s *TenantService) ListAll() ([]*domain.Tenant, error) {
|
||||
return s.tenantRepo.FindAll()
|
||||
}
|
||||
|
||||
// ListAllWithDetails retrieves all tenants with their plan and solutions information
|
||||
func (s *TenantService) ListAllWithDetails() ([]map[string]interface{}, error) {
|
||||
tenants, err := s.tenantRepo.FindAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []map[string]interface{}
|
||||
for _, tenant := range tenants {
|
||||
tenantData := map[string]interface{}{
|
||||
"id": tenant.ID,
|
||||
"name": tenant.Name,
|
||||
"subdomain": tenant.Subdomain,
|
||||
"domain": tenant.Domain,
|
||||
"email": tenant.Email,
|
||||
"phone": tenant.Phone,
|
||||
"cnpj": tenant.CNPJ,
|
||||
"is_active": tenant.IsActive,
|
||||
"created_at": tenant.CreatedAt,
|
||||
"logo_url": tenant.LogoURL,
|
||||
"logo_horizontal_url": tenant.LogoHorizontalURL,
|
||||
"primary_color": tenant.PrimaryColor,
|
||||
"secondary_color": tenant.SecondaryColor,
|
||||
}
|
||||
|
||||
// Buscar subscription e soluções
|
||||
var planName sql.NullString
|
||||
var planID string
|
||||
query := `
|
||||
SELECT
|
||||
s.plan_id,
|
||||
p.name as plan_name
|
||||
FROM agency_subscriptions s
|
||||
JOIN plans p ON s.plan_id = p.id
|
||||
WHERE s.agency_id = $1 AND s.status = 'active'
|
||||
LIMIT 1
|
||||
`
|
||||
err = s.db.QueryRow(query, tenant.ID).Scan(&planID, &planName)
|
||||
if err == nil && planName.Valid {
|
||||
tenantData["plan_name"] = planName.String
|
||||
|
||||
// Buscar soluções do plano
|
||||
solutionsQuery := `
|
||||
SELECT sol.id, sol.name, sol.slug, sol.icon
|
||||
FROM solutions sol
|
||||
JOIN plan_solutions ps ON sol.id = ps.solution_id
|
||||
WHERE ps.plan_id = $1
|
||||
ORDER BY sol.name
|
||||
`
|
||||
rows, err := s.db.Query(solutionsQuery, planID)
|
||||
if err == nil {
|
||||
defer rows.Close()
|
||||
var solutions []map[string]interface{}
|
||||
for rows.Next() {
|
||||
var id, name, slug string
|
||||
var icon sql.NullString
|
||||
if err := rows.Scan(&id, &name, &slug, &icon); err == nil {
|
||||
solution := map[string]interface{}{
|
||||
"id": id,
|
||||
"name": name,
|
||||
"slug": slug,
|
||||
}
|
||||
if icon.Valid {
|
||||
solution["icon"] = icon.String
|
||||
}
|
||||
solutions = append(solutions, solution)
|
||||
}
|
||||
}
|
||||
tenantData["solutions"] = solutions
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, tenantData)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Delete removes a tenant by ID
|
||||
func (s *TenantService) Delete(id uuid.UUID) error {
|
||||
if err := s.tenantRepo.Delete(id); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user