Files
flatrender/services/studio/FlatRender.StudioSvc/Controllers/StudioController.cs
T
soroush.asadi a69bc62724
Build backend images / build content-svc (push) Failing after 1m3s
Build backend images / build file-svc (push) Failing after 1m5s
Build backend images / build gateway (push) Failing after 1m0s
Build backend images / build identity-svc (push) Failing after 1m8s
Build backend images / build notification-svc (push) Failing after 57s
Build backend images / build render-svc (push) Failing after 1m6s
Build backend images / build studio-svc (push) Failing after 1m3s
feat(studio B1): persist input edits to content elements (render-binding foundation)
Studio edits previously went only to edit_state; the render binds saved_scene_contents,
so edits never reached the MP4. Add studio-svc PATCH /v1/saved-projects/{id}/contents
(update saved_scene_contents.value/value_file_id by content key, ExecuteSqlInterpolated
for null-safe params) + Next /api/projects/[id]/contents route + persistence hook pushes
edited values (from bridged c-<key> layers) alongside the scene_data save. Verified
text persists incl. UTF-8 Persian (9 chars/17 bytes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 00:53:17 +03:30

69 lines
2.7 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>Update individual scene-input values by content key (live studio edits).</summary>
[HttpPatch("{id:guid}/contents")]
public async Task<IActionResult> UpdateContents(Guid id, [FromBody] UpdateContentsRequest req) =>
Ok(new { updated = await svc.UpdateSceneContentsAsync(id, UserId, req.Items ?? new List<UpdateContentItem>()) });
/// <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));
}