48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type Volume 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"`
|
|
Name string `gorm:"uniqueIndex" json:"name"`
|
|
ComicID *string `gorm:"column:comic_id" json:"comic_id"`
|
|
Comic *Comic `gorm:"foreignKey:ComicID" json:"comic"`
|
|
}
|
|
|
|
func (volume *Volume) TableName() string {
|
|
return "volume"
|
|
}
|
|
|
|
type VolumeDTO 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"`
|
|
Name string `json:"name"`
|
|
ComicID *string `json:"comic_id"`
|
|
}
|
|
|
|
func ConvertVolumesToDtos(volumes []Volume) []VolumeDTO {
|
|
dtos := make([]VolumeDTO, len(volumes))
|
|
for i, volume := range volumes {
|
|
dtos[i] = VolumeDTO{
|
|
ID: volume.ID,
|
|
CreatedAt: helpers.KontorTime{Time: volume.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: volume.UpdatedAt},
|
|
DeletedAt: volume.DeletedAt,
|
|
Version: volume.Version,
|
|
Name: volume.Name,
|
|
ComicID: volume.ComicID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|