55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type ComicWork 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"`
|
|
ComicID *string `gorm:"column:comic_id" json:"comic_id"`
|
|
Comic *Comic `gorm:"foreignKey:ComicID" json:"comic"`
|
|
WorkTypeID *string `gorm:"column:work_type_id" json:"work_type_id"`
|
|
WorkType *WorkType `gorm:"foreignKey:WorkTypeID" json:"work_type"`
|
|
}
|
|
|
|
func (comic_work *ComicWork) TableName() string {
|
|
return "comic_work"
|
|
}
|
|
|
|
type ComicworkDTO 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"`
|
|
ComicID *string `json:"comic_id"`
|
|
ArtistID *string `json:"artist_id"`
|
|
WorkTypeID *string `json:"work_type_id"`
|
|
}
|
|
|
|
func ConvertComicworksToDtos(comicworks []ComicWork) []ComicworkDTO {
|
|
dtos := make([]ComicworkDTO, len(comicworks))
|
|
for i, comicwork := range comicworks {
|
|
dtos[i] = ComicworkDTO{
|
|
ID: comicwork.ID,
|
|
CreatedAt: helpers.KontorTime{Time: comicwork.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: comicwork.UpdatedAt},
|
|
DeletedAt: comicwork.DeletedAt,
|
|
Version: comicwork.Version,
|
|
ArtistID: comicwork.ArtistID,
|
|
ComicID: comicwork.ComicID,
|
|
WorkTypeID: comicwork.WorkTypeID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type ComicworkDTOList []ComicworkDTO
|