add models for MailAccount and Mail
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MailAccount 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"`
|
||||
Host string `gorm:"column:host" json:"host"`
|
||||
Port int `gorm:"column:port" json:"port"`
|
||||
Protocol string `gorm:"column:protocol" json:"protocol"`
|
||||
UserName string `gorm:"column:user_name" json:"user_name"`
|
||||
Password string `gorm:"column:password" json:"password"`
|
||||
StartTLS bool `gorm:"column:start_tls" json:"start_tls"`
|
||||
}
|
||||
|
||||
func (mail_account *MailAccount) TableName() string {
|
||||
return "mail_account"
|
||||
}
|
||||
|
||||
type MailAccountDTO 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"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Protocol string `json:"protocol"`
|
||||
UserName string `json:"user_name"`
|
||||
Password string `json:"password"`
|
||||
StartTLS bool `json:"start_tls"`
|
||||
}
|
||||
|
||||
func ConvertMailAccountsToDtos(mailaccounts []MailAccount) []MailAccountDTO {
|
||||
dtos := make([]MailAccountDTO, len(mailaccounts))
|
||||
for i, mailaccount := range mailaccounts {
|
||||
dtos[i] = MailAccountDTO{
|
||||
ID: mailaccount.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: mailaccount.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: mailaccount.UpdatedAt},
|
||||
DeletedAt: mailaccount.DeletedAt,
|
||||
Version: mailaccount.Version,
|
||||
Host: mailaccount.Host,
|
||||
Port: mailaccount.Port,
|
||||
Protocol: mailaccount.Protocol,
|
||||
UserName: mailaccount.UserName,
|
||||
Password: mailaccount.Password,
|
||||
StartTLS: mailaccount.StartTLS,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
Reference in New Issue
Block a user