Private
Public Access
refactor: ahora los repos se acceden con un singleton en vez de inyecion
de dependencias
This commit is contained in:
1 parent
52fc779abd
commit
141715ee0a
22 files changed
+244
-211
No files matched your search
@@ -4,21 +4,13 @@ import (
|
||||
"net/http"
|
||||
|
||||
"repuestera_back/dto"
|
||||
repositorios "repuestera_back/repositorios"
|
||||
r "repuestera_back/repositorios"
|
||||
"repuestera_back/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var usuarioRepo repositorios.RepositorioUsuario
|
||||
var grupoRepo repositorios.RepositorioGrupo
|
||||
|
||||
func InitUsuarioRepository(repo repositorios.RepositorioUsuario, repog repositorios.RepositorioGrupo) {
|
||||
usuarioRepo = repo
|
||||
grupoRepo = repog
|
||||
}
|
||||
|
||||
func CambiarContraseña(c *gin.Context) {
|
||||
var req dto.CambiarContraseñaRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -46,7 +38,7 @@ func CambiarContraseña(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := usuarioRepo.ObtenerPorID(targetID)
|
||||
user, err := r.ObtenerRepositorios().Usuario.ObtenerPorID(targetID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "usuario no encontrado"})
|
||||
return
|
||||
@@ -69,7 +61,7 @@ func CambiarContraseña(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := usuarioRepo.ActualizarContraseña(user.ID, string(hashedPassword)); err != nil {
|
||||
if err := r.ObtenerRepositorios().Usuario.ActualizarContraseña(user.ID, string(hashedPassword)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al actualizar la contraseña"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user