feat(postgres):lab4 load attachment ids in ListByChat

This commit is contained in:
Голиков Maximillian Антон
2026-10-20 08:22:38 +03:00
parent 57efb9ce0d
commit cace078c65
@@ -208,6 +208,25 @@ func (r *MessageRepo) ListByChat(ctx context.Context, chatID string, limit int,
c := encodeCursor(scope, last.CreatedAt, last.ID)
next = &c
}
if len(page) > 0 {
msgIDs := make([]string, len(page))
for i := range page {
msgIDs[i] = page[i].ID
}
links, err := r.loadAttachmentIDs(ctx, msgIDs)
if err != nil {
return nil, nil, err
}
for i := range page {
if ids, ok := links[page[i].ID]; ok {
page[i].AttachmentIDs = ids
} else {
page[i].AttachmentIDs = []string{}
}
}
}
return page, next, nil
}