mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
fix: rev db model, added missing entities and helper functions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
@@ -8,7 +9,7 @@ namespace WebApp.Endpoints
|
||||
{
|
||||
public static class EventsEndpoints
|
||||
{
|
||||
const string GetEventEndpointName = "GetEvent";
|
||||
const string GetEventEndpointName = "GetEvent";
|
||||
|
||||
public static RouteGroupBuilder MapEventsEndpoints(this WebApplication app)
|
||||
{
|
||||
@@ -16,7 +17,8 @@ namespace WebApp.Endpoints
|
||||
.WithParameterValidation();
|
||||
|
||||
// GET /events
|
||||
group.MapGet("/", async (ApplicationDbContext dbContext) =>
|
||||
group.MapGet("/",
|
||||
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
|
||||
await dbContext.Events
|
||||
.Include(Eve => Eve.Organisation)
|
||||
.OrderByDescending(Eve => Eve.EventId)
|
||||
@@ -25,7 +27,8 @@ namespace WebApp.Endpoints
|
||||
.ToListAsync());
|
||||
|
||||
// GET /events/1
|
||||
group.MapGet("/{id}", async (int id, ApplicationDbContext dbContext) =>
|
||||
group.MapGet("/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
|
||||
@@ -44,11 +47,14 @@ namespace WebApp.Endpoints
|
||||
.WithName(GetEventEndpointName);
|
||||
|
||||
// POST /events
|
||||
group.MapPost("/", async (EventCreateDto newEvent, ApplicationDbContext dbContext) =>
|
||||
group.MapPost("/",
|
||||
async (EventCreateDto newEvent, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
// ...
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.StatusCode(403);
|
||||
|
||||
Event Eve = newEvent.ToEntity();
|
||||
|
||||
@@ -66,18 +72,21 @@ namespace WebApp.Endpoints
|
||||
});
|
||||
|
||||
// PUT /events/1
|
||||
group.MapPut("/{id}", async (int id, EventUpdateDto updatedEvent, ApplicationDbContext dbContext) =>
|
||||
group.MapPut("/{id}",
|
||||
async (int id, EventUpdateDto updatedEvent, ApplicationDbContext dbContext, GeneralUseHelpers guhf, HttpContext httpContext) =>
|
||||
{
|
||||
var existingEvent = await dbContext.Events.FindAsync(id);
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.StatusCode(403);
|
||||
|
||||
var existingEvent = await dbContext.Events.FindAsync(id);
|
||||
if (existingEvent is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
// ...
|
||||
|
||||
// Sprawdź, czy organizacja ma prawo
|
||||
// do zmodyfikowania tego (EventId = id) eventu.
|
||||
// ...
|
||||
@@ -101,11 +110,14 @@ namespace WebApp.Endpoints
|
||||
});
|
||||
|
||||
// DELETE /events/1
|
||||
group.MapDelete("/{id}", async (int id, ApplicationDbContext dbContext) =>
|
||||
group.MapDelete("/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, GeneralUseHelpers guhf, HttpContext httpContext) =>
|
||||
{
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
// ...
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.StatusCode(403);
|
||||
|
||||
// Sprawdź, czy organizacja ma prawo
|
||||
// do usunięcia tego (EventId = id) eventu.
|
||||
|
||||
Reference in New Issue
Block a user