Skip to content

Commit

Permalink
Fix exchange getters
Browse files Browse the repository at this point in the history
  • Loading branch information
filipbekic01 committed Sep 30, 2024
1 parent 0d62347 commit 8599edd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions backend/ResQueue/ResQueue/DataProtectionKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace ResQueue;
public class DataProtectionKey
{
public ObjectId Id { get; set; }
public string FriendlyName { get; set; }
public string XmlData { get; set; }
public string FriendlyName { get; set; } = null!;
public string XmlData { get; set; } = null!;
}
21 changes: 15 additions & 6 deletions backend/ResQueue/ResQueue/Endpoints/ExchangeEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,35 @@ public static void MapExchangeEndpoints(this IEndpointRouteBuilder routes)
.RequireAuthorization();

group.MapGet("{brokerId}",
async (IMongoCollection<Exchange> collection, UserManager<User> userManager, HttpContext httpContext,
async (IMongoCollection<Exchange> exchangesCollection,
IMongoCollection<Broker> brokersCollection,
UserManager<User> userManager,
HttpContext httpContext,
string brokerId) =>
{
// Get user
var user = await userManager.GetUserAsync(httpContext.User);
if (user == null)
{
return Results.Unauthorized();
}

if (!ObjectId.TryParse(brokerId, out var brokerObjectId))
// Validate broker
var brokerFilter = Builders<Broker>.Filter.And(
Builders<Broker>.Filter.Eq(b => b.Id, ObjectId.Parse(brokerId)),
Builders<Broker>.Filter.ElemMatch(b => b.AccessList, a => a.UserId == user.Id),
Builders<Broker>.Filter.Eq(b => b.DeletedAt, null)
);
if (!await brokersCollection.Find(brokerFilter).AnyAsync())
{
return Results.BadRequest("Invalid Broker ID format.");
return Results.Unauthorized();
}

var filter = Builders<Exchange>.Filter.And(
Builders<Exchange>.Filter.Eq(q => q.UserId, user.Id),
Builders<Exchange>.Filter.Eq(q => q.BrokerId, brokerObjectId)
Builders<Exchange>.Filter.Eq(q => q.BrokerId, ObjectId.Parse(brokerId))
);

var exchanges = await collection.Find(filter).ToListAsync();
var exchanges = await exchangesCollection.Find(filter).ToListAsync();

return Results.Ok(exchanges.Select(q => new ExchangeDto()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public async Task<OperationResult<SyncBrokerFeatureResponse>> ExecuteAsync(SyncB
{
exchangesToAdd.Add(new Exchange
{
UserId = user.Id,
BrokerId = ObjectId.Parse(request.Id),
RawData = BsonDocument.Parse(element.GetRawText())
});
Expand Down
1 change: 0 additions & 1 deletion backend/ResQueue/ResQueue/Models/Exchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace ResQueue.Models;
public class Exchange
{
[BsonId] public ObjectId Id { get; set; }
public ObjectId UserId { get; set; }
public ObjectId BrokerId { get; set; }
public BsonDocument RawData { get; set; } = null!;
}

0 comments on commit 8599edd

Please sign in to comment.