2026-03-03 19:41:01 +01:00
|
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
|
|
|
using WorkClub.Api.Services;
|
|
|
|
|
using WorkClub.Application.Clubs.DTOs;
|
|
|
|
|
|
|
|
|
|
namespace WorkClub.Api.Endpoints.Clubs;
|
|
|
|
|
|
|
|
|
|
public static class ClubEndpoints
|
|
|
|
|
{
|
|
|
|
|
public static void MapClubEndpoints(this IEndpointRouteBuilder app)
|
|
|
|
|
{
|
|
|
|
|
var group = app.MapGroup("/api/clubs");
|
|
|
|
|
|
|
|
|
|
group.MapGet("/me", GetMyClubs)
|
2026-03-05 21:32:34 +01:00
|
|
|
.RequireAuthorization("RequireViewer")
|
2026-03-03 19:41:01 +01:00
|
|
|
.WithName("GetMyClubs");
|
|
|
|
|
|
|
|
|
|
group.MapGet("/current", GetCurrentClub)
|
|
|
|
|
.RequireAuthorization("RequireMember")
|
|
|
|
|
.WithName("GetCurrentClub");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task<Ok<List<ClubListDto>>> GetMyClubs(ClubService clubService)
|
|
|
|
|
{
|
|
|
|
|
var result = await clubService.GetMyClubsAsync();
|
|
|
|
|
return TypedResults.Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task<Results<Ok<ClubDetailDto>, NotFound>> GetCurrentClub(ClubService clubService)
|
|
|
|
|
{
|
|
|
|
|
var result = await clubService.GetCurrentClubAsync();
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
|
return TypedResults.NotFound();
|
|
|
|
|
|
|
|
|
|
return TypedResults.Ok(result);
|
|
|
|
|
}
|
|
|
|
|
}
|