58 lines
2.0 KiB
Go
58 lines
2.0 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 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
|