@@ -16,178 +16,113 @@ docker build -t factory:local .
1616Once you have an image built, run it like
1717
1818``` sh
19- docker run --rm --name factory --network=host - p 8000:8000 factory:local
19+ docker run --rm --name factory -p 8000:8000 factory:local
2020```
2121
2222This snippet is intended just for testing the app, it is usually not a good
2323idea to run any containers like that in production.
2424
2525## Testing it
2626
27- In another terminal window simple ` curl ` can be used to test the application, e.g.
27+ By default Docker container would probably start in ` bridge ` network mode (that
28+ depends on your configuration), to find its IP address open another terminal and
29+ run something like.
30+
31+ ``` sh
32+ export FACTORY_IP_ADDRESS=$( docker inspect factory | jq -r ' .[].NetworkSettings.IPAddress' )
33+ ```
34+
35+ This should give you an important information about the IP of the container. And
36+ that will be available as the ` FACTORY_IP_ADDRESS ` environment variable. Now with
37+ that variable available (so in the same terminal window), you can run some ` curl `
38+ commands to test the application.
39+
40+ Note: If your Docker environment blocks direct access to the containers, you
41+ could run each ` curl ` command in a container. The following code snippets would
42+ still be relavant if you created an alias, e.g.
43+
44+ ``` sh
45+ alias curl=' docker run --rm curlimages/curl'
46+ ```
2847
2948### Creating new materials (oxygen, hydrogen and sulphur)
3049``` sh
31- curl -X POST -H " Content-Type: application/json" \
50+ curl -s - X POST -H " Content-Type: application/json" \
3251 -d ' {"name": "Oxygen", "quantity_unit": "mole"}' \
33- http://localhost :8000/materials/
52+ http://${FACTORY_IP_ADDRESS} :8000/materials/
3453
35- curl -X POST -H " Content-Type: application/json" \
54+ curl -s - X POST -H " Content-Type: application/json" \
3655 -d ' {"name": "Hydrogen", "quantity_unit": "mole"}' \
37- http://localhost :8000/materials/
56+ http://${FACTORY_IP_ADDRESS} :8000/materials/
3857
39- curl -X POST -H " Content-Type: application/json" \
58+ curl -s - X POST -H " Content-Type: application/json" \
4059 -d ' {"name": "Sulphur", "quantity_unit": "mole"}' \
41- http://localhost :8000/materials/
60+ http://${FACTORY_IP_ADDRESS} :8000/materials/
4261```
4362
4463### Listing materials
4564``` sh
46- curl -s http://localhost:8000/materials/ | jq
47- [
48- {
49- " name" : " Oxygen" ,
50- " slug" : " oxygen" ,
51- " quantity_unit" : " mole" ,
52- " id" : " 699139c4-eb11-4815-9021-2c8f66b38d5f"
53- },
54- {
55- " name" : " Hydrogen" ,
56- " slug" : " hydrogen" ,
57- " quantity_unit" : " mole" ,
58- " id" : " c18605cd-3e1e-4898-8192-1da5662bc30a"
59- },
60- {
61- " name" : " Sulphur" ,
62- " slug" : " sulphur" ,
63- " quantity_unit" : " mole" ,
64- " id" : " f49a9fff-8345-41cb-934f-f75adc3161b5"
65- }
66- ]
65+ curl -s http://${FACTORY_IP_ADDRESS} :8000/materials/ | jq
6766```
6867
6968### Updating a material
7069``` sh
71- curl -X PATCH -H " Content-Type: application/json" \
70+ curl -s - X PATCH -H " Content-Type: application/json" \
7271 -d ' {"quantity_unit": "µg"}' \
73- http://localhost :8000/materials/sulphur
72+ http://${FACTORY_IP_ADDRESS} :8000/materials/sulphur
7473```
7574
7675### Fetching information about a single material
7776``` sh
78- curl -s http://localhost:8000/materials/sulphur | jq
79- {
80- " name" : " Sulphur" ,
81- " slug" : " sulphur" ,
82- " quantity_unit" : " µg" ,
83- " id" : " f49a9fff-8345-41cb-934f-f75adc3161b5" ,
84- " created_at" : " 2025-06-17T07:25:13" ,
85- " boms" : [],
86- " stock" : [],
87- " products" : []
88- }
77+ curl -s http://${FACTORY_IP_ADDRESS} :8000/materials/sulphur | jq
8978```
9079
9180### Removing a material
9281``` sh
93- curl -X DELETE http://localhost :8000/materials/sulphur
82+ curl -s - X DELETE http://${FACTORY_IP_ADDRESS} :8000/materials/sulphur
9483```
9584
9685### Creating a warehouse
9786``` sh
98- curl -X POST -H " Content-Type: application/json" \
87+ curl -s - X POST -H " Content-Type: application/json" \
9988 -d ' {"name": "Chemicals-1", "location": "Wien", "max_capacity": 1000000}' \
100- http://localhost :8000/warehouses/
89+ http://${FACTORY_IP_ADDRESS} :8000/warehouses/
10190```
10291
10392other operations look just like operations on materials, e.g. fetching
10493information about a single warehouse would be
10594
10695``` sh
107- curl -s http://localhost:8000/warehouses/chemicals-1 | jq
108- {
109- " name" : " Chemicals-1" ,
110- " slug" : " chemicals-1" ,
111- " location" : " Wien" ,
112- " capacity" : 1000000,
113- " max_capacity" : 1000000,
114- " id" : " ad02b895-ea98-4bd5-a889-7869f3e521fb" ,
115- " created_at" : " 2025-06-17T07:28:47" ,
116- " stock" : []
117- }
96+ curl -s http://${FACTORY_IP_ADDRESS} :8000/warehouses/chemicals-1 | jq
11897```
11998
12099### Delivery process
121100``` sh
122- curl -X POST -H " Content-Type: application/json" \
101+ curl -s - X POST -H " Content-Type: application/json" \
123102 -d ' {"warehouse_id": "ad02b895-ea98-4bd5-a889-7869f3e521fb", \
124- "positions": [{"material_id": "699139c4-eb11-4815-9021-2c8f66b38d5f",
103+ "positions": [{"material_id": "699139c4-eb11-4815-9021-2c8f66b38d5f", \
125104 "quantity": 10}, {"material_id": "c18605cd-3e1e-4898-8192-1da5662bc30a", \
126105 "quantity": 20}]}' \
127- http://localhost :8000/delivery/
106+ http://${FACTORY_IP_ADDRESS} :8000/delivery/
128107```
129108
109+ Note: The ` warehouse_id ` and ` material_id ` s values (UUIDv4) are quoted above
110+ only by way of example, they are pseudo-random values so will be different
111+ in each environment.
112+
130113Delivered materials stored in a warehouse will diminish its capacity, so after
131114testing a delivery something will change, e.g.
132115
133116``` sh
134- curl -s http://localhost:8000/warehouses/chemicals-1 | jq
135- {
136- " name" : " Chemicals-1" ,
137- " slug" : " chemicals-1" ,
138- " location" : " Wien" ,
139- " capacity" : 999970,
140- " max_capacity" : 1000000,
141- " id" : " ad02b895-ea98-4bd5-a889-7869f3e521fb" ,
142- " created_at" : " 2025-06-17T07:28:47" ,
143- " stock" : [
144- {
145- " id" : " d9b1f90d-8559-46e5-b6c3-546d16666aa0" ,
146- " quantity" : 10,
147- " material_name" : " Oxygen" ,
148- " material_slug" : " oxygen"
149- },
150- {
151- " id" : " 31ed7603-43f2-41a9-a817-10ce54fbdf29" ,
152- " quantity" : 20,
153- " material_name" : " Hydrogen" ,
154- " material_slug" : " hydrogen"
155- }
156- ]
157- }
117+ curl -s http://${FACTORY_IP_ADDRESS} :8000/warehouses/chemicals-1 | jq
158118```
159119
160120``` sh
161- curl -s http://localhost:8000/materials/oxygen | jq
162- {
163- " name" : " Oxygen" ,
164- " slug" : " oxygen" ,
165- " quantity_unit" : " mole" ,
166- " id" : " 699139c4-eb11-4815-9021-2c8f66b38d5f" ,
167- " created_at" : " 2025-06-17T07:24:50" ,
168- " boms" : [],
169- " stock" : [
170- {
171- " id" : " d9b1f90d-8559-46e5-b6c3-546d16666aa0" ,
172- " warehouse_id" : " ad02b895-ea98-4bd5-a889-7869f3e521fb" ,
173- " quantity" : 10,
174- " warehouse_name" : " Chemicals-1" ,
175- " warehouse_slug" : " chemicals-1"
176- },
177- {
178- " id" : " ca6bd72a-48ec-4a29-a3d9-545d09f8b7e9" ,
179- " warehouse_id" : " daae3903-dd42-473b-a160-0a838ccf65f0" ,
180- " quantity" : 10000,
181- " warehouse_name" : " Chemicals-2" ,
182- " warehouse_slug" : " chemicals-2"
183- }
184- ],
185- " products" : []
186- }
121+ curl -s http://${FACTORY_IP_ADDRESS} :8000/materials/oxygen | jq
187122```
188123
189124### Further testing
190125
191126There are other endpoints, not described in this short README file. Feel
192127free to investigate them on your own by browsing files in the ` routers/ `
193- directory.
128+ directory.
0 commit comments