65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package commands
|
|
|
|
import (
|
|
m "netina/models"
|
|
c "netina/models/commands"
|
|
o "netina/repositories/owner"
|
|
"netina/validation"
|
|
"time"
|
|
)
|
|
|
|
|
|
type CreateOwnerHandler struct{
|
|
Repository o.OwnerCommandRepository
|
|
}
|
|
|
|
func (r *CreateOwnerHandler) Handle(command c.CreateOwnerCommand) error {
|
|
if err := validation.ValidateStruct(command); err != nil {
|
|
return err
|
|
}
|
|
owner := &m.Owner{
|
|
PhoneNumber: command.PhoneNumber,
|
|
FirstName: command.FirstName,
|
|
LastName: command.LastName,
|
|
NationalCode: command.NationalCode,
|
|
Created_at: time.Now(),
|
|
Modified_by: command.Modified_by,
|
|
}
|
|
|
|
return r.Repository.CreateOwner(owner)
|
|
}
|
|
|
|
|
|
type UpdateOwnerHandler struct {
|
|
Repository o.OwnerCommandRepository
|
|
}
|
|
|
|
|
|
func (r *UpdateOwnerHandler) Handle(id uint , command c.UpdateOwnerCommand)(*m.Owner , error) {
|
|
|
|
if err := validation.ValidateStruct(command); err != nil {
|
|
return nil , err
|
|
}
|
|
|
|
owner := &m.Owner{
|
|
PhoneNumber: command.PhoneNumber,
|
|
FirstName: command.FirstName,
|
|
LastName: command.LastName,
|
|
NationalCode: command.NationalCode,
|
|
Modified_by: command.Modified_by,
|
|
}
|
|
|
|
return r.Repository.UpdateOwner(id , owner)
|
|
}
|
|
|
|
|
|
type RemoveOwnerCommand struct {
|
|
Repository o.OwnerCommandRepository
|
|
}
|
|
|
|
func (r *RemoveOwnerCommand) Handle(id uint) error {
|
|
return r.Repository.RemoveOwner(id)
|
|
}
|
|
|
|
|