Private
Public Access
algunos refactors y arregle el tema de que no se eliminaban los
subgrupos
This commit is contained in:
1 parent
ab88be0ba5
commit
df2412f29a
25 files changed
+415
-261
No files matched your search
@@ -3,7 +3,6 @@ package auth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
"repuestera_back/utils"
|
||||
|
||||
@@ -12,7 +11,11 @@ import (
|
||||
)
|
||||
|
||||
func CambiarContraseña(c *gin.Context) {
|
||||
var req dto.CambiarContraseñaRequest
|
||||
var req struct {
|
||||
UserID uint `json:"user_id"`
|
||||
OldPassword string `json:"old_password"`
|
||||
NewPassword string `json:"new_password" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -16,7 +16,10 @@ import (
|
||||
)
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
var req dto.LoginRequest
|
||||
var req struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -13,7 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func Refresh(c *gin.Context) {
|
||||
var req dto.RefreshRequest
|
||||
var req struct {
|
||||
RefreshToken string `json:"refresh_token" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -13,7 +13,11 @@ import (
|
||||
)
|
||||
|
||||
func Register(c *gin.Context) {
|
||||
var req dto.RegisterRequest
|
||||
var req struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Password string `json:"password" binding:"required,min=6"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -2,14 +2,16 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AgregarGrupoAUsuario(c *gin.Context) {
|
||||
var req dto.GrupoUsuarioRelacion
|
||||
var req struct {
|
||||
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
@@ -2,7 +2,6 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
@@ -10,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func AgregarPermisoAGrupo(c *gin.Context) {
|
||||
var req dto.GrupoPermisoRequest
|
||||
var req struct {
|
||||
PermisoID uint `json:"permission_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -2,7 +2,6 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
@@ -10,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func AgregarSubGrupo(c *gin.Context) {
|
||||
var req dto.GrupoHijoRequest
|
||||
var req struct {
|
||||
ChildGroupID uint `json:"child_group_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -2,14 +2,16 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func QuitarGrupoAUsuario(c *gin.Context) {
|
||||
var req dto.GrupoUsuarioRelacion
|
||||
var req struct {
|
||||
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
@@ -2,7 +2,6 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
@@ -10,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func QuitarPermisoAGrupo(c *gin.Context) {
|
||||
var req dto.GrupoPermisoRequest
|
||||
var req struct {
|
||||
PermisoID uint `json:"permission_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -2,7 +2,6 @@ package grupo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/dto"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
@@ -10,7 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func QuitarSubGrupo(c *gin.Context) {
|
||||
var req dto.GrupoHijoRequest
|
||||
var req struct {
|
||||
ChildGroupID uint `json:"child_group_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
package repuestos
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"repuestera_back/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func CrearRepuesto(c *gin.Context){
|
||||
|
||||
|
||||
func CrearRepuesto(c *gin.Context){
|
||||
var repuesto models.Repuesto
|
||||
if err := c.ShouldBindJSON(&repuesto); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ObtenerRepositorios().Repuesto.Crear(&repuesto); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, repuesto)
|
||||
}
|
||||
@@ -1,9 +1,18 @@
|
||||
package repuestos
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerRepuestos(c *gin.Context){
|
||||
|
||||
repuestos, err := r.ObtenerRepositorios().Repuesto.ObtenerTodos()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, repuestos)
|
||||
}
|
||||
@@ -1,16 +1,5 @@
|
||||
package dto
|
||||
|
||||
type LoginRequest struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
type RegisterRequest struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Password string `json:"password" binding:"required,min=6"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
type TokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
@@ -29,13 +18,3 @@ type MeResponse struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type RefreshRequest struct {
|
||||
RefreshToken string `json:"refresh_token" binding:"required"`
|
||||
}
|
||||
|
||||
type CambiarContraseñaRequest struct {
|
||||
UserID uint `json:"user_id"`
|
||||
OldPassword string `json:"old_password"`
|
||||
NewPassword string `json:"new_password" binding:"required"`
|
||||
}
|
||||
+1
-17
@@ -1,12 +1,5 @@
|
||||
package dto
|
||||
|
||||
type GrupoPermisoRequest struct {
|
||||
PermisoID uint `json:"permission_id"`
|
||||
}
|
||||
|
||||
type GrupoHijoRequest struct {
|
||||
ChildGroupID uint `json:"child_group_id"`
|
||||
}
|
||||
type GrupoSimpleDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
@@ -23,15 +16,6 @@ type PermisosUsuarioResponse struct {
|
||||
}
|
||||
|
||||
type GruposYPermisosResponse struct {
|
||||
Email string `json:"email"`
|
||||
Email string `json:"email"`
|
||||
Groups []GrupoSimpleDTO `json:"groups"`
|
||||
}
|
||||
|
||||
type GrupoUsuarioRelacion struct {
|
||||
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
|
||||
type UsuarioIDRequest struct{
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
@@ -148,16 +148,24 @@ func (r *repositorioGrupo) AgregarSubGrupo(padreID, hijoID uint) error {
|
||||
}
|
||||
|
||||
func (r *repositorioGrupo) QuitarSubGrupo(padreID, hijoID uint) error {
|
||||
// var padre models_seguridad.Grupo
|
||||
// if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
var padre models_seguridad.Grupo
|
||||
if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var nuevos []models_seguridad.Grupo
|
||||
for _, g := range padre.Grupos {
|
||||
if g.ID != hijoID {
|
||||
nuevos = append(nuevos, g)
|
||||
}
|
||||
}
|
||||
padre.Grupos = nuevos
|
||||
return r.db.Save(&padre).Error
|
||||
|
||||
return r.db.Model(&padre).Association("Grupos").Delete(&models_seguridad.Grupo{ID: hijoID})
|
||||
|
||||
// var nuevos []models_seguridad.Grupo
|
||||
// for _, g := range padre.Grupos {
|
||||
// if g.ID != hijoID {
|
||||
// nuevos = append(nuevos, g)
|
||||
// }
|
||||
// }
|
||||
// padre.Grupos = nuevos
|
||||
// return r.db.Save(&padre).Error
|
||||
}
|
||||
Reference in new issue
Block a user