Files
kontor/kontor-gin/internal/models/mail.go
T
Thomas Peetz 8706b3880f
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 13m11s
add methods in Repository an dModel for importing data
2026-10-30 00:19:25 +01:00

74 lines
2.3 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type Mail 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"`
Folder string `gorm:"column:folder" json:"folder"`
Subject string `gorm:"column:subject" json:"subject"`
Body string `gorm:"column:body" json:"body"`
SendAt time.Time `gorm:"column:sent_date" json:"sent_date"`
ReceivedAt time.Time `gorm:"column:received_date" json:"received_date"`
}
func (mail *Mail) TableName() string {
return "mail"
}
type MailDTO 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"`
Folder string `json:"folder"`
Subject string `json:"subject"`
Body string `json:"body"`
SendAt time.Time `json:"sent_date"`
ReceivedAt time.Time `json:"received_date"`
}
func (dto MailDTO) ConvertDTOToModel() Mail {
model := Mail{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Folder: dto.Folder,
Subject: dto.Subject,
Body: dto.Body,
SendAt: dto.SendAt,
ReceivedAt: dto.ReceivedAt,
}
return model
}
func ConvertMailsToDtos(mails []Mail) []MailDTO {
dtos := make([]MailDTO, len(mails))
for i, mail := range mails {
dtos[i] = MailDTO{
ID: mail.ID,
CreatedAt: helpers.KontorTime{Time: mail.CreatedAt},
UpdatedAt: helpers.KontorTime{Time: mail.UpdatedAt},
DeletedAt: mail.DeletedAt,
Version: mail.Version,
Folder: mail.Folder,
Subject: mail.Subject,
Body: mail.Body,
SendAt: mail.SendAt,
ReceivedAt: mail.ReceivedAt,
}
}
return dtos
}
type MailDTOList []MailDTO