64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type Assignment struct {
|
|
ID string `gorm:"type:string;primary_key;" json:"id"`
|
|
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
|
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
|
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
|
Version int `gorm:"default:0" json:"version"`
|
|
ProfileID *string `gorm:"column:profile_id" json:"profile_id"`
|
|
Profile *Profile `gorm:"foreignKey:ProfileID" json:"profile"`
|
|
PermissionID *string `gorm:"column:permission_id" json:"permission_id"`
|
|
Permission *Profile `gorm:"foreignKey:PermissionID" json:"permission"`
|
|
}
|
|
|
|
func (assignment *Assignment) TableName() string {
|
|
return "assignment"
|
|
}
|
|
|
|
type AssignmentDTO struct {
|
|
ID string `json:"id" binding:"required"`
|
|
CreatedAt helpers.KontorTime `json:"created_date"`
|
|
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
|
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
|
Version int `json:"version"`
|
|
ProfileID *string `json:"profile_id"`
|
|
PermissionID *string `json:"permission_id"`
|
|
}
|
|
|
|
func (dto *AssignmentDTO) ConvertDTOToModel() Assignment {
|
|
model := Assignment{
|
|
ID: dto.ID,
|
|
CreatedAt: dto.CreatedAt.Time,
|
|
UpdatedAt: dto.UpdatedAt.Time,
|
|
DeletedAt: dto.DeletedAt,
|
|
Version: dto.Version,
|
|
ProfileID: dto.ProfileID,
|
|
PermissionID: dto.PermissionID,
|
|
}
|
|
return model
|
|
}
|
|
|
|
func ConvertAssignmentsToDtos(assignments []Assignment) []AssignmentDTO {
|
|
dtos := make([]AssignmentDTO, len(assignments))
|
|
for i, assignment := range assignments {
|
|
dtos[i] = AssignmentDTO{
|
|
ID: assignment.ID,
|
|
CreatedAt: helpers.KontorTime{Time: assignment.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: assignment.UpdatedAt},
|
|
DeletedAt: assignment.DeletedAt,
|
|
Version: assignment.Version,
|
|
ProfileID: assignment.ProfileID,
|
|
PermissionID: assignment.PermissionID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type AssignmentDTOList []AssignmentDTO
|