|
2 | 2 | using System.Collections.Concurrent;
|
3 | 3 | using System.Collections.Generic;
|
4 | 4 | using System.Linq;
|
5 |
| -using WealthKernel.ShoppingCart.Models; |
| 5 | +using WealthKernel.ShoppingCart.Data.Models; |
6 | 6 |
|
7 | 7 | namespace WealthKernel.ShoppingCart.Data
|
8 | 8 | {
|
9 |
| - public class ShoppingCartRepository |
| 9 | + public class InMemoryCartItemsRepository |
10 | 10 | {
|
11 |
| - private readonly ConcurrentDictionary<string,CartItemInternal> _items; |
| 11 | + private readonly ConcurrentDictionary<string, CartItem> _items; |
12 | 12 |
|
13 |
| - public ShoppingCartRepository() |
| 13 | + public InMemoryCartItemsRepository() |
14 | 14 | {
|
15 |
| - _items = new ConcurrentDictionary<string, CartItemInternal>(); |
16 |
| - } |
17 |
| - |
18 |
| - public void AddItem(CartItemInternal item) |
| 15 | + _items = new ConcurrentDictionary<string, CartItem>(); |
| 16 | + } |
| 17 | + |
| 18 | + public void AddCartItem(CartItem item) |
19 | 19 | {
|
20 | 20 | var added = _items.TryAdd(item.Id, item);
|
21 |
| - |
| 21 | + |
22 | 22 | if (!added)
|
23 | 23 | {
|
24 | 24 | throw new InvalidOperationException($"Item {item.Id} already exists!");
|
25 | 25 | }
|
26 | 26 | }
|
27 | 27 |
|
28 |
| - public CartItemInternal? GetItem(string id) |
| 28 | + public CartItem? GetCartItem(string id) |
29 | 29 | {
|
30 | 30 | _items.TryGetValue(id, out var item);
|
31 | 31 | return item;
|
32 | 32 | }
|
33 | 33 |
|
34 |
| - public IList<CartItemInternal> SearchItems(string? id = null, string? name = null) |
| 34 | + public IList<CartItem> SearchCartItems(string? name = null) |
35 | 35 | {
|
36 | 36 | var itemsQueryable = _items.Values.AsQueryable();
|
37 | 37 |
|
38 |
| - if (!string.IsNullOrEmpty(id)) |
39 |
| - { |
40 |
| - itemsQueryable = itemsQueryable.Where(r => r.Id == id); |
41 |
| - } |
42 |
| - |
43 | 38 | if (!string.IsNullOrEmpty(name))
|
44 | 39 | {
|
45 | 40 | itemsQueryable = itemsQueryable.Where(r => r.Name == name);
|
|
0 commit comments