Detalhes das alterações: [Banco de Dados] - Ajuste nas constraints UNIQUE das tabelas de catálogo (cursos, empresas, tipos_eventos, etc.) para incluir a coluna `regiao`, permitindo dados duplicados entre regiões mas únicos por região. - Correção crítica na constraint da tabela `precos_tipos_eventos` para evitar conflitos de UPSERT (ON CONFLICT) durante a inicialização. - Implementação de lógica de Seed para a região 'MG': - Clonagem automática de catálogos base de 'SP' para 'MG' (Tipos de Evento, Serviços, etc.). - Inserção de tabela de preços específica para 'MG' via script de migração. [Backend - Go] - Atualização geral dos Handlers e Services para filtrar dados baseados no cabeçalho `x-regiao`. - Ajuste no Middleware de autenticação para processar e repassar o contexto da região. - Correção de queries SQL (geradas pelo sqlc) para suportar os novos filtros regionais. [Frontend - React] - Implementação do envio global do cabeçalho `x-regiao` nas requisições da API. - Correção no componente [PriceTableEditor](cci:1://file:///c:/Projetos/photum/frontend/components/System/PriceTableEditor.tsx:26:0-217:2) para carregar e salvar preços respeitando a região selecionada (fix de "Preços zerados" em MG). - Refatoração profunda na tela de Importação ([ImportData.tsx](cci:7://file:///c:/Projetos/photum/frontend/pages/ImportData.tsx:0:0-0:0)): - Adição de feedback visual detalhado para registros ignorados. - Categorização explícita de erros: "CPF Inválido", "Região Incompatível", "Linha Vazia/Separador". - Correção na lógica de contagem para considerar linhas vazias explicitamente no relatório final, garantindo que o total bata com o Excel. [Geral] - Correção de diversos erros de lint e tipagem TSX. - Padronização de logs de erro no backend para facilitar debug.
90 lines
2.5 KiB
Go
90 lines
2.5 KiB
Go
package anos_formaturas
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"regexp"
|
|
|
|
"photum-backend/internal/db/generated"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type Service struct {
|
|
queries *generated.Queries
|
|
}
|
|
|
|
func NewService(queries *generated.Queries) *Service {
|
|
return &Service{queries: queries}
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, anoSemestre string, regiao string) (*generated.AnosFormatura, error) {
|
|
// Validate format YYYY.S
|
|
matched, _ := regexp.MatchString(`^\d{4}\.[1-2]$`, anoSemestre)
|
|
if !matched {
|
|
return nil, errors.New("invalid format. Expected YYYY.1 or YYYY.2")
|
|
}
|
|
|
|
ano, err := s.queries.CreateAnoFormatura(ctx, generated.CreateAnoFormaturaParams{
|
|
AnoSemestre: anoSemestre,
|
|
Regiao: pgtype.Text{String: regiao, Valid: true},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ano, nil
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context, regiao string) ([]generated.AnosFormatura, error) {
|
|
return s.queries.ListAnosFormaturas(ctx, pgtype.Text{String: regiao, Valid: true})
|
|
}
|
|
|
|
func (s *Service) GetByID(ctx context.Context, id string, regiao string) (*generated.AnosFormatura, error) {
|
|
uuidVal, err := uuid.Parse(id)
|
|
if err != nil {
|
|
return nil, errors.New("invalid id")
|
|
}
|
|
ano, err := s.queries.GetAnoFormaturaByID(ctx, generated.GetAnoFormaturaByIDParams{
|
|
ID: pgtype.UUID{Bytes: uuidVal, Valid: true},
|
|
Regiao: pgtype.Text{String: regiao, Valid: true},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ano, nil
|
|
}
|
|
|
|
func (s *Service) Update(ctx context.Context, id, anoSemestre string, regiao string) (*generated.AnosFormatura, error) {
|
|
uuidVal, err := uuid.Parse(id)
|
|
if err != nil {
|
|
return nil, errors.New("invalid id")
|
|
}
|
|
|
|
// Validate format YYYY.S
|
|
matched, _ := regexp.MatchString(`^\d{4}\.[1-2]$`, anoSemestre)
|
|
if !matched {
|
|
return nil, errors.New("invalid format. Expected YYYY.1 or YYYY.2")
|
|
}
|
|
|
|
ano, err := s.queries.UpdateAnoFormatura(ctx, generated.UpdateAnoFormaturaParams{
|
|
ID: pgtype.UUID{Bytes: uuidVal, Valid: true},
|
|
AnoSemestre: anoSemestre,
|
|
Regiao: pgtype.Text{String: regiao, Valid: true},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ano, nil
|
|
}
|
|
|
|
func (s *Service) Delete(ctx context.Context, id string, regiao string) error {
|
|
uuidVal, err := uuid.Parse(id)
|
|
if err != nil {
|
|
return errors.New("invalid id")
|
|
}
|
|
return s.queries.DeleteAnoFormatura(ctx, generated.DeleteAnoFormaturaParams{
|
|
ID: pgtype.UUID{Bytes: uuidVal, Valid: true},
|
|
Regiao: pgtype.Text{String: regiao, Valid: true},
|
|
})
|
|
}
|