update letter outgoing final attachment
This commit is contained in:
@@ -534,6 +534,60 @@ func (r *LetterOutgoingAttachmentRepository) ListByLetterIDs(ctx context.Context
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type LetterOutgoingFinalAttachmentRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingFinalAttachmentRepository(db *gorm.DB) *LetterOutgoingFinalAttachmentRepository {
|
||||
return &LetterOutgoingFinalAttachmentRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingFinalAttachmentRepository) Create(ctx context.Context, e *entities.LetterOutgoingFinalAttachment) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Create(e).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingFinalAttachmentRepository) CreateBulk(ctx context.Context, list []entities.LetterOutgoingFinalAttachment) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.WithContext(ctx).Create(&list).Error
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingFinalAttachmentRepository) ListByLetter(ctx context.Context, letterID uuid.UUID) ([]entities.LetterOutgoingFinalAttachment, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingFinalAttachment
|
||||
if err := db.WithContext(ctx).Where("letter_id = ?", letterID).Order("uploaded_at ASC").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingFinalAttachmentRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
return db.WithContext(ctx).Where("id = ?", id).Delete(&entities.LetterOutgoingAttachment{}).Error
|
||||
}
|
||||
|
||||
// ListByLetterIDs fetches attachments for multiple letters in a single query
|
||||
func (r *LetterOutgoingFinalAttachmentRepository) ListByLetterIDs(ctx context.Context, letterIDs []uuid.UUID) (map[uuid.UUID][]entities.LetterOutgoingFinalAttachment, error) {
|
||||
if len(letterIDs) == 0 {
|
||||
return make(map[uuid.UUID][]entities.LetterOutgoingFinalAttachment), nil
|
||||
}
|
||||
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var attachments []entities.LetterOutgoingFinalAttachment
|
||||
if err := db.WithContext(ctx).Where("letter_id IN ?", letterIDs).Order("uploaded_at ASC").Find(&attachments).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Group attachments by letter ID
|
||||
result := make(map[uuid.UUID][]entities.LetterOutgoingFinalAttachment)
|
||||
for _, att := range attachments {
|
||||
result[att.LetterID] = append(result[att.LetterID], att)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type LetterOutgoingRecipientRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewLetterOutgoingRecipientRepository(db *gorm.DB) *LetterOutgoingRecipientRepository {
|
||||
|
||||
Reference in New Issue
Block a user