forked from xiongyuxing/tiku-backend.net
feat: add student video and profile experience
This commit is contained in:
58
Tiku.Api/Controllers/VideosController.cs
Normal file
58
Tiku.Api/Controllers/VideosController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Tiku.Api.Contracts;
|
||||
using Tiku.Application.Assets;
|
||||
using Tiku.Application.Catalog;
|
||||
using Tiku.Application.Security;
|
||||
|
||||
namespace Tiku.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Policy = TikuPolicies.CurrentTenantMember)]
|
||||
[Produces("application/json")]
|
||||
[Route("api/videos")]
|
||||
public sealed class VideosController(
|
||||
IVideoPlaybackService videoPlaybackService,
|
||||
ICurrentUser currentUser,
|
||||
ITenantContext currentTenant) : ControllerBase
|
||||
{
|
||||
[HttpGet("search")]
|
||||
[EndpointSummary("搜索通用解析视频")]
|
||||
[ProducesResponseType<CatalogList<VideoExplanationCatalogItem>>(StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<CatalogList<VideoExplanationCatalogItem>>> Search(
|
||||
[FromQuery] VideoSearchQueryDto query,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await videoPlaybackService.SearchAsync(ResolveActor(), query.ToQuery(), cancellationToken));
|
||||
}
|
||||
|
||||
[HttpPost("play")]
|
||||
[EndpointSummary("申请视频播放信息")]
|
||||
[ProducesResponseType<VideoPlaybackItem>(StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<VideoPlaybackItem>> Play(
|
||||
VideoPlayDto request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await videoPlaybackService.PlayAsync(ResolveActor(), request.ToCommand(), cancellationToken));
|
||||
}
|
||||
|
||||
[HttpPost("progress")]
|
||||
[EndpointSummary("上报视频播放进度")]
|
||||
[ProducesResponseType<VideoProgressItem>(StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<VideoProgressItem>> Progress(
|
||||
VideoProgressDto request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await videoPlaybackService.ReportProgressAsync(ResolveActor(), request.ToCommand(), cancellationToken));
|
||||
}
|
||||
|
||||
private VideoPlaybackActor ResolveActor()
|
||||
{
|
||||
if (currentTenant.TenantId is null || currentUser.UserId is null)
|
||||
{
|
||||
throw new VideoPlaybackException("Current video actor was not resolved.", "video_access_denied");
|
||||
}
|
||||
|
||||
return new VideoPlaybackActor(currentTenant.TenantId.Value, currentUser.UserId.Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user