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.
141 lines
3.9 KiB
Go
141 lines
3.9 KiB
Go
package anos_formaturas
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"photum-backend/internal/db/generated"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Handler struct {
|
|
service *Service
|
|
}
|
|
|
|
func NewHandler(service *Service) *Handler {
|
|
return &Handler{service: service}
|
|
}
|
|
|
|
type AnoFormaturaResponse struct {
|
|
ID string `json:"id"`
|
|
AnoSemestre string `json:"ano_semestre"`
|
|
}
|
|
|
|
type CreateAnoFormaturaRequest struct {
|
|
AnoSemestre string `json:"ano_semestre" binding:"required" example:"2029.1"`
|
|
}
|
|
|
|
func toResponse(a generated.AnosFormatura) AnoFormaturaResponse {
|
|
return AnoFormaturaResponse{
|
|
ID: uuid.UUID(a.ID.Bytes).String(),
|
|
AnoSemestre: a.AnoSemestre,
|
|
}
|
|
}
|
|
|
|
// Create godoc
|
|
// @Summary Create a new graduation year
|
|
// @Tags anos_formaturas
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param request body CreateAnoFormaturaRequest true "Ano Semestre"
|
|
// @Success 201 {object} AnoFormaturaResponse
|
|
// @Failure 400 {object} map[string]string
|
|
// @Failure 409 {object} map[string]string
|
|
// @Router /api/anos-formaturas [post]
|
|
func (h *Handler) Create(c *gin.Context) {
|
|
var req CreateAnoFormaturaRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
regiao := c.GetString("regiao")
|
|
ano, err := h.service.Create(c.Request.Context(), req.AnoSemestre, regiao)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), "duplicate key value") {
|
|
c.JSON(http.StatusConflict, gin.H{"error": "Ano/Semestre already exists"})
|
|
return
|
|
}
|
|
if strings.Contains(err.Error(), "invalid format") {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, toResponse(*ano))
|
|
}
|
|
|
|
// List godoc
|
|
// @Summary List all graduation years
|
|
// @Tags anos_formaturas
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {array} AnoFormaturaResponse
|
|
// @Router /api/anos-formaturas [get]
|
|
func (h *Handler) List(c *gin.Context) {
|
|
regiao := c.GetString("regiao")
|
|
anos, err := h.service.List(c.Request.Context(), regiao)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
var response []AnoFormaturaResponse
|
|
for _, ano := range anos {
|
|
response = append(response, toResponse(ano))
|
|
}
|
|
c.JSON(http.StatusOK, response)
|
|
}
|
|
|
|
// Update godoc
|
|
// @Summary Update a graduation year
|
|
// @Tags anos_formaturas
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param id path string true "ID"
|
|
// @Param request body CreateAnoFormaturaRequest true "Ano Semestre"
|
|
// @Success 200 {object} AnoFormaturaResponse
|
|
// @Router /api/anos-formaturas/{id} [put]
|
|
func (h *Handler) Update(c *gin.Context) {
|
|
id := c.Param("id")
|
|
var req CreateAnoFormaturaRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
regiao := c.GetString("regiao")
|
|
ano, err := h.service.Update(c.Request.Context(), id, req.AnoSemestre, regiao)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, toResponse(*ano))
|
|
}
|
|
|
|
// Delete godoc
|
|
// @Summary Delete a graduation year
|
|
// @Tags anos_formaturas
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param id path string true "ID"
|
|
// @Success 204 {object} nil
|
|
// @Router /api/anos-formaturas/{id} [delete]
|
|
func (h *Handler) Delete(c *gin.Context) {
|
|
id := c.Param("id")
|
|
regiao := c.GetString("regiao")
|
|
if err := h.service.Delete(c.Request.Context(), id, regiao); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|