Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
filipbekic01 committed Sep 23, 2024
1 parent 13d6488 commit 0e63f0e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend/ResQueue/ResQueue/Dtos/ArchiveMessagesDto.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace ResQueue.Dtos;

public record ArchiveMessagesDto(string[] Ids);
public record ArchiveMessagesDto(string QueueId, string[] Ids);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public record ArchiveMessagesFeatureResponse();

public class ArchiveMessagesFeature(
UserManager<User> userManager,
IMongoCollection<Message> messagesCollection
IMongoCollection<Message> messagesCollection,
IMongoCollection<Queue> queuesCollection,
IMongoClient mongoClient
) : IArchiveMessagesFeature
{
public async Task<OperationResult<ArchiveMessagesFeatureResponse>> ExecuteAsync(
Expand All @@ -35,12 +37,21 @@ public async Task<OperationResult<ArchiveMessagesFeatureResponse>> ExecuteAsync(

var filter = Builders<Message>.Filter.And(
Builders<Message>.Filter.In(m => m.Id, request.Dto.Ids.Select(ObjectId.Parse)),
Builders<Message>.Filter.Eq(m => m.QueueId, ObjectId.Parse(request.Dto.QueueId)),
Builders<Message>.Filter.Eq(m => m.UserId, user.Id)
);

var update = Builders<Message>.Update.Set(m => m.DeletedAt, dt);

await messagesCollection.UpdateManyAsync(filter, update);
using var session = await mongoClient.StartSessionAsync();
session.StartTransaction();

var result = await messagesCollection.UpdateManyAsync(filter, update);

await queuesCollection.UpdateOneAsync(session, x => x.Id == ObjectId.Parse(request.Dto.QueueId),
Builders<Queue>.Update.Inc(x => x.TotalMessages, -result.ModifiedCount));

await session.CommitTransactionAsync();

return OperationResult<ArchiveMessagesFeatureResponse>.Success(new ArchiveMessagesFeatureResponse());
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/api/messages/archiveMessagesMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export function useArchiveMessagesMutation() {
const queryClient = useQueryClient()

return useMutation({
mutationFn: (ids: string[]) =>
mutationFn: (data: { ids: string[]; queueId: string }) =>
axios.delete(`${API_URL}/messages`, {
data: {
ids
},
data,
withCredentials: true
}),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['messages'] })
queryClient.invalidateQueries({ queryKey: ['message'] })
queryClient.invalidateQueries({ queryKey: ['queues'] })
queryClient.invalidateQueries({ queryKey: ['queue'] })
}
})
}
5 changes: 4 additions & 1 deletion frontend/src/features/message/MessageActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ const archiveMessages = () => {
severity: 'danger'
},
accept: () => {
archiveMessagesAsync(props.selectedMessageIds).then(() => {
archiveMessagesAsync({
ids: props.selectedMessageIds,
queueId: props.rabbitMqQueue.id
}).then(() => {
emit('archive:message')
toast.add({
Expand Down

0 comments on commit 0e63f0e

Please sign in to comment.