Files
kontor/kontor-gin/internal/models/bookshelf_publisher.go
T
tpeetz d9007ba0e4
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
add missing models
2026-10-04 01:56:25 +02:00

45 lines
1.5 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type BookshelfPublisher struct {
ID string `gorm:"type:string;primary_key;"`
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"`
Books []Book `gorm:"foreignKey:PublisherID"`
}
func (publisher *BookshelfPublisher) TableName() string {
return "bookshelf_publisher"
}
type BookshelfPublisherDTO 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"`
}
func ConvertBookshelfPublishersToDtos(publishers []BookshelfPublisher) []BookshelfPublisherDTO {
dtos := make([]BookshelfPublisherDTO, len(publishers))
for i, publisher := range publishers {
dtos[i] = BookshelfPublisherDTO{
ID: publisher.ID,
CreatedAt: helpers.KontorTime{Time: publisher.CreatedAt},
UpdatedAt: helpers.KontorTime{Time: publisher.UpdatedAt},
DeletedAt: publisher.DeletedAt,
Version: publisher.Version,
Name: publisher.Name,
}
}
return dtos
}