This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user