add archive
This commit is contained in:
@@ -54,13 +54,29 @@ func (r *LetterOutgoingRepository) SoftDelete(ctx context.Context, id uuid.UUID)
|
||||
|
||||
func (r *LetterOutgoingRepository) BulkArchive(ctx context.Context, letterIDs []uuid.UUID) (int64, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
now := time.Now()
|
||||
result := db.WithContext(ctx).
|
||||
Model(&entities.LetterOutgoing{}).
|
||||
Where("id IN ? AND deleted_at IS NULL", letterIDs).
|
||||
Update("status", "archived")
|
||||
Updates(map[string]interface{}{
|
||||
"is_archived": true,
|
||||
"archived_at": now,
|
||||
})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) Archive(ctx context.Context, letterID uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
now := time.Now()
|
||||
return db.WithContext(ctx).
|
||||
Model(&entities.LetterOutgoing{}).
|
||||
Where("id = ? AND deleted_at IS NULL", letterID).
|
||||
Updates(map[string]interface{}{
|
||||
"is_archived": true,
|
||||
"archived_at": now,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingRepository) GetWithRelations(ctx context.Context, id uuid.UUID, relations []string) (*entities.LetterOutgoing, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
query := db.WithContext(ctx).Where("id = ? AND deleted_at IS NULL", id)
|
||||
@@ -103,11 +119,7 @@ func (r *LetterOutgoingRepository) List(ctx context.Context, filter ListOutgoing
|
||||
|
||||
// Apply is_archived filter
|
||||
if filter.IsArchived != nil {
|
||||
if *filter.IsArchived {
|
||||
query = query.Where("letters_outgoing.status = 'archived'")
|
||||
} else {
|
||||
query = query.Where("letters_outgoing.status != 'archived'")
|
||||
}
|
||||
query = query.Where("letters_outgoing.is_archived = ?", *filter.IsArchived)
|
||||
}
|
||||
|
||||
if filter.Status != nil {
|
||||
|
||||
@@ -45,15 +45,29 @@ func (r *LetterIncomingRepository) SoftDelete(ctx context.Context, id uuid.UUID)
|
||||
|
||||
func (r *LetterIncomingRepository) BulkArchive(ctx context.Context, letterIDs []uuid.UUID) (int64, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
// For incoming letters, we archive the recipients, not the letter itself
|
||||
// The letter status remains as is (new, in_progress, or completed)
|
||||
now := time.Now()
|
||||
result := db.WithContext(ctx).
|
||||
Model(&entities.LetterIncomingRecipient{}).
|
||||
Where("letter_id IN ?", letterIDs).
|
||||
Update("is_archived", true)
|
||||
Model(&entities.LetterIncoming{}).
|
||||
Where("id IN ? AND deleted_at IS NULL", letterIDs).
|
||||
Updates(map[string]interface{}{
|
||||
"is_archived": true,
|
||||
"archived_at": now,
|
||||
})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
func (r *LetterIncomingRepository) Archive(ctx context.Context, letterID uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
now := time.Now()
|
||||
return db.WithContext(ctx).
|
||||
Model(&entities.LetterIncoming{}).
|
||||
Where("id = ? AND deleted_at IS NULL", letterID).
|
||||
Updates(map[string]interface{}{
|
||||
"is_archived": true,
|
||||
"archived_at": now,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// BulkArchiveForUser archives letters for a specific user only
|
||||
func (r *LetterIncomingRepository) BulkArchiveForUser(ctx context.Context, letterIDs []uuid.UUID, userID uuid.UUID) (int64, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
@@ -122,9 +136,9 @@ func (r *LetterIncomingRepository) List(ctx context.Context, filter ListIncoming
|
||||
|
||||
if filter.IsArchived != nil {
|
||||
if *filter.IsArchived {
|
||||
query = query.Where("letter_incoming_recipients.is_archived = ?", true)
|
||||
query = query.Where("letters_incoming.is_archived = ?", true)
|
||||
} else {
|
||||
query = query.Where("letter_incoming_recipients.is_archived = ? OR letter_incoming_recipients.is_archived IS NULL", false)
|
||||
query = query.Where("letters_incoming.is_archived = ? OR letters_incoming.is_archived IS NULL", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user