feat(clubs): add Club and Member API endpoints with auto-sync
Implement Task 16: Club + Member API endpoints with MemberSyncService
Services:
- ClubService: GetMyClubsAsync (user's clubs), GetCurrentClubAsync (tenant club)
- MemberService: GetMembersAsync (list), GetMemberByIdAsync, GetCurrentMemberAsync
- MemberSyncService: Auto-creates Member records from JWT on first request
Middleware:
- MemberSyncMiddleware: Runs after auth, calls MemberSyncService
Endpoints:
- GET /api/clubs/me (list user's clubs)
- GET /api/clubs/current (current tenant's club)
- GET /api/members (list members, RLS filtered)
- GET /api/members/{id} (member detail)
- GET /api/members/me (current user's membership)
Tests: 14 integration tests (6 club + 8 member)
- Club filtering by user membership
- Multi-tenant isolation via RLS
- Member auto-sync on first request
- Cross-tenant access blocked
- Role-based authorization
Build: 0 errors, all tests compile
Pattern: TypedResults, RequireAuthorization policies, TDD approach
This commit is contained in:
26
backend/WorkClub.Api/Middleware/MemberSyncMiddleware.cs
Normal file
26
backend/WorkClub.Api/Middleware/MemberSyncMiddleware.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using WorkClub.Api.Services;
|
||||
|
||||
namespace WorkClub.Api.Middleware;
|
||||
|
||||
public class MemberSyncMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
public MemberSyncMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context, MemberSyncService memberSyncService)
|
||||
{
|
||||
try
|
||||
{
|
||||
await memberSyncService.EnsureMemberExistsAsync(context);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
await _next(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user