update letter outgoing final attachment
This commit is contained in:
@@ -40,6 +40,9 @@ type LetterOutgoingProcessor interface {
|
||||
AddAttachments(ctx context.Context, letterID uuid.UUID, attachments []entities.LetterOutgoingAttachment, userID uuid.UUID) error
|
||||
RemoveAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID, userID uuid.UUID) error
|
||||
|
||||
AddFinalAttachments(ctx context.Context, letterID uuid.UUID, attachments []entities.LetterOutgoingFinalAttachment, userID uuid.UUID) error
|
||||
RemoveFinalAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID, userID uuid.UUID) error
|
||||
|
||||
CreateDiscussion(ctx context.Context, discussion *entities.LetterOutgoingDiscussion, attachments []entities.LetterOutgoingDiscussionAttachment, userID uuid.UUID) error
|
||||
GetDiscussionByID(ctx context.Context, id uuid.UUID) (*entities.LetterOutgoingDiscussion, error)
|
||||
UpdateDiscussion(ctx context.Context, discussion *entities.LetterOutgoingDiscussion) error
|
||||
@@ -68,6 +71,7 @@ type LetterOutgoingProcessorImpl struct {
|
||||
db *gorm.DB
|
||||
letterRepo *repository.LetterOutgoingRepository
|
||||
attachmentRepo *repository.LetterOutgoingAttachmentRepository
|
||||
finalAttachmentRepo *repository.LetterOutgoingFinalAttachmentRepository
|
||||
recipientRepo *repository.LetterOutgoingRecipientRepository
|
||||
discussionRepo *repository.LetterOutgoingDiscussionRepository
|
||||
discussionAttachmentRepo *repository.LetterOutgoingDiscussionAttachmentRepository
|
||||
@@ -84,6 +88,7 @@ func NewLetterOutgoingProcessor(
|
||||
db *gorm.DB,
|
||||
letterRepo *repository.LetterOutgoingRepository,
|
||||
attachmentRepo *repository.LetterOutgoingAttachmentRepository,
|
||||
finalAttachmentRepo *repository.LetterOutgoingFinalAttachmentRepository,
|
||||
recipientRepo *repository.LetterOutgoingRecipientRepository,
|
||||
discussionRepo *repository.LetterOutgoingDiscussionRepository,
|
||||
discussionAttachmentRepo *repository.LetterOutgoingDiscussionAttachmentRepository,
|
||||
@@ -99,6 +104,7 @@ func NewLetterOutgoingProcessor(
|
||||
db: db,
|
||||
letterRepo: letterRepo,
|
||||
attachmentRepo: attachmentRepo,
|
||||
finalAttachmentRepo: finalAttachmentRepo,
|
||||
recipientRepo: recipientRepo,
|
||||
discussionRepo: discussionRepo,
|
||||
discussionAttachmentRepo: discussionAttachmentRepo,
|
||||
@@ -359,7 +365,7 @@ func (p *LetterOutgoingProcessorImpl) DeleteOutgoingLetter(ctx context.Context,
|
||||
if err := p.activityLogRepo.Create(txCtx, activityLog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1128,6 +1134,51 @@ func (p *LetterOutgoingProcessorImpl) RemoveAttachment(ctx context.Context, lett
|
||||
})
|
||||
}
|
||||
|
||||
func (p *LetterOutgoingProcessorImpl) AddFinalAttachments(ctx context.Context, letterID uuid.UUID, attachments []entities.LetterOutgoingFinalAttachment, userID uuid.UUID) error {
|
||||
return p.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
// Get the letter to get the current revision number
|
||||
_, err := p.letterRepo.Get(txCtx, letterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := p.finalAttachmentRepo.CreateBulk(txCtx, attachments); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
activityLog := &entities.LetterOutgoingActivityLog{
|
||||
LetterID: letterID,
|
||||
ActionType: entities.LetterOutgoingActionAttachmentAdded,
|
||||
ActorUserID: &userID,
|
||||
}
|
||||
if err := p.activityLogRepo.Create(txCtx, activityLog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (p *LetterOutgoingProcessorImpl) RemoveFinalAttachment(ctx context.Context, letterID uuid.UUID, attachmentID uuid.UUID, userID uuid.UUID) error {
|
||||
return p.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
if err := p.finalAttachmentRepo.Delete(txCtx, attachmentID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
activityLog := &entities.LetterOutgoingActivityLog{
|
||||
LetterID: letterID,
|
||||
ActionType: entities.LetterOutgoingActionAttachmentRemoved,
|
||||
ActorUserID: &userID,
|
||||
TargetID: &attachmentID,
|
||||
}
|
||||
if err := p.activityLogRepo.Create(txCtx, activityLog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (p *LetterOutgoingProcessorImpl) CreateDiscussion(ctx context.Context, discussion *entities.LetterOutgoingDiscussion, attachments []entities.LetterOutgoingDiscussionAttachment, userID uuid.UUID) error {
|
||||
return p.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
if err := p.discussionRepo.Create(txCtx, discussion); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user