هنعمل Endpoint اللي بتجيب Order محدد لـ User معين

هنعملها جوا الـ Orders Controller

[ProducesResponseType(typeof(Order)), StatusCodes.Status200OK]
[ProducesResponseType(typeof(ApiResponse)), StatusCodes.Status400NotFound]
// Variable Segmant
[HttpGet("{id}")] // GET : api/orders/1?email=mahmoudfeshar11@gmail.com
public async Task<ActionResult<Order>> GetOrderForUser(int id, string email)
{
	var order = await _orderService.GetOrderByIdForUserAsync(id, email);
	if(order is null) return NotFound(new ApiResponse(404));
	return Ok(order);
}

أي Endpoint في الـ Orders Controller انه لازم يكون Authorized وهيبعتلي Token وانا هاخد منه الـ Email

نروح نعمل Implement لـ GetOrderByIdForUserAsync في الـ OrderService

public Task<Order?> GetOrderByIdForUserAsync(int orderId, string buyerEmail)
{
	var orderRepo = _unitOfWork.Repository<Order>();
	var orderSpec = new OrderSpecifications(orderId, buyerEmail);
	var order = orderRepo.GetByIdWithSpecAsync(orderSpec); 
	// Rename simple one (GetAsync) to (GetByIdAsync)
	return order;
}
 
// We can make it one line
 
public Task<Order?> GetOrderByIdForUserAsync(int orderId, string buyerEmail)
	=> await _unitOfWork.Repossitory<Order>().GetByIdWithSpecAsync(new OrderSpecifications(orderId, buyerEmail));

محتاج أعمل Ctor في الـ OrderSpecifications عشان ياخد الاتنين دول

public OrderSpecifications(int orderId, string buyerEmail)
	:base(O => O.Id == orderId && O.BuyerEmail == buyerEmail)
{
	Includes.Add(O => O.DeliveryMethod);
	Includes.Add(O => O.Items);
}