Files
kontor/kontor-gin/internal/models/volume.go
T
Thomas Peetz 0750621b96
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 19m24s
add methods in Repository and Model for importing data
2026-10-29 17:40:54 +01:00

63 lines
1.9 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 (dto VolumeDTO) ConvertDTOToModel() Volume {
model := Volume{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Name: dto.Name,
ComicID: dto.ComicID,
}
return model
}
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
}
type VolumeDTOList []VolumeDTO