62a5121ffe
Build backend images / build content-svc (push) Failing after 56s
Build backend images / build file-svc (push) Failing after 54s
Build backend images / build gateway (push) Failing after 1m1s
Build backend images / build identity-svc (push) Failing after 55s
Build backend images / build notification-svc (push) Failing after 54s
Build backend images / build render-svc (push) Failing after 52s
Build backend images / build studio-svc (push) Failing after 1m2s
Modeled on the legacy DivineGateWeb admin (CRM + Security/* actions):
- identity-svc AdminService + AdminController (admin-gated):
- GET /v1/admin/crm/analytics — signups/buyers/conversion/revenue + daily series
(from identity.users + identity.payments)
- GET/PUT /v1/users/{id}/crm — tags / note / pipeline status (user_crm table, mig 20)
- power-actions: POST /v1/users/{id}/{balance,password,charge,moderator,grant-plan}
- admin UI: /admin/crm dashboard (funnel cards + daily signup/revenue bars);
per-user "مدیریت" modal in Users (balance, render charge, plan days, password,
moderator, CRM notes)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
3.1 KiB
C#
76 lines
3.1 KiB
C#
using FlatRender.IdentitySvc.Application.Services;
|
|
using FlatRender.IdentitySvc.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace FlatRender.IdentitySvc.Controllers;
|
|
|
|
[ApiController]
|
|
[Authorize(Roles = "Admin")]
|
|
public class AdminController(AdminService svc) : ControllerBase
|
|
{
|
|
private Guid TenantId =>
|
|
Guid.TryParse(User.FindFirst("tenant_id")?.Value, out var t)
|
|
? t : Guid.Parse("00000000-0000-0000-0000-000000000001");
|
|
|
|
// ── CRM analytics ────────────────────────────────────────────────────────
|
|
[HttpGet("v1/admin/crm/analytics")]
|
|
public async Task<IActionResult> Crm([FromQuery] DateTime? start, [FromQuery] DateTime? end)
|
|
{
|
|
var s = start ?? DateTime.UtcNow.AddDays(-30);
|
|
var e = end ?? DateTime.UtcNow;
|
|
return Ok(await svc.GetCrmAnalyticsAsync(TenantId, s, e));
|
|
}
|
|
|
|
// ── CRM notes / tags ───────────────────────────────────────────────────────
|
|
[HttpGet("v1/users/{userId:guid}/crm")]
|
|
public async Task<IActionResult> GetCrm(Guid userId) => Ok(await svc.GetUserCrmAsync(userId));
|
|
|
|
[HttpPut("v1/users/{userId:guid}/crm")]
|
|
public async Task<IActionResult> PutCrm(Guid userId, [FromBody] UpsertUserCrmRequest req)
|
|
=> Ok(await svc.UpsertUserCrmAsync(userId, req));
|
|
|
|
// ── Power-actions ──────────────────────────────────────────────────────────
|
|
[HttpPost("v1/users/{userId:guid}/balance")]
|
|
public async Task<IActionResult> Balance(Guid userId, [FromBody] SetBalanceRequest req)
|
|
{
|
|
await svc.SetBalanceAsync(userId, req.AmountMinor, req.Add);
|
|
return Ok(new { ok = true });
|
|
}
|
|
|
|
[HttpPost("v1/users/{userId:guid}/password")]
|
|
public async Task<IActionResult> Password(Guid userId, [FromBody] ResetPasswordRequest req)
|
|
{
|
|
await svc.ResetPasswordAsync(userId, req.NewPassword);
|
|
return Ok(new { ok = true });
|
|
}
|
|
|
|
[HttpPost("v1/users/{userId:guid}/charge")]
|
|
public async Task<IActionResult> Charge(Guid userId, [FromBody] AddChargeRequest req)
|
|
{
|
|
await svc.AddChargeAsync(userId, req.Seconds, req.RenderCount);
|
|
return Ok(new { ok = true });
|
|
}
|
|
|
|
[HttpPost("v1/users/{userId:guid}/moderator")]
|
|
public async Task<IActionResult> Moderator(Guid userId, [FromBody] SetFlagRequest req)
|
|
{
|
|
await svc.SetModeratorAsync(userId, req.Enabled);
|
|
return Ok(new { ok = true });
|
|
}
|
|
|
|
[HttpPost("v1/users/{userId:guid}/grant-plan")]
|
|
public async Task<IActionResult> GrantPlan(Guid userId, [FromBody] GrantPlanDaysRequest req)
|
|
{
|
|
try
|
|
{
|
|
await svc.GrantPlanDaysAsync(userId, req.PlanId, req.Days);
|
|
return Ok(new { ok = true });
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return BadRequest(new { error = new { message = ex.Message } });
|
|
}
|
|
}
|
|
}
|