Compare commits
2 Commits
c7925d98c8
...
d9620fd6a4
Author | SHA1 | Date | |
---|---|---|---|
|
d9620fd6a4 | ||
|
541e2dd14c |
@@ -17,6 +17,12 @@ public class BotAccount : ModelBase
|
||||
public DevProject Project { get; set; } = null!;
|
||||
|
||||
[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()
|
||||
{
|
||||
|
@@ -65,7 +65,7 @@ public class BotAccountController(
|
||||
|
||||
[MaxLength(256)] public string? Nick { get; set; } = string.Empty;
|
||||
|
||||
[Required] [MaxLength(1024)] public string Slug { get; set; } = string.Empty;
|
||||
[Required] [MaxLength(1024)] public string? Slug { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(128)] public string? Language { get; set; }
|
||||
|
||||
@@ -192,7 +192,7 @@ public class BotAccountController(
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{botId:guid}")]
|
||||
[HttpPatch("{botId:guid}")]
|
||||
public async Task<IActionResult> UpdateBot(
|
||||
[FromRoute] string pubName,
|
||||
[FromRoute] Guid projectId,
|
||||
@@ -234,15 +234,16 @@ public class BotAccountController(
|
||||
if (request.Location is not null) botAccount.Profile.Location = request.Location;
|
||||
if (request.Birthday is not null) botAccount.Profile.Birthday = request.Birthday?.ToTimestamp();
|
||||
|
||||
if (request.Slug is not null) bot.Slug = request.Slug;
|
||||
if (request.IsActive is not null) bot.IsActive = request.IsActive.Value;
|
||||
|
||||
try
|
||||
{
|
||||
var updatedBot = await botService.UpdateBotAsync(
|
||||
bot,
|
||||
botAccount,
|
||||
request.PictureId,
|
||||
request.BackgroundId,
|
||||
request.Slug,
|
||||
request.IsActive
|
||||
request.BackgroundId
|
||||
);
|
||||
|
||||
return Ok(updatedBot);
|
||||
|
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);
|
||||
}
|
||||
}
|
@@ -89,29 +89,16 @@ public class BotAccountService(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BotAccount> UpdateBotAsync(BotAccount bot,
|
||||
public async Task<BotAccount> UpdateBotAsync(
|
||||
BotAccount bot,
|
||||
Account account,
|
||||
string? pictureId,
|
||||
string? backgroundId,
|
||||
string? slug = null,
|
||||
bool? isActive = null
|
||||
string? backgroundId
|
||||
)
|
||||
{
|
||||
var updated = false;
|
||||
if (slug != null && bot.Slug != slug)
|
||||
{
|
||||
bot.Slug = slug;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (isActive.HasValue && bot.IsActive != isActive.Value)
|
||||
{
|
||||
bot.IsActive = isActive.Value;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (!updated) return bot;
|
||||
|
||||
db.Update(bot);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
try
|
||||
{
|
||||
// Update the bot account in the Pass service
|
||||
|
@@ -4,7 +4,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
try
|
||||
|
Reference in New Issue
Block a user