package models import ( "kontor-api-gin/internal/helpers" "time" ) type Article 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"` Title string `gorm:"uniqueIndex" json:"title"` ArticleAuthors []ArticleAuthor `gorm:"foreignKey:ArticleID" json:"article_authors"` } func (article *Article) TableName() string { return "article" } type ArticleDTO 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"` Title string `json:"title"` } func ConvertArticlesToDtos(articles []Article) []ArticleDTO { dtos := make([]ArticleDTO, len(articles)) for i, article := range articles { dtos[i] = ArticleDTO{ ID: article.ID, CreatedAt: helpers.KontorTime{Time: article.CreatedAt}, UpdatedAt: helpers.KontorTime{Time: article.UpdatedAt}, DeletedAt: article.DeletedAt, Version: article.Version, Title: article.Title, } } return dtos } type CreateArticleDTO struct { Title string `json:"title" binding:"required"` } type UpdateArticleDTO struct { Title *string `json:"title,omitempty" binding:"omitempty"` }