feat: implementado un patron de repository

This commit is contained in:
fede committed 2026-06-10 17:50:57 -03:00
1 parent 03df1c5264
commit 785bc7db6b
18 files changed
+505 -160

No files matched your search

@@ -0,0 +1,6 @@
package models_seguridad
type IPermisosComponent interface {
Buscar(id uint) bool
ListarPermisos() []Permiso
}
+25
View File
@@ -21,3 +21,28 @@ type Grupo struct {
func (Grupo) TableName() string {
return "groups"
}
func (g *Grupo) Buscar(id uint) bool {
for _, permiso := range g.Permisos {
if permiso.Buscar(id) {
return true
}
}
for _, subGrupo := range g.Grupos {
if subGrupo.Buscar(id) {
return true
}
}
return false
}
func (g *Grupo) ListarPermisos() []Permiso {
var result []Permiso
for _, permiso := range g.Permisos {
result = append(result, permiso)
}
for _, subGrupo := range g.Grupos {
result = append(result, subGrupo.ListarPermisos()...)
}
return result
}
+8
View File
@@ -19,3 +19,11 @@ type Permiso struct {
func (Permiso) TableName() string {
return "permissions"
}
func (p *Permiso) Buscar(id uint) bool {
return p.ID == id
}
func (p *Permiso) ListarPermisos() []Permiso {
return []Permiso{*p}
}