add final attachment response

This commit is contained in:
efrilm 2025-12-06 11:20:33 +07:00
parent e83eefc614
commit 5e9af152a7
3 changed files with 18 additions and 0 deletions

View File

@ -114,6 +114,7 @@ type OutgoingLetterResponse struct {
IsRead bool `json:"is_read"`
Recipients []OutgoingLetterRecipientResponse `json:"recipients,omitempty"`
Attachments []OutgoingLetterAttachmentResponse `json:"attachments,omitempty"`
FinalAttachments []OutgoingLetterAttachmentResponse `json:"final_attachments,omitempty"`
Approvals []OutgoingLetterApprovalResponse `json:"approvals,omitempty"`
}

View File

@ -32,6 +32,7 @@ func (r *LetterOutgoingRepository) Get(ctx context.Context, id uuid.UUID) (*enti
Preload("ApprovalFlow").
Preload("Recipients").
Preload("Attachments").
Preload("FinalAttachments").
Preload("Approvals.Step").
Preload("Approvals.Approver").
Where("id = ? AND deleted_at IS NULL", id).
@ -51,6 +52,7 @@ func (r *LetterOutgoingRepository) GetByReferenceNumber(ctx context.Context, ref
Preload("ApprovalFlow").
Preload("Recipients").
Preload("Attachments").
Preload("FinalAttachments").
Preload("Approvals.Step").
Preload("Approvals.Approver").
Where("reference_number = ? AND deleted_at IS NULL", refNumber).
@ -259,6 +261,7 @@ func (r *LetterOutgoingRepository) List(ctx context.Context, filter ListOutgoing
Preload("Recipients.User").
Preload("Recipients.Department").
Preload("Attachments").
Preload("FinalAttachments").
Preload("Approvals.Step").
Preload("Approvals.Approver").
Order(orderBy).
@ -359,6 +362,7 @@ func (r *LetterOutgoingRepository) ListAll(ctx context.Context, filter ListOutgo
Preload("Recipients.User").
Preload("Recipients.Department").
Preload("Attachments").
Preload("FinalAttachments").
Preload("Approvals").
Preload("Approvals.Step").
Preload("Approvals.Approver").

View File

@ -1635,6 +1635,19 @@ func transformLetterToResponse(letter *entities.LetterOutgoing) *contract.Outgoi
}
}
if len(letter.FinalAttachments) > 0 {
resp.FinalAttachments = make([]contract.OutgoingLetterAttachmentResponse, len(letter.FinalAttachments))
for i, attachment := range letter.FinalAttachments {
resp.FinalAttachments[i] = contract.OutgoingLetterAttachmentResponse{
ID: attachment.ID,
FileURL: attachment.FileURL,
FileName: attachment.FileName,
FileType: attachment.FileType,
UploadedAt: attachment.UploadedAt,
}
}
}
if len(letter.Approvals) > 0 {
resp.Approvals = make([]contract.OutgoingLetterApprovalResponse, len(letter.Approvals))
for i, approval := range letter.Approvals {