Files
tiku-backend.net/Tiku.Api/Controllers/TenantsController.cs
xiong 4bea745b79 feat: Add tags and endpoint summaries to various controllers for better API documentation
- Added tags to BrowserAuthController for browser authentication endpoints.
- Added tags to CatalogController for public catalog access.
- Added tags to CommerceController for student transaction operations.
- Added tags to CommissionController for tenant commission management.
- Added tags to CrmController for tenant CRM functionalities.
- Added tags to HealthController for system health checks.
- Added tags to LearningController for student learning resources.
- Added tags to MeController for current user information.
- Added tags to PlatformAdminController for platform management.
- Introduced PlatformBackofficeController for backend permissions management.
- Added tags to PlatformBillingCallbackController for billing callbacks.
- Added tags to PlatformPaymentSettingsController for payment settings management.
- Added tags to PlatformSaasController for SaaS package management.
- Added tags to PlatformTenantCapabilitiesController for tenant capabilities.
- Added tags to PointsController for student points management.
- Added tags to ProfileController for student profile management.
- Added tags to QuestionVideosController for question video resources.
- Added tags to ReferralController for referral growth management.
- Added tags to RuntimeController for runtime configurations.
- Added tags to ScorelineController for scoreline management.
- Added tags to TaxonomyController for category management.
- Added tags to TenantAdminDirectController for tenant operations management.
- Introduced TenantBackofficeController for tenant backend permissions.
- Added tags to TenantBillingController for tenant billing operations.
- Added tags to TenantCommerceController for tenant commerce operations.
- Added tags to TenantContentController for tenant content management.
- Added tags to TenantContentDirectController for direct content management.
- Added tags to TenantFrontendConfigController for frontend configurations.
- Added tags to TenantOnboardingController for onboarding guidance.
- Added tags to TenantPublicController for public tenant configurations.
- Added tags to TenantsController for current tenant information.
- Added tags to VideosController for student video resources.
2026-07-29 16:16:27 +08:00

70 lines
2.3 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Tiku.Application.Auth;
using Tiku.Application.Security;
using Tiku.Domain.Tenancy;
using Tiku.Infrastructure.Persistence;
namespace Tiku.Api.Controllers;
[ApiController]
[Tags("租户端-当前租户")]
[Authorize(Policy = TikuPolicies.CurrentTenantMember)]
[Route("api/tenants")]
public sealed class TenantsController(
ICurrentUser currentUser,
ITenantContext currentTenant,
TikuDbContext dbContext) : ControllerBase
{
[HttpGet("current")]
[EndpointSummary("查询当前租户")]
[EndpointDescription("返回当前请求租户及当前用户在该租户内的成员角色。")]
public async Task<ActionResult<CurrentTenantResponse>> GetCurrent(CancellationToken cancellationToken)
{
if (currentUser.UserId is null || currentTenant.TenantId is null)
{
throw new TenantAccessDeniedException();
}
var result = await dbContext.TenantMemberships
.Where(membership =>
membership.UserId == currentUser.UserId.Value &&
membership.TenantId == currentTenant.TenantId.Value &&
membership.Status == MembershipStatus.Active)
.Join(
dbContext.Tenants,
membership => membership.TenantId,
tenant => tenant.Id,
(membership, tenant) => new CurrentTenantResponse(
tenant.Id,
tenant.Name,
tenant.Slug,
tenant.Status,
membership.Role))
.SingleOrDefaultAsync(cancellationToken);
if (result is null)
{
throw new TenantAccessDeniedException();
}
return Ok(result);
}
}
/// <summary>
/// 当前请求租户和当前用户在该租户内的权限摘要。
/// </summary>
/// <param name="TenantId">租户 ID。</param>
/// <param name="TenantName">租户名称。</param>
/// <param name="TenantSlug">租户编码。</param>
/// <param name="Status">租户状态。</param>
/// <param name="Role">当前用户在租户内的角色。</param>
public sealed record CurrentTenantResponse(
Guid TenantId,
string TenantName,
string TenantSlug,
TenantStatus Status,
TenantRole Role);