71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
|
|
package transformer
|
||
|
|
|
||
|
|
import (
|
||
|
|
"eslogad-be/internal/contract"
|
||
|
|
"eslogad-be/internal/entities"
|
||
|
|
)
|
||
|
|
|
||
|
|
func LetterEntityToContract(e *entities.LetterIncoming, attachments []entities.LetterIncomingAttachment) *contract.IncomingLetterResponse {
|
||
|
|
resp := &contract.IncomingLetterResponse{
|
||
|
|
ID: e.ID,
|
||
|
|
LetterNumber: e.LetterNumber,
|
||
|
|
ReferenceNumber: e.ReferenceNumber,
|
||
|
|
Subject: e.Subject,
|
||
|
|
Description: e.Description,
|
||
|
|
PriorityID: e.PriorityID,
|
||
|
|
SenderInstitutionID: e.SenderInstitutionID,
|
||
|
|
ReceivedDate: e.ReceivedDate,
|
||
|
|
DueDate: e.DueDate,
|
||
|
|
Status: string(e.Status),
|
||
|
|
CreatedBy: e.CreatedBy,
|
||
|
|
CreatedAt: e.CreatedAt,
|
||
|
|
UpdatedAt: e.UpdatedAt,
|
||
|
|
Attachments: make([]contract.IncomingLetterAttachmentResponse, 0, len(attachments)),
|
||
|
|
}
|
||
|
|
for _, a := range attachments {
|
||
|
|
resp.Attachments = append(resp.Attachments, contract.IncomingLetterAttachmentResponse{
|
||
|
|
ID: a.ID,
|
||
|
|
FileURL: a.FileURL,
|
||
|
|
FileName: a.FileName,
|
||
|
|
FileType: a.FileType,
|
||
|
|
UploadedAt: a.UploadedAt,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return resp
|
||
|
|
}
|
||
|
|
|
||
|
|
func DispositionsToContract(list []entities.LetterDisposition) []contract.DispositionResponse {
|
||
|
|
out := make([]contract.DispositionResponse, 0, len(list))
|
||
|
|
for _, d := range list {
|
||
|
|
out = append(out, contract.DispositionResponse{
|
||
|
|
ID: d.ID,
|
||
|
|
LetterID: d.LetterID,
|
||
|
|
FromDepartmentID: d.FromDepartmentID,
|
||
|
|
ToDepartmentID: d.ToDepartmentID,
|
||
|
|
Notes: d.Notes,
|
||
|
|
Status: string(d.Status),
|
||
|
|
CreatedBy: d.CreatedBy,
|
||
|
|
CreatedAt: d.CreatedAt,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return out
|
||
|
|
}
|
||
|
|
|
||
|
|
func DiscussionEntityToContract(e *entities.LetterDiscussion) *contract.LetterDiscussionResponse {
|
||
|
|
var mentions map[string]interface{}
|
||
|
|
if e.Mentions != nil {
|
||
|
|
mentions = map[string]interface{}(e.Mentions)
|
||
|
|
}
|
||
|
|
return &contract.LetterDiscussionResponse{
|
||
|
|
ID: e.ID,
|
||
|
|
LetterID: e.LetterID,
|
||
|
|
ParentID: e.ParentID,
|
||
|
|
UserID: e.UserID,
|
||
|
|
Message: e.Message,
|
||
|
|
Mentions: mentions,
|
||
|
|
CreatedAt: e.CreatedAt,
|
||
|
|
UpdatedAt: e.UpdatedAt,
|
||
|
|
EditedAt: e.EditedAt,
|
||
|
|
}
|
||
|
|
}
|