69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type IssueWork 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"`
|
|
ArtistID *string `gorm:"column:artist_id" json:"artist_id"`
|
|
Artist *Artist `gorm:"foreignKey:ArtistID" json:"artist"`
|
|
IssueID *string `gorm:"column:issue_id" json:"issue_id"`
|
|
Issue *Issue `gorm:"foreignKey:IssueID" json:"issue"`
|
|
WorkTypeID *string `gorm:"column:work_type_id" json:"work_type_id"`
|
|
WorkType *WorkType `gorm:"foreignKey:WorkTypeID" json:"work_type"`
|
|
}
|
|
|
|
func (issue_work *IssueWork) TableName() string {
|
|
return "issue_work"
|
|
}
|
|
|
|
type IssueworkDTO 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"`
|
|
IssueID *string `json:"issue_id"`
|
|
ArtistID *string `json:"artist_id"`
|
|
WorkTypeID *string `json:"work_type_id"`
|
|
}
|
|
|
|
func (dto IssueworkDTO) ConvertDTOToModel() IssueWork {
|
|
model := IssueWork{
|
|
ID: dto.ID,
|
|
CreatedAt: dto.CreatedAt.Time,
|
|
UpdatedAt: dto.UpdatedAt.Time,
|
|
DeletedAt: dto.DeletedAt,
|
|
Version: dto.Version,
|
|
IssueID: dto.IssueID,
|
|
ArtistID: dto.ArtistID,
|
|
WorkTypeID: dto.WorkTypeID,
|
|
}
|
|
return model
|
|
}
|
|
|
|
func ConvertIssueworksToDtos(issueworks []IssueWork) []IssueworkDTO {
|
|
dtos := make([]IssueworkDTO, len(issueworks))
|
|
for i, issuework := range issueworks {
|
|
dtos[i] = IssueworkDTO{
|
|
ID: issuework.ID,
|
|
CreatedAt: helpers.KontorTime{Time: issuework.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: issuework.UpdatedAt},
|
|
DeletedAt: issuework.DeletedAt,
|
|
Version: issuework.Version,
|
|
ArtistID: issuework.ArtistID,
|
|
IssueID: issuework.IssueID,
|
|
WorkTypeID: issuework.WorkTypeID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type IssueworkDTOList []IssueworkDTO
|