Features: - React 18 + TypeScript frontend with Vite - Go + Gin backend API - PostgreSQL database - JWT authentication with refresh tokens - User management (admin panel) - Docker containerization - Progress tracking system - 4 economic modules structure Fixed: - Login with username or email - User creation without required email - Database nullable timestamps - API response field naming
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ren/econ/backend/internal/models"
|
|
"github.com/ren/econ/backend/internal/repository"
|
|
)
|
|
|
|
type ContenidoHandler struct {
|
|
contenidoRepo *repository.ContenidoRepository
|
|
}
|
|
|
|
func NewContenidoHandler(contenidoRepo *repository.ContenidoRepository) *ContenidoHandler {
|
|
return &ContenidoHandler{contenidoRepo: contenidoRepo}
|
|
}
|
|
|
|
// GetModulos godoc
|
|
// @Summary Listar módulos
|
|
// @Description Lista todos los módulos disponibles
|
|
// @Tags contenido
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {array} models.ModuloResumen
|
|
// @Router /api/contenido/modulos [get]
|
|
func (h *ContenidoHandler) GetModulos(c *gin.Context) {
|
|
modulos, err := h.contenidoRepo.GetModulos(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al obtener módulos"})
|
|
return
|
|
}
|
|
|
|
if modulos == nil {
|
|
modulos = []models.ModuloResumen{}
|
|
}
|
|
|
|
c.JSON(http.StatusOK, modulos)
|
|
}
|
|
|
|
// GetModulo godoc
|
|
// @Summary Obtener contenido de módulo
|
|
// @Description Obtiene el contenido de un módulo específico
|
|
// @Tags contenido
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param numero path int true "Número del módulo"
|
|
// @Success 200 {object} models.Modulo
|
|
// @Router /api/contenido/modulos/{numero} [get]
|
|
func (h *ContenidoHandler) GetModulo(c *gin.Context) {
|
|
moduloNumero, err := strconv.Atoi(c.Param("numero"))
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Número de módulo inválido"})
|
|
return
|
|
}
|
|
|
|
modulo, err := h.contenidoRepo.GetModulo(c.Request.Context(), moduloNumero)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al obtener módulo"})
|
|
return
|
|
}
|
|
|
|
if modulo == nil || len(modulo.Ejercicios) == 0 {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "Módulo no encontrado"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, modulo)
|
|
}
|