role commands
parent
d4722e4d17
commit
dd6c3666af
|
@ -0,0 +1,60 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
m "netina/models"
|
||||||
|
c "netina/models/commands"
|
||||||
|
p "netina/repositories/role"
|
||||||
|
"netina/validation"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateRoleHandler struct {
|
||||||
|
Repository p.RoleCommandRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func (r *CreateRoleHandler) Handle(command c.CreateRoleCommand) error {
|
||||||
|
|
||||||
|
if err := validation.ValidateStruct(command); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
role := &m.Role{
|
||||||
|
Name: command.Name,
|
||||||
|
Created_at: time.Now(),
|
||||||
|
Modified_by: command.Modified_by ,
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Repository.CreateRole(role)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type UpdateRoleHandler struct {
|
||||||
|
Repository p.RoleCommandRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (r *UpdateRoleHandler) Handle (id uint , command c.UpdateRoleCommand)(*m.Role , error) {
|
||||||
|
if err := validation.ValidateStruct(command); err != nil {
|
||||||
|
return nil , err
|
||||||
|
}
|
||||||
|
|
||||||
|
role := &m.Role{
|
||||||
|
Name: command.Name,
|
||||||
|
Modified_by: command.Modified_by,
|
||||||
|
Modified_at: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Repository.UpdateRole(id , role)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type RemoveRoleHandler struct {
|
||||||
|
Repository p.RoleCommandRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (r *RemoveRoleHandler) Handle (id uint )error {
|
||||||
|
return r.Repository.RemoveRole(id)
|
||||||
|
}
|
Loading…
Reference in New Issue