mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
feat: basic organization endpoint
This commit is contained in:
@@ -41,10 +41,10 @@ namespace WebApp.Endpoints
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||
// przed jego wysłaniem!
|
||||
Eve.ToEventDetailsDto();
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId) Eve.EventRegistrations = [];
|
||||
EventDetailsDto EveDto = Eve.ToEventDetailsDto();
|
||||
|
||||
return Results.Ok(Eve); //EventDetailsDto
|
||||
return Results.Ok(EveDto); //EventDetailsDto
|
||||
})
|
||||
.WithName(GetEventEndpointName);
|
||||
|
||||
|
||||
42
WebApp/Endpoints/OrganizationsEndpoints.cs
Normal file
42
WebApp/Endpoints/OrganizationsEndpoints.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.Data;
|
||||
using WebApp.Entities;
|
||||
using WebApp.Mapping;
|
||||
|
||||
|
||||
namespace WebApp.Endpoints;
|
||||
|
||||
public static class OrganizationsEndpoints
|
||||
{
|
||||
const string GetOrganizationEndpointName = "GetOrganization";
|
||||
|
||||
public static RouteGroupBuilder MapOrganizationsEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("api/organizations")
|
||||
.WithParameterValidation();
|
||||
|
||||
// GET /organizations
|
||||
group.MapGet("/",
|
||||
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
|
||||
await dbContext.Organisations
|
||||
//.Include(Eve => Eve.Organisation)
|
||||
.OrderByDescending(Org => Org.OrganisationId)
|
||||
.Select(Org => Org.ToOrgSummaryDto()) //OrgSummaryDto
|
||||
.AsNoTracking()
|
||||
.ToListAsync());
|
||||
|
||||
// GET /organizations/1
|
||||
group.MapGet("/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Organisation? Org = await dbContext.Organisations.FindAsync(id);
|
||||
|
||||
if (Org is null) return Results.NotFound();
|
||||
|
||||
return Results.Ok(Org.ToOrgSummaryDto()); //OrgSummaryDto
|
||||
})
|
||||
.WithName(GetOrganizationEndpointName);
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user