From 541e2dd14c3d50b88409e24db6abc621ccf5c1cf Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 23 Aug 2025 17:06:52 +0800 Subject: [PATCH] :bug: Fix bots errors --- .../Identity/BotAccountController.cs | 11 ++++---- .../Identity/BotAccountService.cs | 25 +++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/DysonNetwork.Develop/Identity/BotAccountController.cs b/DysonNetwork.Develop/Identity/BotAccountController.cs index b0187a0..499e94b 100644 --- a/DysonNetwork.Develop/Identity/BotAccountController.cs +++ b/DysonNetwork.Develop/Identity/BotAccountController.cs @@ -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 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); diff --git a/DysonNetwork.Develop/Identity/BotAccountService.cs b/DysonNetwork.Develop/Identity/BotAccountService.cs index 321f356..70fbf48 100644 --- a/DysonNetwork.Develop/Identity/BotAccountService.cs +++ b/DysonNetwork.Develop/Identity/BotAccountService.cs @@ -89,29 +89,16 @@ public class BotAccountService( } } - public async Task UpdateBotAsync(BotAccount bot, + public async Task 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