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

49 lines
1.8 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type ArticleAuthor 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"`
ArticleID *string `gorm:"column:article_id" json:"article_id"`
Article *Article `gorm:"foreignKey:ArticleID" json:"article"`
AuthorID *string `form:"column:author_id" json:"author_id"`
Author *Author `gorm:"foreignKey:AuthorID" json:"author"`
}
func (article_author *ArticleAuthor) TableName() string {
return "article_author"
}
type ArticleAuthorDTO 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"`
ArticleID *string `json:"article_id"`
AuthorID *string `json:"author_id"`
}
func ConvertArticleAuthorsToDtos(article_authors []ArticleAuthor) []ArticleAuthorDTO {
dtos := make([]ArticleAuthorDTO, len(article_authors))
for i, article_author := range article_authors {
dtos[i] = ArticleAuthorDTO{
ID: article_author.ID,
CreatedAt: helpers.KontorTime{Time: article_author.CreatedAt},
UpdatedAt: helpers.KontorTime{Time: article_author.UpdatedAt},
DeletedAt: article_author.DeletedAt,
Version: article_author.Version,
ArticleID: article_author.ArticleID,
AuthorID: article_author.AuthorID,
}
}
return dtos
}