Files
kontor/kontor-gin/internal/models/assignment.go
T
Thomas Peetz 4aaf580735
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
WIP: Export Kontor DB
2026-10-01 17:40:17 +02:00

49 lines
1.8 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 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
}