refactor: ahora los repos se acceden con un singleton en vez de inyecion

de dependencias
This commit is contained in:
fede committed 2026-06-14 02:58:56 -03:00
1 parent 52fc779abd
commit 141715ee0a
22 files changed
+244 -211

No files matched your search

+5 -4
View File
@@ -6,6 +6,7 @@ import (
"repuestera_back/dto"
models_seguridad "repuestera_back/models/seguridad"
r "repuestera_back/repositorios"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/bcrypt"
@@ -20,7 +21,7 @@ func Register(c *gin.Context) {
email := strings.ToLower(strings.TrimSpace(req.Email))
if _, err := usuarioRepo.ObtenerPorEmail(email); err == nil {
if _, err := r.ObtenerRepositorios().Usuario.ObtenerPorEmail(email); err == nil {
c.JSON(http.StatusConflict, gin.H{"error": "El email ya esta registrado"})
return
}
@@ -39,9 +40,9 @@ func Register(c *gin.Context) {
//checkeo para ver si hay usuarios añadidos
var cantUsuarios int64
usuarioRepo.CantidadUsuarios(&cantUsuarios)
r.ObtenerRepositorios().Usuario.CantidadUsuarios(&cantUsuarios)
if (cantUsuarios < 1){
admin, err := grupoRepo.ObtenerPorID(1)
admin, err := r.ObtenerRepositorios().Grupo.ObtenerPorID(1)
if err != nil{
c.JSON(http.StatusInternalServerError, gin.H{"error": "Hay un problema con la base de datos: Faltan Grupos?"})
return
@@ -49,7 +50,7 @@ func Register(c *gin.Context) {
user.Grupos = append(user.Grupos, *admin)
}
if err := usuarioRepo.Crear(&user); err != nil {
if err := r.ObtenerRepositorios().Usuario.Crear(&user); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}