-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54316d2
commit 0da5d4a
Showing
33 changed files
with
2,933 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Security.Claims; | ||
using API.Entities; | ||
using API.Services; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace API.Controllers; | ||
|
||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class OrderController : ControllerBase | ||
{ | ||
private readonly IOrderService _orderService; | ||
private readonly IAddressService _addressService; | ||
private readonly ICartService _cartService; | ||
|
||
public OrderController(IOrderService orderService, IAddressService addressService, ICartService cartService) | ||
{ | ||
_orderService = orderService; | ||
_addressService = addressService; | ||
_cartService = cartService; | ||
} | ||
|
||
[HttpGet] | ||
public Task<IEnumerable<Order>> GetOrders() | ||
{ | ||
return _orderService.GetOrders(GetUserId()); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ActionResult> CreateOrder(int addressId) | ||
{ | ||
await _orderService.CreateOrder(GetUserId(), addressId); | ||
return NoContent(); | ||
} | ||
|
||
|
||
private int GetUserId() | ||
{ | ||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); | ||
int.TryParse(userId, out int validUserId); | ||
return validUserId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.