Private
Public Access
feat: hecha funcionalidad del cu-12
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
5a8d4bc2d6
commit
37d357357a
14 files changed
+672
-116
No files matched your search
@@ -1,21 +1,53 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
applog "log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
dto "repuestera_back/dto/Stock"
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerReservas(c *gin.Context) {
|
||||
filtros := r.FiltrosReserva{}
|
||||
_ = filtros
|
||||
var q dto.FiltrosReservaQuery
|
||||
if err := c.ShouldBindQuery(&q); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if !estadoReservaValido(q.Estado) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "estado de reserva inválido"})
|
||||
return
|
||||
}
|
||||
|
||||
reservas, err := r.ObtenerRepositorios(c).Reserva.ListarActivas(filtros)
|
||||
repo := r.ObtenerRepositorios(c)
|
||||
|
||||
// D9: las reservas vencidas se procesan de forma lazy al consultar.
|
||||
if err := marcarReservasVencidas(r.BaseDeDatos(), repo, c.GetUint("userID"), time.Now()); err != nil {
|
||||
applog.Printf("stock: no se pudieron procesar las reservas vencidas: %v", err)
|
||||
}
|
||||
|
||||
reservas, err := repo.Reserva.ListarActivas(q)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, reservas)
|
||||
}
|
||||
|
||||
func estadoReservaValido(estado string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(estado)) {
|
||||
case "", "todas",
|
||||
string(models.ReservaActiva),
|
||||
string(models.ReservaVencida),
|
||||
string(models.ReservaLiberada),
|
||||
string(models.ReservaConsumida):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user