Files
flatrender/services/studio/FlatRender.StudioSvc/Controllers/StudioController.cs
T
soroush.asadi 3091911260
Build backend images / build content-svc (push) Failing after 1s
Build backend images / build file-svc (push) Failing after 1s
Build backend images / build gateway (push) Failing after 0s
Build backend images / build identity-svc (push) Failing after 0s
Build backend images / build notification-svc (push) Failing after 1s
Build backend images / build render-svc (push) Failing after 1s
Build backend images / build studio-svc (push) Failing after 1s
feat(admin): affiliate/personal discounts, user-videos, internal routes, authz
Closes the remaining legacy-admin gaps:
- Users «مدیریت» modal: create personal discount or affiliate code (owner_user_id +
  owner_profit_percentage on existing /v1/discounts), and view the user's saved
  projects ("videos") via new admin GET /v1/saved-projects/by-user/{id} (studio)
- Internal routes admin (/admin/routes): CRUD on content.internal_routes
  (RoutesController + CmsService + gateway /v1/routes/*)
- Security: lock identity UsersController Search + Ban to [Authorize(Roles="Admin")]

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 22:42:01 +03:30

64 lines
2.4 KiB
C#

using System.Security.Claims;
using FlatRender.StudioSvc.Application.Services;
using FlatRender.StudioSvc.Models.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FlatRender.StudioSvc.Controllers;
[ApiController]
[Route("v1/saved-projects")]
[Authorize]
public class StudioController(StudioService svc) : ControllerBase
{
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
private Guid TenantId => Guid.Parse(
User.FindFirstValue("tenant_id") ?? "00000000-0000-0000-0000-000000000001");
[HttpGet]
public async Task<IActionResult> List([FromQuery] SavedProjectListRequest req) =>
Ok(await svc.ListProjectsAsync(UserId, req));
// Admin: view any user's saved projects ("user videos" viewer).
[HttpGet("by-user/{userId:guid}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> ListByUser(Guid userId, [FromQuery] SavedProjectListRequest req) =>
Ok(await svc.ListProjectsAsync(userId, req));
[HttpGet("{id:guid}")]
public async Task<IActionResult> Get(Guid id) =>
Ok(await svc.GetProjectAsync(id, UserId));
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateSavedProjectRequest req)
{
var result = await svc.CreateProjectAsync(UserId, TenantId, req);
return CreatedAtAction(nameof(Get), new { id = result.Id }, result);
}
[HttpPatch("{id:guid}")]
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateSavedProjectRequest req) =>
Ok(await svc.UpdateProjectAsync(id, UserId, req));
[HttpDelete("{id:guid}")]
public async Task<IActionResult> Delete(Guid id)
{
await svc.DeleteProjectAsync(id, UserId);
return NoContent();
}
/// <summary>
/// Save all scenes for a project (full atomic replace).
/// Called by the studio editor on every save.
/// </summary>
[HttpPut("{id:guid}/scenes")]
public async Task<IActionResult> SaveScenes(Guid id, [FromBody] List<SaveSceneRequest> scenes) =>
Ok(await svc.SaveScenesAsync(id, UserId, scenes));
/// <summary>Internal endpoint: get project for render service (no user-ownership check).</summary>
[HttpGet("{id:guid}/render-payload")]
[Authorize(Roles = "Service")]
public async Task<IActionResult> GetRenderPayload(Guid id) =>
Ok(await svc.GetProjectForRenderAsync(id));
}