Hub-Api/commands/license_handler.go

66 lines
1.3 KiB
Go

package commands
import (
m "netina/models"
c "netina/models/commands"
l "netina/repositories/license"
"netina/validation"
"time"
)
type CreateLicenseHandler struct {
Repository l.LicenseCommandRepository
}
func(r *CreateLicenseHandler) Handle (command c.CreateLicenseCommand , modified_by string) error {
if err := validation.ValidateStruct(command); err != nil {
return err
}
license := &m.License{
Plan_id: command.Plan_id,
Created_at: time.Now(),
Modified_by: modified_by,
NumberOfRenewals: 0,
ExpireDate: command.ExpireDate,
}
return r.Repository.CreateLicense(license)
}
type UpdateLicenseHandler struct {
Repository l.LicenseCommandRepository
}
func (r *UpdateLicenseHandler) Handle (id uint , command c.UpdateLicenseCommand , modified_by string) (*m.License , error) {
if err := validation.ValidateStruct(command); err != nil {
return nil , err
}
license := &m.License{
Plan_id: command.Plan_id,
Modified_by: modified_by,
Modified_at: time.Now(),
ExpireDate: command.ExpireDate,
NumberOfRenewals: command.NumberOfRenewals,
}
return r.Repository.UpdateLicense(id , license)
}
type RemoveLicenseHandler struct {
Repository l.LicenseCommandRepository
}
func ( r *RemoveLicenseHandler) Handle (id uint) error {
return r.Repository.RemoveLicense(id)
}