diff --git a/NineChroniclesUtilBackend/Controllers/AvatarController.cs b/NineChroniclesUtilBackend/Controllers/AvatarController.cs index 2c44eabb..de02ea07 100644 --- a/NineChroniclesUtilBackend/Controllers/AvatarController.cs +++ b/NineChroniclesUtilBackend/Controllers/AvatarController.cs @@ -9,6 +9,15 @@ namespace NineChroniclesUtilBackend.Controllers; public class AvatarController(AvatarRepository avatarRepository) : ControllerBase { [HttpGet("{avatarAddress}/inventory")] - public Inventory GetInventory(string avatarAddress) => - avatarRepository.GetInventory(avatarAddress); + public Inventory? GetInventory(string avatarAddress) + { + var inventory = avatarRepository.GetInventory(avatarAddress); + if (inventory is null) + { + Response.StatusCode = StatusCodes.Status404NotFound; + return null; + } + + return inventory; + } } diff --git a/NineChroniclesUtilBackend/Repositories/AvatarRepository.cs b/NineChroniclesUtilBackend/Repositories/AvatarRepository.cs index 48224c33..9242e6b3 100644 --- a/NineChroniclesUtilBackend/Repositories/AvatarRepository.cs +++ b/NineChroniclesUtilBackend/Repositories/AvatarRepository.cs @@ -10,11 +10,16 @@ public class AvatarRepository(MongoDBCollectionService mongoDBCollectionService) private readonly IMongoCollection _avatarsCollection = mongoDBCollectionService.GetCollection("avatars"); - public Inventory GetInventory(string avatarAddress) + public Inventory? GetInventory(string avatarAddress) { var filter = Builders.Filter.Eq(f => f["Avatar"]["address"], avatarAddress); var projection = Builders.Projection.Include(f => f["Avatar"]["inventory"]["Equipments"]); var document = _avatarsCollection.Find(filter).Project(projection).FirstOrDefault(); + if (document is null) + { + return null; + } + return new Inventory(document["Avatar"]["inventory"]); } }