kontor-echo: setup project to show homepage
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Mail struct {
|
||||
bun.BaseModel `bun:"table:mail"`
|
||||
|
||||
ID string `bun:"id,pk"`
|
||||
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
||||
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Folder string `bun:"folder"`
|
||||
Subject string `bun:"subject"`
|
||||
Body string `bun:"body"`
|
||||
SendAt time.Time `bun:"sent_date"`
|
||||
ReceivedAt time.Time `bun:"received_date"`
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user