✨ Bot transparency API
This commit is contained in:
@@ -18,6 +18,12 @@ public class BotAccount : ModelBase
|
|||||||
|
|
||||||
[NotMapped] public AccountReference? Account { get; set; }
|
[NotMapped] public AccountReference? Account { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This developer field is to serve the transparent info for user to know which developer
|
||||||
|
/// published this robot. Not for relationships usage.
|
||||||
|
/// </summary>
|
||||||
|
[NotMapped] public Developer? Developer { get; set; }
|
||||||
|
|
||||||
public Shared.Proto.BotAccount ToProtoValue()
|
public Shared.Proto.BotAccount ToProtoValue()
|
||||||
{
|
{
|
||||||
var proto = new Shared.Proto.BotAccount
|
var proto = new Shared.Proto.BotAccount
|
||||||
|
35
DysonNetwork.Develop/Identity/BotAccountPublicController.cs
Normal file
35
DysonNetwork.Develop/Identity/BotAccountPublicController.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace DysonNetwork.Develop.Identity;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/bots")]
|
||||||
|
public class BotAccountPublicController(BotAccountService botService, DeveloperService developerService) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("{botId:guid}")]
|
||||||
|
public async Task<ActionResult<BotAccount>> GetBotTransparentInfo([FromRoute] Guid botId)
|
||||||
|
{
|
||||||
|
var bot = await botService.GetBotByIdAsync(botId);
|
||||||
|
if (bot is null) return NotFound("Bot not found");
|
||||||
|
bot = await botService.LoadBotAccountAsync(bot);
|
||||||
|
|
||||||
|
var developer = await developerService.GetDeveloperById(bot!.Project.DeveloperId);
|
||||||
|
if (developer is null) return NotFound("Developer not found");
|
||||||
|
bot.Developer = await developerService.LoadDeveloperPublisher(developer);
|
||||||
|
|
||||||
|
return Ok(bot);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{botId:guid}/developer")]
|
||||||
|
public async Task<ActionResult<Developer>> GetBotDeveloper([FromRoute] Guid botId)
|
||||||
|
{
|
||||||
|
var bot = await botService.GetBotByIdAsync(botId);
|
||||||
|
if (bot is null) return NotFound("Bot not found");
|
||||||
|
|
||||||
|
var developer = await developerService.GetDeveloperById(bot!.Project.DeveloperId);
|
||||||
|
if (developer is null) return NotFound("Developer not found");
|
||||||
|
developer = await developerService.LoadDeveloperPublisher(developer);
|
||||||
|
|
||||||
|
return Ok(developer);
|
||||||
|
}
|
||||||
|
}
|
@@ -4,7 +4,10 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace DysonNetwork.Develop.Identity;
|
namespace DysonNetwork.Develop.Identity;
|
||||||
|
|
||||||
public class DeveloperService(AppDatabase db, PublisherService.PublisherServiceClient ps, ILogger<DeveloperService> logger)
|
public class DeveloperService(
|
||||||
|
AppDatabase db,
|
||||||
|
PublisherService.PublisherServiceClient ps,
|
||||||
|
ILogger<DeveloperService> logger)
|
||||||
{
|
{
|
||||||
public async Task<Developer> LoadDeveloperPublisher(Developer developer)
|
public async Task<Developer> LoadDeveloperPublisher(Developer developer)
|
||||||
{
|
{
|
||||||
@@ -47,6 +50,11 @@ public class DeveloperService(AppDatabase db, PublisherService.PublisherServiceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Developer?> GetDeveloperById(Guid id)
|
||||||
|
{
|
||||||
|
return await db.Developers.FirstOrDefaultAsync(d => d.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> IsMemberWithRole(Guid pubId, Guid accountId, PublisherMemberRole role)
|
public async Task<bool> IsMemberWithRole(Guid pubId, Guid accountId, PublisherMemberRole role)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Reference in New Issue
Block a user