Initial commit: Plataforma de Economía
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
This commit is contained in:
71
backend/internal/handlers/contenido.go
Normal file
71
backend/internal/handlers/contenido.go
Normal file
@@ -0,0 +1,71 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user