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 (dto ArticleAuthorDTO) ConvertDTOToModel() ArticleAuthor { model := ArticleAuthor{ ID: dto.ID, CreatedAt: dto.CreatedAt.Time, UpdatedAt: dto.UpdatedAt.Time, DeletedAt: dto.DeletedAt, Version: dto.Version, ArticleID: dto.ArticleID, AuthorID: dto.AuthorID, } return model } 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 } type ArticleAuthorDTOList []ArticleAuthorDTO