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 (dto AuthorDTO) ConvertDTOToModel() Author { model := Author{ ID: dto.ID, CreatedAt: dto.CreatedAt.Time, UpdatedAt: dto.UpdatedAt.Time, DeletedAt: dto.DeletedAt, Version: dto.Version, FirstName: dto.FirstName, LastName: dto.LastName, } return model } 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 } type AuthorDTOList []AuthorDTO