Hub-Api/commands/license_handler.go

66 lines
1.3 KiB
Go
Raw Normal View History

2024-05-27 23:06:25 +03:30
package commands
import (
m "netina/models"
c "netina/models/commands"
2024-05-27 23:06:25 +03:30
l "netina/repositories/license"
"netina/validation"
2024-05-27 23:06:25 +03:30
"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{
2024-05-27 23:06:25 +03:30
Plan_id: command.Plan_id,
Created_at: time.Now(),
Modified_by: modified_by,
NumberOfRenewals: 0,
ExpireDate: command.ExpireDate,
2024-05-27 23:06:25 +03:30
}
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{
2024-05-27 23:06:25 +03:30
Plan_id: command.Plan_id,
Modified_by: modified_by,
2024-06-07 15:14:01 +03:30
Modified_at: time.Now(),
ExpireDate: command.ExpireDate,
NumberOfRenewals: command.NumberOfRenewals,
2024-05-27 23:06:25 +03:30
}
return r.Repository.UpdateLicense(id , license)
}
type RemoveLicenseHandler struct {
Repository l.LicenseCommandRepository
}
func ( r *RemoveLicenseHandler) Handle (id uint) error {
return r.Repository.RemoveLicense(id)
}