package models import ( "kontor-api-gin/internal/helpers" "time" ) type Comic 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"` Title string `gorm:"uniqueIndex" json:"title"` CurrentOrder bool `gorm:"column:current_order" json:"current_order"` Completed bool `gorm:"column:completed" json:"completed"` WebLink string `gorm:"column:weblink" json:"weblink"` PublisherID *string `gorm:"column:publisher_id" json:"publisher_id"` Publisher *Publisher `gorm:"foreignKey:PublisherID"` Issues []Issue `gorm:"foreignKey:ComicID"` StoryArcs []StoryArc `gorm:"foreignKey:ComicID"` TradePaperbacks []TradePaperback `gorm:"foreignKey:ComicID"` Volumes []Volume `gorm:"foreignKey:ComicID"` ComicWorks []ComicWork `gorm:"foreignKey:ComicID"` } func (comic *Comic) TableName() string { return "comic" } type ComicDTO 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"` Title string `json:"title"` PublisherID *string `json:"publisher_id"` CurrentOrder bool `json:"current_order"` Completed bool `json:"completed"` WebLink string `json:"weblink"` } func (dto ComicDTO) ConvertDTOToModel() Comic { model := Comic{ ID: dto.ID, CreatedAt: dto.CreatedAt.Time, UpdatedAt: dto.UpdatedAt.Time, DeletedAt: dto.DeletedAt, Version: dto.Version, Title: dto.Title, PublisherID: dto.PublisherID, CurrentOrder: dto.CurrentOrder, Completed: dto.Completed, WebLink: dto.WebLink, } return model } func ConvertComicsToDtos(comics []Comic) []ComicDTO { dtos := make([]ComicDTO, len(comics)) for i, comic := range comics { dtos[i] = ComicDTO{ ID: comic.ID, CreatedAt: helpers.KontorTime{Time: comic.CreatedAt}, UpdatedAt: helpers.KontorTime{Time: comic.UpdatedAt}, DeletedAt: comic.DeletedAt, Version: comic.Version, Title: comic.Title, CurrentOrder: comic.CurrentOrder, Completed: comic.Completed, WebLink: comic.WebLink, PublisherID: comic.PublisherID, } } return dtos } type ComicDTOList []ComicDTO type CreateComicDTO struct { Title string `json:"title" binding:"required"` } type UpdateComicDTO struct { Title *string `json:"title,omitempty" binding:"omitempty"` WebLink *string `json:"weblink,omitempty" binding:"omitempty"` Completed *bool `json:"cimpleted,omitempty" binding:"omitempty"` CurrentOrder *bool `json:"current_order,omitempty" binding:"omitempty"` }