70 lines
2.7 KiB
Go
70 lines
2.7 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type Issue 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"`
|
|
InStock bool `gorm:"column:in_stock" json:"in_stock"`
|
|
IsRead bool `gorm:"column:is_read" json:"is_read"`
|
|
IssueNumber string `gorm:"column:issue_number" json:"issue_number"`
|
|
Title string `gorm:"column:title" json:"title"`
|
|
PublishedOn time.Time `gorm:"column:published_on" json:"published_on"`
|
|
ComicID *string `gorm:"column:comic_id" json:"comic_id"`
|
|
Comic *Comic `gorm:"foreignKey:ComicID" json:"comic"`
|
|
StoryArcID *string `gorm:"column:story_arc_id" json:"story_arc_id"`
|
|
StoryArc *StoryArc `gorm:"foreignKey:StoryArcID" json:"story_arc"`
|
|
VolumeID *string `gorm:"column:volume_id" json:"volume_id"`
|
|
Volume *Volume `gorm:"foreignKey:VolumeID" json:"volume"`
|
|
}
|
|
|
|
func (issue *Issue) TableName() string {
|
|
return "issue"
|
|
}
|
|
|
|
type IssueDTO 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"`
|
|
IssueNumber string `json:"issue_number"`
|
|
Title string `json:"title"`
|
|
PublishedOn helpers.DateOnly `json:"published_on"`
|
|
InStock bool `json:"in_stock"`
|
|
IsRead bool `json:"is_read"`
|
|
ComicID *string `json:"comic_id"`
|
|
VolumeID *string `json:"volume_id"`
|
|
StoryArcID *string `json:"story_arc_id"`
|
|
}
|
|
|
|
func ConvertIssuesToDtos(issues []Issue) []IssueDTO {
|
|
dtos := make([]IssueDTO, len(issues))
|
|
for i, issue := range issues {
|
|
dtos[i] = IssueDTO{
|
|
ID: issue.ID,
|
|
CreatedAt: helpers.KontorTime{Time: issue.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: issue.UpdatedAt},
|
|
DeletedAt: issue.DeletedAt,
|
|
Version: issue.Version,
|
|
IssueNumber: issue.IssueNumber,
|
|
Title: issue.Title,
|
|
PublishedOn: helpers.DateOnly{Time: issue.PublishedOn},
|
|
InStock: issue.InStock,
|
|
IsRead: issue.IsRead,
|
|
ComicID: issue.ComicID,
|
|
VolumeID: issue.VolumeID,
|
|
StoryArcID: issue.StoryArcID,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type IssueDTOList []IssueDTO
|