Skip to content

Commit 6d29c3a

Browse files
committed
Draft Web API design
1 parent bdc7de7 commit 6d29c3a

File tree

7 files changed

+632
-15
lines changed

7 files changed

+632
-15
lines changed

FashionStore.sln

+3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationCoreLegacy", "sr
3333
EndProject
3434
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "design", "design", "{B6FB1121-D255-47D9-84E3-017756A5BAD6}"
3535
ProjectSection(SolutionItems) = preProject
36+
design\DDD_new.uml = design\DDD_new.uml
3637
design\DDD_old.uml = design\DDD_old.uml
3738
design\DDD_old_Main.png = design\DDD_old_Main.png
3839
design\DDD_old_Sales.png = design\DDD_old_Sales.png
40+
design\WebAPI_inventory.txt = design\WebAPI_inventory.txt
41+
design\WebAPI_sales.txt = design\WebAPI_sales.txt
3942
EndProjectSection
4043
EndProject
4144
Global

design/DDD_new.uml

+373
Large diffs are not rendered by default.

design/WebAPI_inventory.txt

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
I. Viewing list of Stores (and selecting the "current" one at the UI side).
2+
3+
GET /api/inventory/stores - list of all active stores (ordered by ordinal number)
4+
/api/inventory/stores/show/all - also include inactive ones (ordered by ordinal number)
5+
6+
7+
8+
II. Searching for Products with an appropriate name.
9+
10+
GET /api/inventory/find-products/<name-beginning>/at-store/<store-id> - list all Products at a given store; search by beginning of the name (order by name)
11+
example: /api/inventory/find-products/name%2012/at-store/2
12+
[
13+
{
14+
"name": "shirt 1234",
15+
"purchasePrice": 14.0,
16+
"retailPrice": 16.0,
17+
"inStock": 1
18+
},
19+
{
20+
"name": "shirt 1246",
21+
"purchasePrice": 14.5,
22+
"retailPrice": 17.0,
23+
"inStock": 3
24+
}
25+
]
26+
27+
28+
29+
III. Getting Product IDs and purchase prices for one exact name.
30+
31+
GET /api/inventory/product-ids-for/<name>/at-store/<store-id>
32+
example: /api/inventory/product-ids-for/shirt%201234/at-store/2
33+
[
34+
{
35+
"id": 34562,
36+
"purchasePrice": 13.5
37+
},
38+
{
39+
"id": 954560,
40+
"purchasePrice": 14.0
41+
}
42+
]
43+
44+
45+
46+
IV. Getting Product details with stocks at a given Store.
47+
48+
GET /api/inventory/products/<id>/at-store/<store-id>
49+
example: /api/inventory/products/1080/at-store/3
50+
{
51+
"id": 1080,
52+
"name": "suit 56",
53+
"sizeChartId": 3,
54+
"purchasePrice": 20.0,
55+
"retailPrice": 26.0,
56+
"modified": "2020-12-25T17:25:00",
57+
"stocks": [
58+
[0, 0, 0, 0, 0, 1, 0, 3],
59+
[0, 0, 0, 0, 0, 0, 0, 0],
60+
[0, 0, 0, 0, 0, 0, 0, 0],
61+
[0, 0, 0, 0, 0, 0, 0, 0],
62+
[0, 0, 0, 4, 0, 0, 0, 0],
63+
[0, 0, 0, 0, 0, 0, 0, 0],
64+
[0, 0, 0, 0, 0, 2, 0, 0],
65+
[0, 0, 0, 0, 0, 0, 0, 0],
66+
[0, 0, 0, 0, 0, 0, 0, 0],
67+
[0, 0, 0, 0, 0, 0, 0, 0]
68+
]
69+
}
70+
71+
72+
73+
V. Getting a Size chart.
74+
75+
GET /api/inventory/size-charts/ - list all existing IDs
76+
GET /api/inventory/size-charts/<id> - get details of the specified size chart
77+
example: /api/inventory/size-charts/4
78+
{
79+
"name": "shirt"
80+
"cellsX": "164/170,170/176,176,176/182,184,182/188,188/194,Defective (0)",
81+
"cellsY": "36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53"
82+
}
83+
84+
85+
86+
VI. Save Product details: retail price and/or stocks (the latter one - at a given Store).
87+
88+
6.1) Create a new Product.
89+
90+
POST /api/inventory/products/
91+
example: /api/inventory/products/
92+
{
93+
"name": "suit 1342",
94+
"sizeChartId": 2,
95+
"purchasePrice": 14.0,
96+
"retailPrice": 19.99
97+
}
98+
will be returned: id of the new Product
99+
100+
Note: "sizeChartId" may (and should) be omitted if we create a variant of the existing Product
101+
with a new purchase price.
102+
103+
6.2) Update Product retail price.
104+
105+
PUT /api/inventory/products/<id>
106+
example: /api/inventory/products/6892
107+
{
108+
"retailPrice": 21.99
109+
}
110+
111+
6.3) Set/update Product stocks for the given Store.
112+
113+
PUT /api/inventory/products/<id>/at-store/<store-id>
114+
example: /api/inventory/products/567/at-store/3
115+
{
116+
"stocks": [
117+
[0, 0, 0, 0, 0, 1, 0, 3],
118+
[0, 0, 0, 0, 0, 0, 0, 0],
119+
[0, 0, 0, 0, 0, 0, 0, 0],
120+
[0, 0, 0, 0, 0, 0, 0, 0],
121+
[0, 0, 0, 4, 0, 0, 0, 0],
122+
[0, 0, 0, 0, 0, 0, 0, 0],
123+
[0, 0, 0, 0, 0, 2, 0, 0],
124+
[0, 0, 0, 0, 0, 0, 0, 0],
125+
[0, 0, 0, 0, 0, 0, 0, 0],
126+
[0, 0, 0, 0, 0, 0, 0, 0]
127+
]
128+
}
129+
130+
131+
132+
VII. Remove all Product stocks from the Store.
133+
134+
DELETE /api/inventory/products/<id>/from-store/<store-id>
135+
136+
Note: If, after removing stocks at the given Store, there will not be any stock of
137+
this Product at other Stores, the Product itself will be removed from the database too.
138+
139+
140+
141+
VIII. Move Product stocks from one Store to another.
142+
143+
POST /api/inventory/move/<product-id>
144+
params (with example values):
145+
{
146+
"sourceStoreId": 2,
147+
"destinationStoreId": 1,
148+
"cellX": "167",
149+
"cellY": "60",
150+
"units": 1
151+
}
152+
153+
This method is atomic and non-idempotent.
154+
155+
156+
157+
IV. Inventory report.
158+
159+
GET /api/inventory/report
160+
Optional URL parameters:
161+
at-store/<store-id> - limit report by the store (otherwise, all stores will be included)
162+
product-name-begins/<product-name-beginning> - limit by first letters in the Product name
163+
show-purchase-prices/<true-or-false>
164+
show-retail-prices/<true-or-false>
165+
show-stock-prices/<true-or-false> - show the overall purchase cost of all those Products in stock
166+
detail-sizes/<true-or-false> - show detailed stock by sizes
167+
168+
169+
170+
171+
брюки 125580/3 16 06 20

design/WebAPI_sales.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
I. Sell a Product.
2+
3+
POST /api/sales/sell/<product-id>
4+
params (with example values):
5+
{
6+
"storeId": 2,
7+
"cellX": "167",
8+
"cellY": "60",
9+
"unitPrice": 20.0,
10+
"units": 2,
11+
"paidByCard": 18.0,
12+
"paidInCash": 2.0
13+
}
14+
15+
16+
17+
II. Product return.
18+
19+
POST /api/sales/return/<product-id>
20+
params (with example values):
21+
{
22+
"storeId": 2,
23+
"cellX": "167",
24+
"cellY": "60",
25+
"unitPrice": 20.0,
26+
"units": 2,
27+
"returnedInCash": 20.0
28+
}
29+
30+
31+
32+
III. View sales register.
33+
34+
GET /api/sales/register/store/<id>
35+
Optional URL params:
36+
first-date/<first-date> - limit list by the minimum date (time part is ignored)
37+
last-date/<last-date> - limit list by the maximum date (time part is ignored; including sales during this last day)
38+
paid-by/<means> - where <means> is either "cash" or "card"; otherwise all means are included
39+
40+
example (get sales for a single day, paid by a credit card):
41+
/api/sales/register/store/2/first-date/2020-11-02/last-date/2020-11-02/paid-by/card
+19-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace ApplicationCore.Entities
1+
namespace ApplicationCore.Entities
62
{
3+
/// <summary>
4+
/// Two-dimensional size chart
5+
/// </summary>
6+
/// <remarks>
7+
/// The dress SKU can use either both dimensions (ex.: Size + Height of suit) or only
8+
/// one of them (ex.: S, M, L, XL). In the latter case, the first size axis (X) will
9+
/// be ignored. If SKU has no size (ex.: tie), it will use the one-cell fictitious size
10+
/// chart.
11+
/// </remarks>
712
public class SizeChart
813
{
14+
/// <summary>
15+
/// Id
16+
/// </summary>
917
public int Id { get; set; }
1018

19+
/// <summary>
20+
/// Comma-separated names of sizes on the X (first) axis
21+
/// </summary>
1122
public string CellsX { get; set; } = string.Empty;
1223

24+
/// <summary>
25+
/// Comma-separated names of sizes on the Y (second) axis
26+
/// </summary>
1327
public string CellsY { get; set; } = string.Empty;
1428
}
1529
}

src/ApplicationCore/Entities/Sku.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class Sku
2626
public SizeChart SizeChart { get; set; } = default!;
2727

2828
/// <summary>
29-
/// Purchasing cost
29+
/// Purchase price
3030
/// </summary>
31-
public decimal PurchasingCost { get; set; }
31+
public decimal PurchasePrice { get; set; }
3232

3333
/// <summary>
34-
/// Price
34+
/// Retail Price
3535
/// </summary>
36-
public decimal Price { get; set; }
36+
public decimal RetailPrice { get; set; }
3737

3838
/// <summary>
3939
/// Time of the last change

src/ApplicationCore/Entities/Store.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace ApplicationCore.Entities
1+
namespace ApplicationCore.Entities
62
{
3+
/// <summary>
4+
/// Fashion store
5+
/// </summary>
6+
/// <remarks>
7+
/// This could be a dress or boot shop, warehouse, or something, which
8+
/// can store and/or sell goods.
9+
/// </remarks>
710
public class Store
811
{
12+
/// <summary>
13+
/// Id
14+
/// </summary>
915
public int Id { get; set; }
1016

17+
/// <summary>
18+
/// Name
19+
/// </summary>
1120
public string Name { get; set; } = string.Empty;
1221

22+
/// <summary>
23+
/// Ordinal number in lists, reports, etc.
24+
/// </summary>
1325
public int OrdinalNumber { get; set; }
1426

15-
public bool IsDeleted { get; set; }
27+
/// <summary>
28+
/// Is the store functioning
29+
/// </summary>
30+
public bool IsActive { get; set; }
1631
}
1732
}

0 commit comments

Comments
 (0)