This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Author 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"`
|
||||
FirstName string `gorm:"column:first_name" json:"first_name"`
|
||||
LastName string `gorm:"column:last_name" json:"last_name"`
|
||||
ArticleAuthors []ArticleAuthor `gorm:"foreignKey:AuthorID" json:"article_authors"`
|
||||
BookAuthors []BookAuthor `gorm:"foreignKey:AuthorID" json:"book_authors"`
|
||||
}
|
||||
|
||||
func (author *Author) TableName() string {
|
||||
return "author"
|
||||
}
|
||||
|
||||
type AuthorDTO 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"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
}
|
||||
|
||||
func ConvertAuthorsToDtos(authors []Author) []AuthorDTO {
|
||||
dtos := make([]AuthorDTO, len(authors))
|
||||
for i, author := range authors {
|
||||
dtos[i] = AuthorDTO{
|
||||
ID: author.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: author.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: author.UpdatedAt},
|
||||
DeletedAt: author.DeletedAt,
|
||||
Version: author.Version,
|
||||
FirstName: author.FirstName,
|
||||
LastName: author.LastName,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
Reference in New Issue
Block a user