Files
tiku-backend.net/Tiku.Api/Controllers/CrmController.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

88 lines
3.3 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Contracts;
using Tiku.Application.Growth;
using Tiku.Application.Security;
namespace Tiku.Api.Controllers;
[ApiController]
[Tags("租户端-CRM")]
[Authorize(Policy = BackendPermissions.TenantCrmManage)]
[Tiku.Api.Security.RequireSaasFeature(SaasFeatureCatalog.Crm)]
[Produces("application/json")]
[Route("api/crm")]
public sealed class CrmController(
ICrmService crmService,
ICurrentUser currentUser,
ITenantContext currentTenant) : ControllerBase
{
[HttpGet("config")]
[EndpointSummary("查询 CRM 推送配置")]
[ProducesResponseType<CrmConfigItem>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmConfigItem>> Config(CancellationToken cancellationToken)
{
return Ok(await crmService.GetConfigAsync(ResolveActor(), cancellationToken));
}
[HttpPut("config")]
[EndpointSummary("保存 CRM 推送配置")]
[ProducesResponseType<CrmConfigItem>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmConfigItem>> UpsertConfig(
UpsertCrmConfigDto request,
CancellationToken cancellationToken)
{
return Ok(await crmService.UpsertConfigAsync(ResolveActor(), request.ToCommand(), cancellationToken));
}
[HttpGet("queue")]
[EndpointSummary("查询 CRM webhook 队列")]
[ProducesResponseType<CrmList<CrmQueueItem>>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmList<CrmQueueItem>>> Queue(
[FromQuery] CrmQueueQueryDto query,
CancellationToken cancellationToken)
{
return Ok(await crmService.GetQueueAsync(ResolveActor(), query.ToQuery(), cancellationToken));
}
[HttpGet("dead-letters")]
[EndpointSummary("查询 CRM 死信任务与汇总")]
[ProducesResponseType<CrmDeadLetterResult>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmDeadLetterResult>> DeadLetters(
[FromQuery] CrmQueueQueryDto query,
CancellationToken cancellationToken)
{
return Ok(await crmService.GetDeadLettersAsync(ResolveActor(), query.ToQuery(), cancellationToken));
}
[HttpGet("queue/logs")]
[EndpointSummary("查询 CRM 队列执行日志")]
[ProducesResponseType<CrmList<CrmQueueLogItem>>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmList<CrmQueueLogItem>>> Logs(
[FromQuery] CrmQueueLogQueryDto query,
CancellationToken cancellationToken)
{
return Ok(await crmService.GetLogsAsync(ResolveActor(), query.ToQuery(), cancellationToken));
}
[HttpPost("queue/action")]
[EndpointSummary("重试或忽略 CRM 死信任务")]
[ProducesResponseType<CrmQueueItem>(StatusCodes.Status200OK)]
public async Task<ActionResult<CrmQueueItem>> Action(
CrmQueueActionDto request,
CancellationToken cancellationToken)
{
return Ok(await crmService.ApplyQueueActionAsync(ResolveActor(), request.ToCommand(), cancellationToken));
}
private CrmAdminActor ResolveActor()
{
if (currentTenant.TenantId is null || currentUser.UserId is null)
{
throw new CrmException("CRM admin actor was not resolved.", "crm_access_denied");
}
return new CrmAdminActor(currentTenant.TenantId.Value, currentUser.UserId.Value);
}
}