68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type StoryArc 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"`
|
|
VolumeID *string `gorm:"column:volume_id" json:"volume_id"`
|
|
Volume *Volume `gorm:"foreignKey:VolumeID" json:"volume"`
|
|
}
|
|
|
|
func (story_arc *StoryArc) TableName() string {
|
|
return "story_arc"
|
|
}
|
|
|
|
type StoryArcDTO 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"`
|
|
VolumeID *string `json:"volume_id"`
|
|
}
|
|
|
|
func (dto StoryArcDTO) ConvertDTOToModel() StoryArc {
|
|
model := StoryArc{
|
|
ID: dto.ID,
|
|
CreatedAt: dto.CreatedAt.Time,
|
|
UpdatedAt: dto.UpdatedAt.Time,
|
|
DeletedAt: dto.DeletedAt,
|
|
Version: dto.Version,
|
|
Name: dto.Name,
|
|
ComicID: dto.ComicID,
|
|
VolumeID: dto.VolumeID,
|
|
}
|
|
return model
|
|
}
|
|
|
|
func ConvertStoryArcsToDtos(storyarcs []StoryArc) []StoryArcDTO {
|
|
dtos := make([]StoryArcDTO, len(storyarcs))
|
|
for i, storyarc := range storyarcs {
|
|
dtos[i] = StoryArcDTO{
|
|
ID: storyarc.ID,
|
|
CreatedAt: helpers.KontorTime{Time: storyarc.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: storyarc.UpdatedAt},
|
|
DeletedAt: storyarc.DeletedAt,
|
|
Version: storyarc.Version,
|
|
Name: storyarc.Name,
|
|
ComicID: storyarc.ComicID,
|
|
VolumeID: storyarc.VolumeID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type StoryArcDTOList []StoryArcDTO
|