fix archived
This commit is contained in:
parent
a10accdf8d
commit
6a67cd1267
@ -49,6 +49,7 @@ type LetterOutgoingProcessor interface {
|
|||||||
GetOutgoingLetterWithDetails(ctx context.Context, letterID uuid.UUID) (*entities.LetterOutgoing, error)
|
GetOutgoingLetterWithDetails(ctx context.Context, letterID uuid.UUID) (*entities.LetterOutgoing, error)
|
||||||
GetUsersByIDs(ctx context.Context, userIDs []uuid.UUID) ([]entities.User, error)
|
GetUsersByIDs(ctx context.Context, userIDs []uuid.UUID) ([]entities.User, error)
|
||||||
BulkArchiveOutgoingLetters(ctx context.Context, letterIDs []uuid.UUID) (int64, error)
|
BulkArchiveOutgoingLetters(ctx context.Context, letterIDs []uuid.UUID) (int64, error)
|
||||||
|
BulkArchiveIncomingLettersForUser(ctx context.Context, letterIDs []uuid.UUID, userId uuid.UUID) (int64, error)
|
||||||
|
|
||||||
// Batch loading methods for efficient querying
|
// Batch loading methods for efficient querying
|
||||||
GetBatchAttachments(ctx context.Context, letterIDs []uuid.UUID) (map[uuid.UUID][]entities.LetterOutgoingAttachment, error)
|
GetBatchAttachments(ctx context.Context, letterIDs []uuid.UUID) (map[uuid.UUID][]entities.LetterOutgoingAttachment, error)
|
||||||
@ -1087,6 +1088,10 @@ func (p *LetterOutgoingProcessorImpl) BulkArchiveOutgoingLetters(ctx context.Con
|
|||||||
return p.letterRepo.BulkArchive(ctx, letterIDs)
|
return p.letterRepo.BulkArchive(ctx, letterIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *LetterOutgoingProcessorImpl) BulkArchiveIncomingLettersForUser(ctx context.Context, letterIDs []uuid.UUID, userID uuid.UUID) (int64, error) {
|
||||||
|
return p.letterRepo.BulkArchiveForUser(ctx, letterIDs, userID)
|
||||||
|
}
|
||||||
|
|
||||||
// GetBatchAttachments fetches attachments for multiple letters in a single query
|
// GetBatchAttachments fetches attachments for multiple letters in a single query
|
||||||
func (p *LetterOutgoingProcessorImpl) GetBatchAttachments(ctx context.Context, letterIDs []uuid.UUID) (map[uuid.UUID][]entities.LetterOutgoingAttachment, error) {
|
func (p *LetterOutgoingProcessorImpl) GetBatchAttachments(ctx context.Context, letterIDs []uuid.UUID) (map[uuid.UUID][]entities.LetterOutgoingAttachment, error) {
|
||||||
if p.attachmentRepo == nil || len(letterIDs) == 0 {
|
if p.attachmentRepo == nil || len(letterIDs) == 0 {
|
||||||
|
|||||||
@ -77,6 +77,17 @@ func (r *LetterOutgoingRepository) Archive(ctx context.Context, letterID uuid.UU
|
|||||||
}).Error
|
}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *LetterOutgoingRepository) BulkArchiveForUser(ctx context.Context, letterIDs []uuid.UUID, userID uuid.UUID) (int64, error) {
|
||||||
|
db := DBFromContext(ctx, r.db)
|
||||||
|
// Archive only the recipient records for the specific user
|
||||||
|
// Note: letter_incoming_recipients uses recipient_user_id column
|
||||||
|
result := db.WithContext(ctx).
|
||||||
|
Model(&entities.LetterOutgoingRecipient{}).
|
||||||
|
Where("letter_id IN ? AND user_id = ?", letterIDs, userID).
|
||||||
|
Update("is_archived", true)
|
||||||
|
return result.RowsAffected, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
func (r *LetterOutgoingRepository) GetWithRelations(ctx context.Context, id uuid.UUID, relations []string) (*entities.LetterOutgoing, error) {
|
func (r *LetterOutgoingRepository) GetWithRelations(ctx context.Context, id uuid.UUID, relations []string) (*entities.LetterOutgoing, error) {
|
||||||
db := DBFromContext(ctx, r.db)
|
db := DBFromContext(ctx, r.db)
|
||||||
query := db.WithContext(ctx).Where("id = ? AND deleted_at IS NULL", id)
|
query := db.WithContext(ctx).Where("id = ? AND deleted_at IS NULL", id)
|
||||||
@ -120,7 +131,11 @@ func (r *LetterOutgoingRepository) List(ctx context.Context, filter ListOutgoing
|
|||||||
|
|
||||||
// Apply is_archived filter
|
// Apply is_archived filter
|
||||||
if filter.IsArchived != nil {
|
if filter.IsArchived != nil {
|
||||||
query = query.Where("letters_outgoing.is_archived = ?", *filter.IsArchived)
|
if *filter.IsArchived {
|
||||||
|
query = query.Where("letter_outgoing_recipients.is_archived = ?", true)
|
||||||
|
} else {
|
||||||
|
query = query.Where("letter_outgoing_recipients.is_archived = ? OR letter_outgoing_recipients.is_archived IS NULL", false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.Status != nil {
|
if filter.Status != nil {
|
||||||
|
|||||||
@ -136,9 +136,9 @@ func (r *LetterIncomingRepository) List(ctx context.Context, filter ListIncoming
|
|||||||
|
|
||||||
if filter.IsArchived != nil {
|
if filter.IsArchived != nil {
|
||||||
if *filter.IsArchived {
|
if *filter.IsArchived {
|
||||||
query = query.Where("letters_incoming.is_archived = ?", true)
|
query = query.Where("letter_incoming_recipients.is_archived = ?", true)
|
||||||
} else {
|
} else {
|
||||||
query = query.Where("letters_incoming.is_archived = ? OR letters_incoming.is_archived IS NULL", false)
|
query = query.Where("letter_incoming_recipients.is_archived = ? OR letter_incoming_recipients.is_archived IS NULL", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,9 +206,9 @@ func (r *LetterIncomingRepository) List(ctx context.Context, filter ListIncoming
|
|||||||
//}
|
//}
|
||||||
if filter.IsArchived != nil {
|
if filter.IsArchived != nil {
|
||||||
if *filter.IsArchived {
|
if *filter.IsArchived {
|
||||||
dataQuery = dataQuery.Where("letters_incoming.is_archived = ?", true)
|
dataQuery = dataQuery.Where("letter_incoming_recipients.is_archived = ?", true)
|
||||||
} else {
|
} else {
|
||||||
dataQuery = dataQuery.Where("letters_incoming.is_archived = ? OR letters_incoming.is_archived IS NULL", false)
|
dataQuery = dataQuery.Where("letter_incoming_recipients.is_archived = ? OR letter_incoming_recipients.is_archived IS NULL", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1831,7 +1831,9 @@ func ApplyLetterFilterOverrides(ctx context.Context, filter *repository.ListOutg
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *LetterOutgoingServiceImpl) BulkArchiveOutgoingLetters(ctx context.Context, letterIDs []uuid.UUID) (*contract.BulkArchiveLettersResponse, error) {
|
func (s *LetterOutgoingServiceImpl) BulkArchiveOutgoingLetters(ctx context.Context, letterIDs []uuid.UUID) (*contract.BulkArchiveLettersResponse, error) {
|
||||||
archivedCount, err := s.processor.BulkArchiveOutgoingLetters(ctx, letterIDs)
|
userID := appcontext.FromGinContext(ctx).UserID
|
||||||
|
|
||||||
|
archivedCount, err := s.processor.BulkArchiveIncomingLettersForUser(ctx, letterIDs, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -831,8 +831,10 @@ func (s *LetterServiceImpl) GetLetterCTA(ctx context.Context, letterID uuid.UUID
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *LetterServiceImpl) BulkArchiveIncomingLetters(ctx context.Context, letterIDs []uuid.UUID) (*contract.BulkArchiveLettersResponse, error) {
|
func (s *LetterServiceImpl) BulkArchiveIncomingLetters(ctx context.Context, letterIDs []uuid.UUID) (*contract.BulkArchiveLettersResponse, error) {
|
||||||
|
userID := appcontext.FromGinContext(ctx).UserID
|
||||||
|
|
||||||
// Archive the letters themselves
|
// Archive the letters themselves
|
||||||
archivedCount, err := s.processor.BulkArchiveIncomingLetters(ctx, letterIDs)
|
archivedCount, err := s.processor.BulkArchiveIncomingLettersForUser(ctx, letterIDs, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user