mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Add remove endpoint
This commit is contained in:
@@ -104,6 +104,31 @@ namespace WebApp.Endpoints
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/events/remove/{id}/{userId}
|
||||||
|
group.MapPost("/remove/{id}/{userId}",
|
||||||
|
async (int id, int userId, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||||
|
{
|
||||||
|
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||||
|
if (Eve is null)
|
||||||
|
return Results.Json(new { success = false, error_msg = "Event not found." });
|
||||||
|
|
||||||
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
|
if (org is null || org.OrganisationId != Eve.OrganisationId)
|
||||||
|
return Results.Json(new { success = false, error_msg = "Unauthorized." });
|
||||||
|
|
||||||
|
EventRegistration? registration = await dbContext.EventRegistrations
|
||||||
|
.FirstOrDefaultAsync(er => er.UserId == userId && er.EventId == id);
|
||||||
|
|
||||||
|
if (registration is null)
|
||||||
|
return Results.Json(new { success = false, error_msg = "Registration not found." });
|
||||||
|
|
||||||
|
dbContext.EventRegistrations.Remove(registration);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Results.Json(new { success = true });
|
||||||
|
});
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user