forked from xiongyuxing/tiku-backend.net
- 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.
103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Tiku.Api.Contracts;
|
|
using Tiku.Application.Points;
|
|
using Tiku.Application.Security;
|
|
|
|
namespace Tiku.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Tags("学生端-积分")]
|
|
[Authorize(Policy = TikuPolicies.CurrentTenantMember)]
|
|
[Tiku.Api.Security.RequireSaasFeature(SaasFeatureCatalog.StudentStore)]
|
|
[Produces("application/json")]
|
|
[Route("api/points")]
|
|
public sealed class PointsController(
|
|
IPointService pointService,
|
|
ICurrentUser currentUser,
|
|
ITenantContext currentTenant) : ControllerBase
|
|
{
|
|
[HttpGet("summary")]
|
|
[EndpointSummary("查询当前用户积分摘要")]
|
|
[ProducesResponseType<PointSummaryItem>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointSummaryItem>> Summary(CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.GetSummaryAsync(ResolveActor(), cancellationToken));
|
|
}
|
|
|
|
[HttpGet("tasks")]
|
|
[EndpointSummary("查询当前可领取积分任务")]
|
|
[ProducesResponseType<PointList<PointTaskItem>>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointList<PointTaskItem>>> Tasks(
|
|
[FromQuery] PointQueryDto query,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.GetTasksAsync(
|
|
ResolveActor(),
|
|
query.ToQuery(),
|
|
cancellationToken));
|
|
}
|
|
|
|
[HttpPost("tasks/claim")]
|
|
[EndpointSummary("领取积分任务奖励")]
|
|
[ProducesResponseType<PointClaimItem>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointClaimItem>> ClaimTask(
|
|
ClaimPointTaskDto request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.ClaimTaskAsync(
|
|
ResolveActor(),
|
|
request.ToCommand(),
|
|
cancellationToken));
|
|
}
|
|
|
|
[HttpGet("exchange-items")]
|
|
[EndpointSummary("查询积分兑换项")]
|
|
[ProducesResponseType<PointList<PointExchangeItemDto>>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointList<PointExchangeItemDto>>> ExchangeItems(
|
|
[FromQuery] PointQueryDto query,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.GetExchangeItemsAsync(
|
|
ResolveActor(),
|
|
query.ToQuery(),
|
|
cancellationToken));
|
|
}
|
|
|
|
[HttpPost("exchange-orders")]
|
|
[EndpointSummary("创建积分兑换订单")]
|
|
[ProducesResponseType<PointExchangeOrderItem>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointExchangeOrderItem>> CreateExchangeOrder(
|
|
CreatePointExchangeOrderDto request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.CreateExchangeOrderAsync(
|
|
ResolveActor(),
|
|
request.ToCommand(),
|
|
cancellationToken));
|
|
}
|
|
|
|
[HttpGet("exchange-orders")]
|
|
[EndpointSummary("查询当前用户积分兑换订单")]
|
|
[ProducesResponseType<PointList<PointExchangeOrderItem>>(StatusCodes.Status200OK)]
|
|
public async Task<ActionResult<PointList<PointExchangeOrderItem>>> ExchangeOrders(
|
|
[FromQuery] PointQueryDto query,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return Ok(await pointService.GetExchangeOrdersAsync(
|
|
ResolveActor(),
|
|
query.ToQuery(),
|
|
cancellationToken));
|
|
}
|
|
|
|
private PointActor ResolveActor()
|
|
{
|
|
if (currentTenant.TenantId is null || currentUser.UserId is null)
|
|
{
|
|
throw new PointException("Current point actor was not resolved.", "point_access_denied");
|
|
}
|
|
|
|
return new PointActor(currentTenant.TenantId.Value, currentUser.UserId.Value);
|
|
}
|
|
}
|