feat: V2 microservices stack — backend services, gateway, JWT auth
Add full V2 architecture: identity, content, studio (.NET 10) and file, render, notification, gateway (Go) services with vendored deps, plus DB migrations, event/API contracts, and an init-db script. Wire the Next.js frontend to the gateway: server-side JWT auth routes (login/register/refresh/logout/me), gateway fetch helper, and session/ cookie/jwt helpers under src/lib. Containerize the stack via docker-compose.v2.yml and per-service Dockerfiles. Base images resolve through a Nexus mirror (Docker Hub) and MCR directly; npm/NuGet pull from Nexus groups. Self-host fonts via next/font/local to avoid Google Fonts (geo-blocked). Add CI workflow and ignore .env.v2, *.stackdump, and .NET bin/obj. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
using System.Security.Claims;
|
||||
using FlatRender.ContentSvc.Application.Services;
|
||||
using FlatRender.ContentSvc.Models.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FlatRender.ContentSvc.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/blogs")]
|
||||
public class BlogsController(CmsService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> List([FromQuery] BlogListRequest req) =>
|
||||
Ok(await svc.GetBlogsAsync(req));
|
||||
|
||||
[HttpGet("{slug}")]
|
||||
public async Task<IActionResult> Get(string slug) =>
|
||||
Ok(await svc.GetBlogBySlugAsync(slug));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateBlogRequest req)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) is { } s ? Guid.Parse(s) : (Guid?)null;
|
||||
return Ok(await svc.CreateBlogAsync(new BlogListRequest(), req, userId));
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateBlogRequest req) =>
|
||||
Ok(await svc.UpdateBlogAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
await svc.DeleteBlogAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/comments")]
|
||||
public class CommentsController(CmsService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> List(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 20,
|
||||
[FromQuery] Guid? blogId = null, [FromQuery] Guid? containerId = null,
|
||||
[FromQuery] bool? isApproved = null) =>
|
||||
Ok(await svc.GetCommentsAsync(page, pageSize, blogId, containerId, isApproved));
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateCommentRequest req)
|
||||
{
|
||||
var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||
return Ok(await svc.CreateCommentAsync(req, userId));
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPatch("{id:guid}/approve")]
|
||||
public async Task<IActionResult> Approve(Guid id, [FromQuery] bool approve = true)
|
||||
{
|
||||
await svc.ApproveCommentAsync(id, approve);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
await svc.DeleteCommentAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/slides")]
|
||||
public class SlidesController(CmsService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery] Guid? tenantId = null) =>
|
||||
Ok(await svc.GetSlidesAsync(tenantId));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateSlideRequest req) =>
|
||||
Ok(await svc.CreateSlideAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
await svc.DeleteSlideAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/home-events")]
|
||||
public class HomePageEventsController(CmsService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery] Guid? tenantId = null) =>
|
||||
Ok(await svc.GetHomePageEventsAsync(tenantId));
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/settings")]
|
||||
public class WebsiteSettingsController(CmsService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery] Guid? tenantId = null) =>
|
||||
Ok(await svc.GetSettingsAsync(tenantId, includeSecret: false));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpGet("all")]
|
||||
public async Task<IActionResult> GetAll([FromQuery] Guid? tenantId = null) =>
|
||||
Ok(await svc.GetSettingsAsync(tenantId, includeSecret: true));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> Upsert([FromQuery] Guid? tenantId, [FromBody] UpsertWebsiteSettingRequest req) =>
|
||||
Ok(await svc.UpsertSettingAsync(tenantId, req));
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/favorites")]
|
||||
[Authorize]
|
||||
public class FavoritesController(CmsService 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("folders")]
|
||||
public async Task<IActionResult> GetFolders() =>
|
||||
Ok(await svc.GetFavoriteFoldersAsync(UserId));
|
||||
|
||||
[HttpPost("folders")]
|
||||
public async Task<IActionResult> CreateFolder([FromBody] CreateFavoriteFolderRequest req) =>
|
||||
Ok(await svc.CreateFavoriteFolderAsync(UserId, TenantId, req));
|
||||
|
||||
[HttpDelete("folders/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteFolder(Guid id)
|
||||
{
|
||||
await svc.DeleteFavoriteFolderAsync(UserId, id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("containers")]
|
||||
public async Task<IActionResult> AddContainer([FromBody] AddFavoriteContainerRequest req)
|
||||
{
|
||||
await svc.AddFavoriteContainerAsync(UserId, TenantId, req);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("containers/{containerId:guid}")]
|
||||
public async Task<IActionResult> RemoveContainer(Guid containerId)
|
||||
{
|
||||
await svc.RemoveFavoriteContainerAsync(UserId, containerId);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using FlatRender.ContentSvc.Application.Services;
|
||||
using FlatRender.ContentSvc.Models.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FlatRender.ContentSvc.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("v1")]
|
||||
public class TaxonomyController(TaxonomyService svc) : ControllerBase
|
||||
{
|
||||
// ── Categories ────────────────────────────────────────────────────────────
|
||||
|
||||
[HttpGet("categories")]
|
||||
public async Task<IActionResult> GetCategories() =>
|
||||
Ok(await svc.GetCategoryTreeAsync());
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost("categories")]
|
||||
public async Task<IActionResult> CreateCategory([FromBody] CreateCategoryRequest req) =>
|
||||
Ok(await svc.CreateCategoryAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("categories/{id:guid}")]
|
||||
public async Task<IActionResult> UpdateCategory(Guid id, [FromBody] UpdateCategoryRequest req) =>
|
||||
Ok(await svc.UpdateCategoryAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("categories/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteCategory(Guid id)
|
||||
{
|
||||
await svc.DeleteCategoryAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ── Tags ──────────────────────────────────────────────────────────────────
|
||||
|
||||
[HttpGet("tags")]
|
||||
public async Task<IActionResult> GetTags(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 50,
|
||||
[FromQuery] string? search = null) =>
|
||||
Ok(await svc.GetTagsAsync(page, pageSize, search));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost("tags")]
|
||||
public async Task<IActionResult> CreateTag([FromBody] CreateTagRequest req) =>
|
||||
Ok(await svc.CreateTagAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("tags/{id:guid}")]
|
||||
public async Task<IActionResult> UpdateTag(Guid id, [FromBody] UpdateTagRequest req) =>
|
||||
Ok(await svc.UpdateTagAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("tags/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteTag(Guid id)
|
||||
{
|
||||
await svc.DeleteTagAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ── Fonts ─────────────────────────────────────────────────────────────────
|
||||
|
||||
[HttpGet("fonts")]
|
||||
public async Task<IActionResult> GetFonts(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 50,
|
||||
[FromQuery] string? search = null, [FromQuery] string? direction = null) =>
|
||||
Ok(await svc.GetFontsAsync(page, pageSize, search, direction));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost("fonts")]
|
||||
public async Task<IActionResult> CreateFont([FromBody] CreateFontRequest req) =>
|
||||
Ok(await svc.CreateFontAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("fonts/{id:guid}")]
|
||||
public async Task<IActionResult> UpdateFont(Guid id, [FromBody] UpdateFontRequest req) =>
|
||||
Ok(await svc.UpdateFontAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("fonts/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteFont(Guid id)
|
||||
{
|
||||
await svc.DeleteFontAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ── Music Tracks ──────────────────────────────────────────────────────────
|
||||
|
||||
[HttpGet("music")]
|
||||
public async Task<IActionResult> GetMusicTracks(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 50,
|
||||
[FromQuery] string? search = null) =>
|
||||
Ok(await svc.GetMusicTracksAsync(page, pageSize, search));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost("music")]
|
||||
public async Task<IActionResult> CreateMusicTrack([FromBody] CreateMusicTrackRequest req) =>
|
||||
Ok(await svc.CreateMusicTrackAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("music/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteMusicTrack(Guid id)
|
||||
{
|
||||
await svc.DeleteMusicTrackAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using FlatRender.ContentSvc.Application.Services;
|
||||
using FlatRender.ContentSvc.Models.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FlatRender.ContentSvc.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/templates")]
|
||||
public class TemplatesController(TemplateService svc) : ControllerBase
|
||||
{
|
||||
// ── Containers ────────────────────────────────────────────────────────────
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ListContainers([FromQuery] ContainerListRequest req) =>
|
||||
Ok(await svc.GetContainersAsync(req));
|
||||
|
||||
[HttpGet("{slug}")]
|
||||
public async Task<IActionResult> GetContainer(string slug)
|
||||
{
|
||||
await svc.IncrementContainerViewAsync(
|
||||
(await svc.GetContainerBySlugAsync(slug)).Id);
|
||||
return Ok(await svc.GetContainerBySlugAsync(slug));
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateContainer([FromBody] CreateContainerRequest req) =>
|
||||
Ok(await svc.CreateContainerAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> UpdateContainer(Guid id, [FromBody] UpdateContainerRequest req) =>
|
||||
Ok(await svc.UpdateContainerAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> DeleteContainer(Guid id)
|
||||
{
|
||||
await svc.DeleteContainerAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/projects")]
|
||||
public class ProjectsController(TemplateService svc) : ControllerBase
|
||||
{
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> GetProject(Guid id) =>
|
||||
Ok(await svc.GetProjectDetailAsync(id));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateProject([FromBody] CreateProjectRequest req) =>
|
||||
Ok(await svc.CreateProjectAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> UpdateProject(Guid id, [FromBody] UpdateProjectRequest req) =>
|
||||
Ok(await svc.UpdateProjectAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> DeleteProject(Guid id)
|
||||
{
|
||||
await svc.DeleteProjectAsync(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user