Files
kontor/kontor-gin/internal/models/book_author.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

51 lines
1.8 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type BookAuthor 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"`
BookID *string `gorm:"column:book_id" json:"book_id"`
Book *Book `gorm:"foreignKey:BookID" json:"book"`
AuthorID *string `form:"column:author_id" json:"author_id"`
Author *Author `gorm:"foreignKey:AuthorID" json:"author"`
}
func (book_author *BookAuthor) TableName() string {
return "book_author"
}
type BookAuthorDTO 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"`
Version int `json:"version"`
BookID *string `json:"book_id"`
AuthorID *string `json:"author_id"`
}
func ConvertBookAuthorsToDtos(book_authors []BookAuthor) []BookAuthorDTO {
dtos := make([]BookAuthorDTO, len(book_authors))
for i, book_author := range book_authors {
dtos[i] = BookAuthorDTO{
ID: book_author.ID,
CreatedAt: helpers.KontorTime{Time: book_author.CreatedAt},
UpdatedAt: helpers.KontorTime{Time: book_author.UpdatedAt},
DeletedAt: book_author.DeletedAt,
Version: book_author.Version,
BookID: book_author.BookID,
AuthorID: book_author.AuthorID,
}
}
return dtos
}
type BookAuthorDTOList []BookAuthorDTO