Files
kontor/kontor-gin/internal/models/mailaccount.go
T
Thomas Peetz b0cc5f0cd1
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / build-and-test (push) Failing after 14m37s
add methods in Repository and Model for importing data
2026-10-30 09:15:19 +01:00

78 lines
2.6 KiB
Go

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 (dto MailAccountDTO) ConvertDTOToModel() MailAccount {
model := MailAccount{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Host: dto.Host,
Port: dto.Port,
Protocol: dto.Protocol,
UserName: dto.UserName,
Password: dto.Password,
StartTLS: dto.StartTLS,
}
return model
}
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
}
type MailAccountDTOList []MailAccountDTO