using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using qtc_api.Services.StoreService; using System.Security.Claims; namespace qtc_api.Controllers { [Route("api/store")] [ApiController] public class StoreController : ControllerBase { private readonly StoreService _storeService; private readonly IUserService _userService; public StoreController(StoreService storeService, IUserService userService) { _storeService = storeService; _userService = userService; } [HttpGet] [Route("all-items")] public ActionResult>> GetAllItems() { return Ok(_storeService.GetStoreItems()); } [HttpPost] [Route("buy-item")] [Authorize] public async Task>> BuyStoreItem(int id) { var identity = HttpContext.User.Identity as ClaimsIdentity; if (identity != null) { IEnumerable claims = identity.Claims; var userId = claims.First().Value; if (userId != null) { var user = await _userService.GetUserById(userId); if(user != null && user.Success && user.Data != null) { var result = await _storeService.BuyStoreItem(user.Data.Id, id); return Ok(result); } else return Ok(new ServiceResponse { Success = false, Message = "User Not Found In Auth Header" }); } else return Ok(new ServiceResponse { Success = false, Message = "No UserId In Auth Header" }); } else return Ok(new ServiceResponse { Success = false, Message = "No Auth Header" }); } } }