update letter outgoing final attachment
This commit is contained in:
@@ -21,10 +21,11 @@ type FileServiceImpl struct {
|
||||
userProcessor UserProcessor
|
||||
profileBucket string
|
||||
docBucket string
|
||||
finalBucket string
|
||||
}
|
||||
|
||||
func NewFileService(storage FileStorage, userProcessor UserProcessor, profileBucket, docBucket string) *FileServiceImpl {
|
||||
return &FileServiceImpl{storage: storage, userProcessor: userProcessor, profileBucket: profileBucket, docBucket: docBucket}
|
||||
func NewFileService(storage FileStorage, userProcessor UserProcessor, profileBucket, docBucket string, finalBucket string) *FileServiceImpl {
|
||||
return &FileServiceImpl{storage: storage, userProcessor: userProcessor, profileBucket: profileBucket, docBucket: docBucket, finalBucket: finalBucket}
|
||||
}
|
||||
|
||||
func (s *FileServiceImpl) UploadProfileAvatar(ctx context.Context, userID uuid.UUID, filename string, content []byte, contentType string) (string, error) {
|
||||
@@ -61,6 +62,22 @@ func (s *FileServiceImpl) UploadDocument(ctx context.Context, userID uuid.UUID,
|
||||
return url, key, nil
|
||||
}
|
||||
|
||||
func (s *FileServiceImpl) UploadDocumentFinal(ctx context.Context, userID uuid.UUID, filename string, content []byte, contentType string) (string, string, error) {
|
||||
if err := s.storage.EnsureBucket(ctx, s.docBucket); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(filename), "."))
|
||||
if mimeExt := mimeExtFromContentType(contentType); mimeExt != "" {
|
||||
ext = mimeExt
|
||||
}
|
||||
key := buildObjectKey("finals", userID, ext)
|
||||
url, err := s.storage.Upload(ctx, s.docBucket, key, content, contentType)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return url, key, nil
|
||||
}
|
||||
|
||||
func buildObjectKey(prefix string, userID uuid.UUID, ext string) string {
|
||||
now := time.Now().UTC()
|
||||
parts := []string{
|
||||
|
||||
@@ -39,6 +39,9 @@ type LetterOutgoingService interface {
|
||||
AddAttachments(ctx context.Context, letterID uuid.UUID, req *contract.AddAttachmentsRequest) error
|
||||
RemoveAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID) error
|
||||
|
||||
AddFinalAttachments(ctx context.Context, letterID uuid.UUID, req *contract.AddAttachmentsRequest) error
|
||||
RemoveFinalAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID) error
|
||||
|
||||
CreateDiscussion(ctx context.Context, letterID uuid.UUID, req *contract.CreateDiscussionRequest) (*contract.DiscussionResponse, error)
|
||||
UpdateDiscussion(ctx context.Context, discussionID uuid.UUID, req *contract.UpdateDiscussionRequest) error
|
||||
DeleteDiscussion(ctx context.Context, discussionID uuid.UUID) error
|
||||
@@ -915,7 +918,6 @@ func (s *LetterOutgoingServiceImpl) AddAttachments(ctx context.Context, letterID
|
||||
FileURL: a.FileURL,
|
||||
FileName: a.FileName,
|
||||
FileType: a.FileType,
|
||||
IsFinal: a.IsFinal,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,6 +939,46 @@ func (s *LetterOutgoingServiceImpl) RemoveAttachment(ctx context.Context, letter
|
||||
return s.processor.RemoveAttachment(ctx, letterID, attachmentID, userID)
|
||||
}
|
||||
|
||||
func (s *LetterOutgoingServiceImpl) AddFinalAttachments(ctx context.Context, letterID uuid.UUID, req *contract.AddAttachmentsRequest) error {
|
||||
userID := getUserIDFromContext(ctx)
|
||||
|
||||
_, err := s.processor.GetOutgoingLetterByID(ctx, letterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//if letter.Status != entities.LetterOutgoingStatusDraft {
|
||||
// return gorm.ErrInvalidData
|
||||
//}
|
||||
|
||||
attachments := make([]entities.LetterOutgoingFinalAttachment, len(req.Attachments))
|
||||
for i, a := range req.Attachments {
|
||||
attachments[i] = entities.LetterOutgoingFinalAttachment{
|
||||
LetterID: letterID,
|
||||
FileURL: a.FileURL,
|
||||
FileName: a.FileName,
|
||||
FileType: a.FileType,
|
||||
}
|
||||
}
|
||||
|
||||
return s.processor.AddFinalAttachments(ctx, letterID, attachments, userID)
|
||||
}
|
||||
|
||||
func (s *LetterOutgoingServiceImpl) RemoveFinalAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID) error {
|
||||
userID := getUserIDFromContext(ctx)
|
||||
|
||||
letter, err := s.processor.GetOutgoingLetterByID(ctx, letterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if letter.Status != entities.LetterOutgoingStatusDraft {
|
||||
return gorm.ErrInvalidData
|
||||
}
|
||||
|
||||
return s.processor.RemoveFinalAttachment(ctx, letterID, attachmentID, userID)
|
||||
}
|
||||
|
||||
func (s *LetterOutgoingServiceImpl) CreateDiscussion(ctx context.Context, letterID uuid.UUID, req *contract.CreateDiscussionRequest) (*contract.DiscussionResponse, error) {
|
||||
userID := getUserIDFromContext(ctx)
|
||||
|
||||
@@ -1589,7 +1631,6 @@ func transformLetterToResponse(letter *entities.LetterOutgoing) *contract.Outgoi
|
||||
FileName: attachment.FileName,
|
||||
FileType: attachment.FileType,
|
||||
UploadedAt: attachment.UploadedAt,
|
||||
IsFinal: attachment.IsFinal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user