| 6 | namespace API.Extensions; |
| 7 | |
| 8 | public static class BasketExtensions |
| 9 | { |
| 10 | public static BasketDto ToDto(this Basket basket) |
| 11 | { |
| 12 | return new BasketDto |
| 13 | { |
| 14 | BasketId = basket.BasketId, |
| 15 | ClientSecret = basket.ClientSecret, |
| 16 | Coupon = basket.Coupon, |
| 17 | Items = basket.Items.Select(x => new BasketItemDto |
| 18 | { |
| 19 | ProductId = x.ProductId, |
| 20 | Name = x.Product.Name, |
| 21 | Price = x.Product.Price, |
| 22 | Brand = x.Product.Brand, |
| 23 | Type = x.Product.Type, |
| 24 | PictureUrl = x.Product.PictureUrl, |
| 25 | Quantity = x.Quantity |
| 26 | }).ToList() |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | public static async Task<Basket> GetBasketWithItems(this IQueryable<Basket> query, |
| 31 | string? basketId) |
| 32 | { |
| 33 | return await query |
| 34 | .Include(x => x.Items) |
| 35 | .ThenInclude(x => x.Product) |
| 36 | .FirstOrDefaultAsync(x => x.BasketId == basketId) |
| 37 | ?? throw new Exception("Cannot get basket"); |
| 38 | } |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected