Browse Source

商店数据用的是账号id的bug

master
秦汉 2 weeks ago
parent
commit
6adde41763
  1. 16
      Build_God_Api/Build_God_Api/Controllers/ShopController.cs

16
Build_God_Api/Build_God_Api/Controllers/ShopController.cs

@ -9,10 +9,12 @@ namespace Build_God_Api.Controllers
[Route("api/god/[controller]")] [Route("api/god/[controller]")]
public class ShopController( public class ShopController(
IShopService service, IShopService service,
ICharacterService characterService,
ICurrentUserService currentUserService ICurrentUserService currentUserService
) : ControllerBase ) : ControllerBase
{ {
private readonly IShopService service = service; private readonly IShopService service = service;
private readonly ICharacterService characterService = characterService;
private readonly ICurrentUserService currentUserService = currentUserService; private readonly ICurrentUserService currentUserService = currentUserService;
// ============ 商店物品配置管理(后台) ============ // ============ 商店物品配置管理(后台) ============
@ -59,7 +61,12 @@ namespace Build_God_Api.Controllers
[Authorize] [Authorize]
public async Task<ActionResult<ShopDto>> GetCharacterShop() public async Task<ActionResult<ShopDto>> GetCharacterShop()
{ {
var characterList = await service.GetCharacterShop(currentUserService.UserId); var character = await characterService.GetCharacterByAccountId(currentUserService.UserId);
if (character == null)
{
return NotFound();
}
var characterList = await service.GetCharacterShop(character.Id);
return characterList; return characterList;
} }
@ -67,7 +74,12 @@ namespace Build_God_Api.Controllers
[Authorize] [Authorize]
public async Task<ActionResult<bool>> BuyItem([FromBody] ShopBuyDto dto) public async Task<ActionResult<bool>> BuyItem([FromBody] ShopBuyDto dto)
{ {
return await service.BuyItem(currentUserService.UserId, dto.ShopItemId); var character = await characterService.GetCharacterByAccountId(currentUserService.UserId);
if (character == null)
{
return NotFound();
}
return await service.BuyItem(character.Id, dto.ShopItemId);
} }
} }

Loading…
Cancel
Save