├── .gitignore
├── LICENSE
├── README.md
├── client
├── microapiclient
│ ├── __init__.py
│ ├── __main__.py
│ ├── customer.py
│ ├── manager.py
│ ├── order.py
│ ├── price.py
│ └── product.py
├── orders.csv
├── requirements.txt
└── setup.py
├── customer-service
├── Dockerfile
├── app
│ ├── api
│ │ ├── customers.py
│ │ ├── db.py
│ │ ├── db_manager.py
│ │ └── models.py
│ └── main.py
└── requirements.txt
├── docker-compose.yml
├── img
├── customers.gif
├── install.gif
├── logo.png
├── orders.png
├── prices.png
└── products.png
├── nginx_config.conf
├── order-service
├── Dockerfile
├── app
│ ├── api
│ │ ├── db.py
│ │ ├── db_manager.py
│ │ ├── models.py
│ │ └── orders.py
│ └── main.py
└── requirements.txt
├── orders.csv
├── price-service
├── Dockerfile
├── app
│ ├── api
│ │ ├── models.py
│ │ └── prices.py
│ └── main.py
└── requirements.txt
└── product-service
├── Dockerfile
├── app
├── api
│ ├── db.py
│ ├── db_manager.py
│ ├── models.py
│ └── products.py
└── main.py
└── requirements.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ## :green_square: Getting Started
24 |
25 | [MicroAPI](https://github.com/zakharb/microapi) is fully separates API in Async mode based on [Microservices](https://en.wikipedia.org/wiki/Microservices)
26 |
27 | For CRUD operations is used `Customer - Product - Price - Order` model
28 |
29 | > The `Customer` buys a `Product` with a different `Price` and receives an `Order`
30 | > The `Price` is calculated including taxes/discounts depending on the type of customer/
31 |
32 | Each part is work like Microservice
33 | The Microservice runs in separate Docker container
34 |
35 | Microservice has its own Database
36 | Database can be switch from Postgres to MongoDB or other
37 |
38 |
39 | ### Requirements
40 |
41 | 
42 | 
43 | 
44 | 
45 |
46 | ### Installing
47 |
48 | Clone the project
49 |
50 | ```
51 | git clone git@github.com:zakharb/microapi.git
52 | cd microapi
53 | ```
54 |
55 | Start docker-compose
56 |
57 | ```
58 | docker-compose up -d
59 | ```
60 |
61 |
62 |
63 |
64 |
65 | ## :green_square: Usage
66 |
67 | ### Customers
68 | Get, put, update, delete `Customers` via API [Customers](http://localhost:8080/api/v1/customers/docs)
69 |
70 |
71 |
72 |
73 | ### Products
74 | Get, put, update, delete `Products` via API [Products](http://localhost:8080/api/v1/products/docs)
75 |
76 |
77 |
78 |
79 | ### Prices
80 | Get `Prices` via API [Prices](http://localhost:8080/api/v1/prices/docs)
81 |
82 |
83 |
84 |
85 | ### Orders
86 | Get `Orders` via API [Orders](http://localhost:8080/api/v1/orders/docs)
87 |
88 |
89 |
90 |
91 |
92 | ## :green_square: Configuration
93 | To solve problem with performance each Service run in container
94 | [Uvicorn]((https://www.uvicorn.org/)) work as ASGI server and connect to one piece with [Nginx](https://www.nginx.com/)
95 | Main configuration is `docker-compose.yml`
96 |
97 | - every service located in separate directory `name-service`
98 | - use `Dockerfile` to change docker installation settings
99 | - folder `app` contain FastAPI application
100 | - all services connected to one piece in `docker-compose.yml`
101 | - example of service + DB containers (change `--workers XX` to increase multiprocessing)
102 |
103 | ### Examples
104 | `Customer` service
105 | ```
106 | customer_service:
107 | build: ./customer-service
108 | command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
109 | #command: gunicorn main:app --workers 4 --worker-class --host 0.0.0.0 --port 8000
110 | volumes:
111 | - ./customer-service/:/app/
112 | ports:
113 | - 8001:8000
114 | environment:
115 | - DATABASE_URI=postgresql://customer_db_username:customer_db_password@customer_db/customer_db_dev
116 | depends_on:
117 | - customer_db
118 | logging:
119 | driver: none
120 |
121 | customer_db:
122 | image: postgres:latest
123 | volumes:
124 | - postgres_data_customer:/var/lib/postgresql/data/
125 | environment:
126 | - POSTGRES_USER=customer_db_username
127 | - POSTGRES_PASSWORD=customer_db_password
128 | - POSTGRES_DB=customer_db_dev
129 | logging:
130 | driver: none
131 | ```
132 |
133 |
134 | ## :green_square: Client
135 | There is client for work with Microservices
136 | `Microapiclient` is used for generating data and testing
137 |
138 | It is located in folder `client`
139 |
140 | ### Install
141 | ```
142 | cd client
143 | python3 -m venv venv
144 | source venv/bin/activate
145 | python -m pip install -e .
146 | ```
147 |
148 | ### Run
149 | ```
150 | cd client
151 | source venv/bin/activate
152 | python -m microapiclient
153 |
154 | __ __ _ _____ _____ _______
155 | (__)_(__) (_) _ (_____) (_____)(_______)
156 | (_) (_) (_) _ ___ (_)__ ___ (_)___(_)(_)__(_) (_)
157 | (_) (_) (_)(_) _(___)(____)(___) (_______)(_____) (_)
158 | (_) (_)(_)(_)___ (_) (_)_(_)(_) (_)(_) __(_)__
159 | (_) (_)(_) (____)(_) (___) (_) (_)(_) (_______)
160 |
161 | usage: __main__.py [-h]
162 | {getcustomer,postcustomer,getproduct,postproduct,getprice,postorder,postorders,generateorder}
163 | ...
164 |
165 | positional arguments:
166 | {getcustomer,postcustomer,getproduct,postproduct,getprice,postorder,postorders,generateorder}
167 | getcustomer Get customer from DB
168 | postcustomer Post new customer into DB
169 | getproduct Get product by name from DB
170 | postproduct Post new product into DB
171 | getprice Get price_net and price_gross
172 | postorder Post order into DB
173 | postorders Bulk write orders into DB
174 | generateorder Generate order into CSV file
175 |
176 | optional arguments:
177 | -h, --help show this help message and exit
178 |
179 | ```
180 |
181 | ### Examples
182 |
183 | - Generate Customers
184 | ```
185 | python -m microapiclient postcustomer --customer-count 50
186 | ```
187 | - Generate Products
188 | ```
189 | python -m microapiclient postproduct --product-count 50
190 | ```
191 | - Generate Orders to file
192 | ```
193 | python -m microapiclient generateorder --order-count 1000 --task-count 32
194 | ```
195 | - Bulk write Orders from file to DB
196 | ```
197 | python -m microapiclient postorders --order-file orders.csv --task-count 32
198 | ```
199 | - View logs in `client.log`
200 | ```
201 | cat client.log | more
202 | ```
203 |
204 | ## :green_square: Deployment
205 |
206 | Edit `Dockerfile` for each Microservice and deploy container
207 |
208 | ## :green_square: Versioning
209 |
210 | Using [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/zakharb/microapi/tags).
211 |
212 | ## :green_square: Authors
213 |
214 | * **Zakhar Bengart** - *Initial work* - [Ze](https://github.com/zakharb)
215 |
216 | See also the list of [contributors](https://github.com/zakharb/microapi/contributors) who participated in this project.
217 |
218 | ## :green_square: License
219 |
220 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation - see the [LICENSE](LICENSE) file for details
221 |
--------------------------------------------------------------------------------
/client/microapiclient/__init__.py:
--------------------------------------------------------------------------------
1 | from .customer import Customer
2 | from .product import Product
3 | from .price import Price
4 | from .order import Order
5 | from .manager import post_orders, generate_orders
--------------------------------------------------------------------------------
/client/microapiclient/__main__.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Client to work with Micro API
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Client is used to manipulate with MicroAPI
24 | You can do CRUD operations with services
25 | It use Modules to every service and Manager wtih actions
26 | Work in Async mode with customized number of tasks
27 | """
28 |
29 | import json
30 | import asyncio
31 | import logging
32 | import argparse
33 | from datetime import datetime
34 |
35 | from random import randrange, choice
36 | from logging.handlers import RotatingFileHandler
37 | from microapiclient import Customer, Product, Price, Order
38 | from microapiclient import post_orders, generate_orders
39 |
40 | def print_logo():
41 | print(' __ __ _ _____ _____ _______ \n'\
42 | ' (__)_(__) (_) _ (_____) (_____)(_______)\n'\
43 | '(_) (_) (_) _ ___ (_)__ ___ (_)___(_)(_)__(_) (_) \n'\
44 | '(_) (_) (_)(_) _(___)(____)(___) (_______)(_____) (_) \n'\
45 | '(_) (_)(_)(_)___ (_) (_)_(_)(_) (_)(_) __(_)__ \n'\
46 | '(_) (_)(_) (____)(_) (___) (_) (_)(_) (_______)\n')
47 |
48 | async def run_main(args):
49 | """
50 | Main function starting all tasks denends on args
51 | """
52 | if args.command == 'getcustomer':
53 | # get cutomer by ID from customer-service
54 | print('\n[*] Getting Customer by ID\n----------------')
55 | customer = Customer()
56 | data = await customer.get_customer(args.cid)
57 | print(data)
58 | elif args.command == 'postcustomer':
59 | # post random geretated Customers to DB
60 | print('\n[*] Posting new Customers\n----------------')
61 | customer = Customer()
62 | i = 0
63 | while args.customer_count > 0:
64 | data = {
65 | 'name': 'Customer' + str(randrange(1000)),
66 | 'customer_class': choice(['Enduser', 'Reseller', 'ResellerHighVolume']),
67 | 'vat_percentage': str(randrange(30)),
68 | 'status': choice(['Active', 'Deleted', 'Active', 'Active']),
69 | }
70 | response = await customer.post_customer(data)
71 | print(response)
72 | args.customer_count -= 1
73 | await customer.close_session()
74 | elif args.command == 'getproduct':
75 | # get products by Name and Status from product-service
76 | print('\n[*] Getting Product by name\n----------------')
77 | product = Product()
78 | parameters = ''
79 | if args.pname and args.pstatus:
80 | parameters += '?name=' + args.pname + '&' + 'status=' + args.pstatus
81 | elif args.pname:
82 | parameters += '?name=' + args.pname
83 | elif args.pstatus:
84 | parameters += '?status=' + args.pstatus
85 | data = await product.get_products(parameters)
86 | print(data)
87 | await product.close_session()
88 | elif args.command == 'postproduct':
89 | # post random geretated Products to DB
90 | print('\n[*] Posting new Products\n----------------')
91 | product = Product()
92 | i = 0
93 | while args.product_count > 0:
94 | data = {
95 | 'name': 'Product' + str(randrange(100)),
96 | 'price_net': str(randrange(300)),
97 | 'status': choice(['Active', 'Inactive', 'Active', 'Active']),
98 | }
99 | response = await product.post_product(data)
100 | print(response)
101 | args.product_count -= 1
102 | await product.close_session()
103 | elif args.command == 'getprice':
104 | # calculate Price from price-service
105 | print('\n[*] Getting Price\n----------------')
106 | price = Price()
107 | parameters = ('?quantity=' + args.quantity +
108 | '&price_net=' + args.price_net +
109 | '&vat_percentage=' + args.vat_percentage +
110 | '&customer_class=' + args.customer_class)
111 | data = await price.get_price(parameters)
112 | print(data)
113 | await price.close_session()
114 | elif args.command == 'postorder':
115 | # post order with order-service
116 | print('\n[*] Posting Order\n----------------')
117 | order = Order()
118 | data = {
119 | 'order_no': args.order_no,
120 | 'customer_id': args.customer_id,
121 | 'product_id': args.product_id,
122 | 'quantity': args.quantity,
123 | 'price_net': args.price_net,
124 | 'price_gross': args.price_gross,
125 | }
126 | response = await order.post_order(data)
127 | print(response)
128 | await order.close_session()
129 | elif args.command == 'postorders':
130 | # bulk write orders to DB from CSV file
131 | await post_orders(args.order_file, args.task_count)
132 | elif args.command == 'generateorder':
133 | # generate CSV file with orders
134 | await generate_orders(args.order_count, args.task_count)
135 | else:
136 | parser.print_help()
137 |
138 |
139 | if __name__ == "__main__":
140 | """
141 | Use modelu Argparser to build menu with submenu
142 | """
143 | print_logo()
144 | logging.basicConfig(
145 | handlers=[RotatingFileHandler('client.log', maxBytes=1000000)],
146 | level='INFO',
147 | format=' %(asctime)s %(levelname)s %(message)s')
148 | parser = argparse.ArgumentParser()
149 | subparser = parser.add_subparsers(dest='command')
150 | # args for Customer
151 | getcustomer = subparser.add_parser('getcustomer', help='Get customer from DB')
152 | getcustomer.add_argument('--cid', type=str, required=True,
153 | help='customer id')
154 | postcustomer = subparser.add_parser('postcustomer',
155 | help='Post new customer into DB')
156 | postcustomer.add_argument('--customer-count', type=int, required=True,
157 | help='how many customers to post')
158 | # args for Product
159 | getproduct = subparser.add_parser('getproduct', help='Get product by name from DB')
160 | getproduct.add_argument('--pname', type=str,
161 | help='product name')
162 | getproduct.add_argument('--pstatus', type=str,
163 | help='product status')
164 | postproduct = subparser.add_parser('postproduct',
165 | help='Post new product into DB')
166 | postproduct.add_argument('--product-count', type=int, required=True,
167 | help='how many products to post')
168 | # args for Price
169 | getprice = subparser.add_parser('getprice', help='Get price_net and price_gross')
170 | getprice.add_argument('--quantity', type=str, required=True,
171 | help='quantity of the product')
172 | getprice.add_argument('--price-net', type=str, required=True,
173 | help='price net')
174 | getprice.add_argument('--customer-class', type=str, required=True,
175 | help='customer class')
176 | getprice.add_argument('--vat-percentage', type=str, required=True,
177 | help='vat for product')
178 | # args for Order
179 | postorder = subparser.add_parser('postorder', help='Post order into DB')
180 | postorder.add_argument('--order-no', type=str, required=True,
181 | help='order number')
182 | postorder.add_argument('--customer-id', type=str, required=True,
183 | help='customer ID')
184 | postorder.add_argument('--product-id', type=str, required=True,
185 | help='product ID')
186 | postorder.add_argument('--quantity', type=str, required=True,
187 | help='amount to buy')
188 | postorder.add_argument('--price-net', type=str, required=True,
189 | help='net price')
190 | postorder.add_argument('--price-gross', type=str, required=True,
191 | help='gross price')
192 | # args for Manager actions
193 | postorders = subparser.add_parser('postorders', help='Bulk write orders into DB')
194 | postorders.add_argument('--order-file', type=str, required=True,
195 | help='file name to read orders')
196 | postorders.add_argument('--task-count', type=int, required=True,
197 | help='how many tasks to use')
198 | generateorder = subparser.add_parser('generateorder',
199 | help='Generate order into CSV file')
200 | generateorder.add_argument('--order-count', type=int, required=True,
201 | help='how many orders to save')
202 | generateorder.add_argument('--task-count', type=int, required=True,
203 | help='how many tasks to use')
204 |
205 | args = parser.parse_args()
206 | asyncio.run(run_main(args))
207 |
--------------------------------------------------------------------------------
/client/microapiclient/customer.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Module for communication with CustomerAPI
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Description:
20 |
21 | Author:
22 | Bengart Zakhar
23 |
24 | """
25 | import json
26 | import aiohttp
27 | import logging
28 | from datetime import datetime
29 |
30 |
31 | class Customer:
32 | """
33 | Class for work with CustomerAPI
34 | """
35 | def __init__(self):
36 | self.url = "http://localhost:8080/api/v1/customers/"
37 | self.session = aiohttp.ClientSession()
38 |
39 | async def get_customers(self):
40 | """
41 | Get data about all customers
42 | """
43 | try:
44 | async with self.session.get(self.url, timeout=1) as resp:
45 | if resp.status != 200:
46 | logging.error('CustomerAPI getting resp error, code: ' + str(resp.status))
47 | return
48 | return await resp.text()
49 | except Exception as e:
50 | logging.error('CustomerAPI getting data error: ' + repr(e))
51 |
52 | async def get_customer(self, customer_id):
53 | """
54 | Get data about customer by ID
55 | """
56 | try:
57 | url = self.url + customer_id + '/'
58 | async with self.session.get(url, timeout=1) as resp:
59 | if resp.status != 200:
60 | logging.error('CustomerAPI getting resp error, code: ' + str(resp.status))
61 | return '{}'
62 | return await resp.text()
63 | except Exception as e:
64 | logging.error('CustomerAPI getting data error: ' + repr(e))
65 |
66 | async def post_customer(self, data):
67 | """
68 | Post new Customer into DB
69 | """
70 | try:
71 | headers = {
72 | 'content-type': 'application/json',
73 | }
74 | pload = json.dumps(data, default=str, ensure_ascii=False)
75 | async with self.session.post(self.url, data=pload, headers=headers, timeout=1) as resp:
76 | if resp.status != 201:
77 | logging.error('CustomerAPI posting response code: ' + str(resp.status))
78 | return await resp.text()
79 | except Exception as e:
80 | logging.error('CustomerAPI posting data error: ' + repr(e))
81 |
82 | async def close_session(self):
83 | await self.session.close()
--------------------------------------------------------------------------------
/client/microapiclient/manager.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Manager to work with Micro API actions
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Manager is used to make some complex action with different services^
24 | - bulk write Orders
25 | - generate Orders to CSV file
26 |
27 | """
28 | import json
29 | import asyncio
30 | import logging
31 | from datetime import datetime
32 | from random import randrange, choice
33 |
34 | from .customer import Customer
35 | from .product import Product
36 | from .price import Price
37 | from .order import Order
38 |
39 | async def post_orders(file, task_number):
40 | """
41 | Bulk write orders to DB from CSV file
42 | """
43 | loop = asyncio.get_event_loop()
44 | time = datetime.now()
45 | with open(file, 'r') as f:
46 | raw_data = f.read().splitlines()
47 | tasks = []
48 | orders = []
49 | for data in raw_data[1:]:
50 | order = data.split(',')
51 | orders.append(order)
52 | order_count = len(orders) // task_number
53 | order_trash = len(orders) % task_number
54 | start_order = 0
55 | end_order = start_order + order_count + order_trash
56 | for i in range(task_number):
57 | print('Start task: ', i)
58 | task_order = orders[ start_order : end_order + 1]
59 | task = loop.create_task(task_post_orders(task_order))
60 | tasks.append(task)
61 | start_order = end_order
62 | end_order = start_order + order_count
63 | for task in tasks:
64 | await task
65 | print('Finished, time: ', datetime.now() - time)
66 |
67 | async def task_post_orders(data):
68 | """
69 | Simple task to write Orders to DB
70 | """
71 | customer = Customer()
72 | product = Product()
73 | price = Price()
74 | db_order = Order()
75 | orders = []
76 | for d in data:
77 | order = {}
78 | response = await customer.get_customer(d[1])
79 | if response:
80 | customer_data = json.loads(response)
81 | else:
82 | continue
83 | if customer_data['status'] == 'Deleted':
84 | logging.warning('Customer status is Deleted: ' + customer_data['name'])
85 | parameters = '?name=' + d[2]
86 | response = await product.get_products(parameters)
87 | if response:
88 | product_data = json.loads(response)
89 | else:
90 | continue
91 | if product_data:
92 | product_data = product_data[0]
93 | else:
94 | logging.error('Product is Unknown: ' + d[2])
95 | continue
96 | if product_data['status'] == 'Inactive':
97 | logging.warning('Product status is Inactive: ' + product_data['name'])
98 | parameters = ('?quantity=' + str(d[3]) +
99 | '&price_net=' + str(product_data['price_net']) +
100 | '&vat_percentage=' + str(customer_data['vat_percentage']) +
101 | '&customer_class=' + customer_data['customer_class'])
102 | response = await price.get_price(parameters)
103 | price_data = json.loads(response)
104 | if not price_data:
105 | continue
106 | order['order_no'] = d[0]
107 | order['customer_id'] = customer_data['customer_id']
108 | order['product_id'] = product_data['product_id']
109 | order['quantity'] = d[3]
110 | order['price_net'] = price_data['price_net']
111 | order['price_gross'] = price_data['price_gross']
112 | await db_order.post_order(order)
113 | await customer.close_session()
114 | await product.close_session()
115 | await price.close_session()
116 | await db_order.close_session()
117 |
118 | async def generate_orders(count, task_number):
119 | """
120 | Generate random Orders and save it to CSV file
121 | """
122 | order_count = count / task_number
123 | loop = asyncio.get_event_loop()
124 | time = datetime.now()
125 | tasks = []
126 | orders = []
127 | for i in range(task_number):
128 | print('Start task: ', i)
129 | task = loop.create_task(task_generate_orders(order_count))
130 | tasks.append(task)
131 | for task in tasks:
132 | orders += await task
133 | if orders:
134 | with open('orders.csv', 'w') as f:
135 | row = ''
136 | for data in orders[0]:
137 | row += str(data) + ','
138 | f.write(row + '\n')
139 | for order in orders:
140 | row = ''
141 | for data in order.values():
142 | row += str(data) + ','
143 | f.write(row + '\n')
144 | print('Finished, time: ', datetime.now() - time)
145 |
146 | async def task_generate_orders(order_count):
147 | """
148 | Simple task to generate Orders
149 | """
150 | i = 0
151 | customer = Customer()
152 | product = Product()
153 | price = Price()
154 | response = await customer.get_customers()
155 | count_customers = len(json.loads(response))
156 | response = await product.get_products()
157 | count_products = len(json.loads(response))
158 | orders = []
159 | while order_count > 0:
160 | order = {'order_no': randrange(100000)}
161 | response = await customer.get_customer(str(randrange(count_customers)))
162 | customer_data = json.loads(response)
163 | if not customer_data:
164 | order_count -= 1
165 | continue
166 | order['customer_id'] = customer_data['customer_id']
167 | response = await product.get_product(str(randrange(count_products)))
168 | product_data = json.loads(response)
169 | if not product_data:
170 | order_count -= 1
171 | continue
172 | order['product_name'] = product_data['name']
173 | if order_count % 10 == 0:
174 | order['product_name'] += 'unknown'
175 | order['quantity'] = str(randrange(60))
176 | orders.append(order)
177 | order_count -= 1
178 | await customer.close_session()
179 | await product.close_session()
180 | await price.close_session()
181 | return orders
182 |
--------------------------------------------------------------------------------
/client/microapiclient/order.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Module for communication with OrderAPI
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Class to work with order-service
24 |
25 | """
26 | import json
27 | import aiohttp
28 | import logging
29 | from datetime import datetime
30 |
31 |
32 | class Order:
33 | """
34 | Class for work with OrderAPI
35 | """
36 | def __init__(self):
37 | self.url = "http://localhost:8080/api/v1/orders/"
38 | self.session = aiohttp.ClientSession()
39 |
40 | async def post_order(self, data):
41 | """
42 | Post data about orders into DB
43 | """
44 | try:
45 | headers = {
46 | 'content-type': 'application/json',
47 | }
48 | pload = json.dumps(data, default=str, ensure_ascii=False)
49 | async with self.session.post(self.url, data=pload, headers=headers, timeout=1) as resp:
50 | if resp.status != 201:
51 | logging.error('OrderAPI posting order response code: ' + str(resp.status))
52 | return await resp.text()
53 | except Exception as e:
54 | logging.error('OrderAPI posting data error: ' + repr(e))
55 |
56 | async def close_session(self):
57 | await self.session.close()
--------------------------------------------------------------------------------
/client/microapiclient/price.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Module for communication with PriceAPI
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Class to work with price-service
24 |
25 |
26 | """
27 | import aiohttp
28 | import logging
29 | from datetime import datetime
30 |
31 |
32 | class Price:
33 | """
34 | Class for work with PriceAPI
35 | """
36 | def __init__(self):
37 | self.url = "http://localhost:8080/api/v1/prices/"
38 | self.session = aiohttp.ClientSession()
39 |
40 | async def get_price(self, parameters):
41 | """
42 | Get data about prices with parameters by Name or Status
43 | """
44 | try:
45 | if parameters:
46 | url = self.url + parameters
47 | async with self.session.get(url, timeout=1) as resp:
48 | if resp.status != 200:
49 | logging.error('PriceAPI getting resp error, code: ' + str(resp.status))
50 | return await resp.text()
51 | except Exception as e:
52 | logging.error('PriceAPI getting data error: ' + repr(e))
53 |
54 | async def close_session(self):
55 | await self.session.close()
--------------------------------------------------------------------------------
/client/microapiclient/product.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Module for communication with ProductAPI
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Class to work with price-service
24 |
25 | """
26 | import json
27 | import aiohttp
28 | import logging
29 | from datetime import datetime
30 |
31 |
32 | class Product:
33 | """
34 | Class for work with ProductAPI
35 | """
36 | def __init__(self):
37 | self.url = "http://localhost:8080/api/v1/products/"
38 | self.session = aiohttp.ClientSession()
39 |
40 | async def get_products(self, parameteres=None):
41 | """
42 | Get data about products with parameters by Name or Status
43 | """
44 | url = self.url
45 | if parameteres:
46 | url = self.url + parameteres
47 | try:
48 | async with self.session.get(url, timeout=1) as resp:
49 | if resp.status != 200:
50 | logging.error('ProductAPI getting resp error, code: ' + str(resp.status))
51 | return await resp.text()
52 | except Exception as e:
53 | logging.error('ProductAPI getting data error: ' + repr(e))
54 |
55 | async def get_product(self, product_id):
56 | """
57 | Get data about product by ID
58 | """
59 | try:
60 | url = self.url + product_id + '/'
61 | async with self.session.get(url, timeout=1) as resp:
62 | if resp.status != 200:
63 | logging.error('ProductAPI getting resp error, code: ' + str(resp.status))
64 | return '{}'
65 | return await resp.text()
66 | except Exception as e:
67 | logging.error('ProductAPI getting data error: ' + repr(e))
68 |
69 | async def post_product(self, data):
70 | """
71 | Post new Product into DB
72 | """
73 | try:
74 | headers = {
75 | 'content-type': 'application/json',
76 | }
77 | pload = json.dumps(data, default=str, ensure_ascii=False)
78 | async with self.session.post(self.url, data=pload, headers=headers, timeout=1) as resp:
79 | if resp.status != 201:
80 | logging.error('ProductAPI posting response code: ' + str(resp.status))
81 | return await resp.text()
82 | except Exception as e:
83 | logging.error('ProductAPI posting data error: ' + repr(e))
84 |
85 | async def close_session(self):
86 | await self.session.close()
--------------------------------------------------------------------------------
/client/requirements.txt:
--------------------------------------------------------------------------------
1 | aiohttp==3.8.1
2 | aiosignal==1.2.0
3 | async-timeout==4.0.2
4 | attrs==21.4.0
5 | charset-normalizer==2.0.12
6 | frozenlist==1.3.0
7 | idna==3.3
8 | multidict==6.0.2
9 | yarl==1.7.2
10 |
--------------------------------------------------------------------------------
/client/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import find_packages, setup
2 |
3 | with open('requirements.txt') as f:
4 | required = f.read().splitlines()
5 |
6 | setup(
7 | name='microapiclient',
8 | version='1.0.0',
9 | packages=find_packages(),
10 | include_package_data=True,
11 | zip_safe=False,
12 | install_requires=required,
13 | )
14 |
--------------------------------------------------------------------------------
/customer-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.9-slim
2 |
3 | WORKDIR /app
4 |
5 | COPY ./requirements.txt /app/requirements.txt
6 |
7 | RUN apt-get update \
8 | && apt-get install gcc -y \
9 | && apt-get clean
10 |
11 | RUN pip install -r /app/requirements.txt \
12 | && rm -rf /root/.cache/pip
13 |
14 | COPY . /app/
15 |
--------------------------------------------------------------------------------
/customer-service/app/api/customers.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Routers for customer-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Routers for operations with API
24 | """
25 |
26 | from typing import List
27 | from fastapi import APIRouter, HTTPException
28 |
29 | from app.api.models import CustomerOut, CustomerIn, CustomerUpdate
30 | from app.api import db_manager
31 |
32 | from datetime import datetime
33 | router = APIRouter()
34 |
35 | @router.post('/', response_model=CustomerOut, status_code=201)
36 | async def create_customer(payload: CustomerIn):
37 | customer_id = await db_manager.add_customer(payload)
38 | response = {
39 | 'customer_id': customer_id,
40 | **payload.dict()
41 | }
42 | return response
43 |
44 | @router.get('/', response_model=List[CustomerOut])
45 | async def get_customers():
46 | return await db_manager.get_all_customers()
47 |
48 | @router.get('/{customer_id}/', response_model=CustomerOut)
49 | async def get_customer(customer_id: int):
50 | customer = await db_manager.get_customer(customer_id)
51 | if not customer:
52 | raise HTTPException(status_code=404, detail="Customer not found")
53 | return customer
54 |
55 | @router.put('/{customer_id}/', response_model=CustomerOut)
56 | async def update_customer(customer_idid: int, payload: CustomerUpdate):
57 | customer = await db_manager.get_customer(customer_id)
58 | if not customer:
59 | raise HTTPException(status_code=404, detail="Customer not found")
60 |
61 | update_data = payload.dict(exclude_unset=True)
62 | customer_in_db = CustomerIn(**customer)
63 | updated_customer = customer_in_db.copy(update=update_data)
64 | return await db_manager.update_customer(customer_id, updated_customer)
65 |
66 | @router.delete('/{customer_id}', response_model=None)
67 | async def delete_customer(customer_id: int):
68 | customer = await db_manager.get_customer(customer_id)
69 | if not customer:
70 | raise HTTPException(status_code=404, detail="Customer not found")
71 | return await db_manager.delete_customer(customer_id)
72 |
--------------------------------------------------------------------------------
/customer-service/app/api/db.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | DB module for customer-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Make engine, connection to DB and tables
24 | """
25 |
26 | import os
27 | import sqlalchemy
28 | from databases import Database
29 |
30 | DATABASE_URI = os.getenv('DATABASE_URI')
31 |
32 | engine = sqlalchemy.create_engine(DATABASE_URI)
33 | metadata = sqlalchemy.MetaData()
34 |
35 | customers = sqlalchemy.Table(
36 | 'customers',
37 | metadata,
38 | sqlalchemy.Column('customer_id', sqlalchemy.BigInteger, primary_key=True),
39 | sqlalchemy.Column('name', sqlalchemy.String(50)),
40 | sqlalchemy.Column('customer_class', sqlalchemy.String(250)),
41 | sqlalchemy.Column('vat_percentage', sqlalchemy.Integer),
42 | sqlalchemy.Column('status', sqlalchemy.String(250)),
43 | )
44 |
45 | database = Database(DATABASE_URI)
--------------------------------------------------------------------------------
/customer-service/app/api/db_manager.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Manager to work with DB at customer-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | CRUD operations to work with DB
24 | """
25 |
26 | from app.api.models import CustomerIn, CustomerOut, CustomerUpdate
27 | from app.api.db import customers, database
28 |
29 |
30 | async def add_customer(payload: CustomerIn):
31 | query = customers.insert().values(**payload.dict())
32 | return await database.execute(query=query)
33 |
34 | async def get_all_customers():
35 | query = customers.select()
36 | return await database.fetch_all(query=query)
37 |
38 | async def get_customer(customer_id):
39 | query = customers.select(customers.c.customer_id==customer_id)
40 | return await database.fetch_one(query=query)
41 |
42 | async def delete_customer(customer_id: int):
43 | query = customers.delete().where(customers.c.customer_id==customer_id)
44 | return await database.execute(query=query)
45 |
46 | async def update_customer(customer_id: int, payload: CustomerIn):
47 | query = (
48 | customers
49 | .update()
50 | .where(customers.c.customer_id == customer_id)
51 | .values(**payload.dict())
52 | )
53 | return await database.execute(query=query)
--------------------------------------------------------------------------------
/customer-service/app/api/models.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Models to customer-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Pydantic models to make docs and check types
24 | """
25 |
26 | from pydantic import BaseModel, constr
27 | from typing import List, Optional
28 | from enum import Enum
29 |
30 | class CustomerClassEnum(str, Enum):
31 | enduser = 'Enduser'
32 | reseller = 'Reseller'
33 | resseler_high_volume = 'ResellerHighVolume'
34 |
35 |
36 | class Status(str, Enum):
37 | active = 'Active'
38 | deleted = 'Deleted'
39 |
40 |
41 | class CustomerIn(BaseModel):
42 | name: str
43 | customer_class: CustomerClassEnum
44 | vat_percentage: int
45 | status: Status
46 |
47 |
48 | class CustomerOut(CustomerIn):
49 | customer_id: int
50 |
51 |
52 | class CustomerUpdate(CustomerIn):
53 | name: Optional[str] = None
54 | customer_class: Optional[CustomerClassEnum] = None
55 | vat_percentage: Optional[int] = None
56 | status: Optional[Status] = None
57 |
--------------------------------------------------------------------------------
/customer-service/app/main.py:
--------------------------------------------------------------------------------
1 | from fastapi import FastAPI
2 | from app.api.customers import router as customers_router
3 | from app.api.db import metadata, database, engine
4 |
5 | metadata.create_all(engine)
6 |
7 | app = FastAPI(openapi_url="/api/v1/customers/openapi.json",
8 | docs_url="/api/v1/customers/docs")
9 |
10 | @app.on_event("startup")
11 | async def startup():
12 | await database.connect()
13 |
14 | @app.on_event("shutdown")
15 | async def shutdown():
16 | await database.disconnect()
17 |
18 | app.include_router(customers_router, prefix='/api/v1/customers', tags=['customers'])
--------------------------------------------------------------------------------
/customer-service/requirements.txt:
--------------------------------------------------------------------------------
1 | anyio==3.5.0
2 | asgiref==3.5.0
3 | asyncpg==0.25.0
4 | click==8.1.2
5 | databases==0.5.5
6 | fastapi==0.75.2
7 | greenlet==1.1.2
8 | h11==0.13.0
9 | idna==3.3
10 | psycopg2-binary==2.9.3
11 | pydantic==1.9.0
12 | sniffio==1.2.0
13 | SQLAlchemy==1.4.36
14 | starlette==0.17.1
15 | typing-extensions==4.2.0
16 | uvicorn==0.17.6
17 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.7'
2 |
3 | services:
4 | customer_service:
5 | build: ./customer-service
6 | command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
7 | volumes:
8 | - ./customer-service/:/app/
9 | ports:
10 | - 8001:8000
11 | environment:
12 | - DATABASE_URI=postgresql://customer_db_username:customer_db_password@customer_db/customer_db_dev
13 | depends_on:
14 | - customer_db
15 |
16 | customer_db:
17 | image: postgres:latest
18 | volumes:
19 | - postgres_data_customer:/var/lib/postgresql/data/
20 | environment:
21 | - POSTGRES_USER=customer_db_username
22 | - POSTGRES_PASSWORD=customer_db_password
23 | - POSTGRES_DB=customer_db_dev
24 | logging:
25 | driver: none
26 |
27 | product_service:
28 | build: ./product-service
29 | command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
30 | volumes:
31 | - ./product-service/:/app/
32 | ports:
33 | - 8002:8000
34 | environment:
35 | - DATABASE_URI=postgresql://product_db_username:product_db_password@product_db/product_db_dev
36 | logging:
37 | driver: none
38 |
39 | product_db:
40 | image: postgres:latest
41 | volumes:
42 | - postgres_data_product:/var/lib/postgresql/data/
43 | environment:
44 | - POSTGRES_USER=product_db_username
45 | - POSTGRES_PASSWORD=product_db_password
46 | - POSTGRES_DB=product_db_dev
47 | logging:
48 | driver: none
49 |
50 | price_service:
51 | build: ./price-service
52 | command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
53 | volumes:
54 | - ./price-service/:/app/
55 | ports:
56 | - 8003:8000
57 | environment:
58 | - DATABASE_URI=postgresql://price_db_username:price_db_password@price_db/price_db_dev
59 |
60 | order_service:
61 | build: ./order-service
62 | command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
63 | volumes:
64 | - ./order-service/:/app/
65 | ports:
66 | - 8004:8000
67 | environment:
68 | - DATABASE_URI=postgresql://order_db_username:order_db_password@order_db/order_db_dev
69 |
70 | order_db:
71 | image: postgres:latest
72 | volumes:
73 | - postgres_data_order:/var/lib/postgresql/data/
74 | environment:
75 | - POSTGRES_USER=order_db_username
76 | - POSTGRES_PASSWORD=order_db_password
77 | - POSTGRES_DB=order_db_dev
78 | logging:
79 | driver: none
80 |
81 | nginx:
82 | image: nginx:latest
83 | ports:
84 | - "8080:8080"
85 | volumes:
86 | - ./nginx_config.conf:/etc/nginx/conf.d/default.conf
87 | depends_on:
88 | - customer_service
89 | - product_service
90 | - price_service
91 | - order_service
92 |
93 | volumes:
94 | postgres_data_customer:
95 | postgres_data_product:
96 | postgres_data_price:
97 | postgres_data_order:
98 |
--------------------------------------------------------------------------------
/img/customers.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/customers.gif
--------------------------------------------------------------------------------
/img/install.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/install.gif
--------------------------------------------------------------------------------
/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/logo.png
--------------------------------------------------------------------------------
/img/orders.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/orders.png
--------------------------------------------------------------------------------
/img/prices.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/prices.png
--------------------------------------------------------------------------------
/img/products.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zakharb/MicroAPI/382044aa0b0f74202df9f09826699fc473c42383/img/products.png
--------------------------------------------------------------------------------
/nginx_config.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 8080;
3 |
4 | location /api/v1/customers {
5 | proxy_pass http://customer_service:8000/api/v1/customers;
6 | }
7 |
8 | location /api/v1/products {
9 | proxy_pass http://product_service:8000/api/v1/products;
10 | }
11 |
12 | location /api/v1/prices {
13 | proxy_pass http://price_service:8000/api/v1/prices;
14 | }
15 |
16 | location /api/v1/orders {
17 | proxy_pass http://order_service:8000/api/v1/orders;
18 | }
19 | }
--------------------------------------------------------------------------------
/order-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.9-slim
2 |
3 | WORKDIR /app
4 |
5 | COPY ./requirements.txt /app/requirements.txt
6 |
7 | RUN apt-get update \
8 | && apt-get install gcc -y \
9 | && apt-get clean
10 |
11 | RUN pip install -r /app/requirements.txt \
12 | && rm -rf /root/.cache/pip
13 |
14 | COPY . /app/
15 |
--------------------------------------------------------------------------------
/order-service/app/api/db.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | DB module for order-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Make engine, connection to DB and tables
24 | """
25 |
26 | import os
27 | import sqlalchemy
28 |
29 | from databases import Database
30 |
31 | DATABASE_URI = os.getenv('DATABASE_URI')
32 |
33 | engine = sqlalchemy.create_engine(DATABASE_URI)
34 | metadata = sqlalchemy.MetaData()
35 |
36 | orders = sqlalchemy.Table(
37 | 'orders',
38 | metadata,
39 | sqlalchemy.Column('order_id', sqlalchemy.BigInteger, primary_key=True),
40 | sqlalchemy.Column('order_no', sqlalchemy.BigInteger),
41 | sqlalchemy.Column('customer_id', sqlalchemy.BigInteger),
42 | sqlalchemy.Column('product_id', sqlalchemy.BigInteger),
43 | sqlalchemy.Column('quantity', sqlalchemy.BigInteger),
44 | sqlalchemy.Column('price_net', sqlalchemy.Integer),
45 | sqlalchemy.Column('price_gross', sqlalchemy.Integer),
46 | )
47 |
48 | database = Database(DATABASE_URI)
--------------------------------------------------------------------------------
/order-service/app/api/db_manager.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Manager to work with DB at order-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | CRUD operations to work with DB
24 | """
25 |
26 | from app.api.models import OrderIn, OrderOut, OrderUpdate
27 | from app.api.db import orders, database
28 |
29 |
30 | async def add_order(payload: OrderIn):
31 | query = orders.insert().values(**payload.dict())
32 | return await database.execute(query=query)
33 |
34 | async def get_all_orders():
35 | query = orders.select()
36 | return await database.fetch_all(query=query)
37 |
38 | async def get_order(id):
39 | query = orders.select(orders.c.id==id)
40 | return await database.fetch_one(query=query)
41 |
42 | async def delete_order(id: int):
43 | query = orders.delete().where(orders.c.id==id)
44 | return await database.execute(query=query)
45 |
46 | async def update_order(id: int, payload: OrderIn):
47 | query = (
48 | orders
49 | .update()
50 | .where(orders.c.id == id)
51 | .values(**payload.dict())
52 | )
53 | return await database.execute(query=query)
--------------------------------------------------------------------------------
/order-service/app/api/models.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Models to order-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Pydantic models to make docs and check types
24 | """
25 |
26 | from pydantic import BaseModel
27 | from typing import List, Optional
28 |
29 |
30 | class OrderIn(BaseModel):
31 | order_no: int
32 | customer_id: int
33 | product_id: int
34 | quantity: int
35 | price_net: int
36 | price_gross: int
37 |
38 |
39 | class OrderOut(OrderIn):
40 | order_id: int
41 |
42 |
43 | class OrderUpdate(OrderIn):
44 | customer_id: Optional[int] = None
45 | product_id: Optional[int] = None
46 | quantity: Optional[int] = None
47 | price_net: Optional[int] = None
48 | price_gross: Optional[int] = None
49 |
--------------------------------------------------------------------------------
/order-service/app/api/orders.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Routers for order-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Routers for operations with API
24 | """
25 |
26 | from typing import List
27 | from fastapi import APIRouter, HTTPException
28 |
29 | from app.api.models import OrderOut, OrderIn, OrderUpdate
30 | from app.api import db_manager
31 |
32 | router = APIRouter()
33 |
34 | @router.post('/', response_model=OrderOut, status_code=201)
35 | async def create_order(payload: OrderIn):
36 | order_id = await db_manager.add_order(payload)
37 | response = {
38 | 'order_id': order_id,
39 | **payload.dict()
40 | }
41 | return response
42 |
43 | @router.get('/', response_model=List[OrderOut])
44 | async def get_orders():
45 | return await db_manager.get_all_orders()
46 |
47 | @router.get('/{id}/', response_model=OrderOut)
48 | async def get_order(id: int):
49 | order = await db_manager.get_order(id)
50 | if not order:
51 | raise HTTPException(status_code=404, detail="Order not found")
52 | return order
53 |
54 | @router.put('/{id}/', response_model=OrderOut)
55 | async def update_order(id: int, payload: OrderUpdate):
56 | order = await db_manager.get_order(id)
57 | if not order:
58 | raise HTTPException(status_code=404, detail="Order not found")
59 | update_data = payload.dict(exclude_unset=True)
60 | order_in_db = OrderIn(**order)
61 | updated_order = order_in_db.copy(update=update_data)
62 | return await db_manager.update_order(id, updated_order)
63 |
64 | @router.delete('/{id}', response_model=None)
65 | async def delete_order(id: int):
66 | order = await db_manager.get_order(id)
67 | if not order:
68 | raise HTTPException(status_code=404, detail="Order not found")
69 | return await db_manager.delete_order(id)
70 |
--------------------------------------------------------------------------------
/order-service/app/main.py:
--------------------------------------------------------------------------------
1 | from fastapi import FastAPI
2 | from app.api.orders import router as orders_router
3 | from app.api.db import metadata, database, engine
4 |
5 | metadata.create_all(engine)
6 |
7 | app = FastAPI(openapi_url="/api/v1/orders/openapi.json",
8 | docs_url="/api/v1/orders/docs")
9 |
10 | @app.on_event("startup")
11 | async def startup():
12 | await database.connect()
13 |
14 | @app.on_event("shutdown")
15 | async def shutdown():
16 | await database.disconnect()
17 |
18 | app.include_router(orders_router, prefix='/api/v1/orders', tags=['orders'])
--------------------------------------------------------------------------------
/order-service/requirements.txt:
--------------------------------------------------------------------------------
1 | anyio==3.5.0
2 | asgiref==3.5.0
3 | asyncpg==0.25.0
4 | click==8.1.2
5 | databases==0.5.5
6 | fastapi==0.75.2
7 | greenlet==1.1.2
8 | h11==0.13.0
9 | idna==3.3
10 | psycopg2-binary==2.9.3
11 | pydantic==1.9.0
12 | sniffio==1.2.0
13 | SQLAlchemy==1.4.36
14 | starlette==0.17.1
15 | typing-extensions==4.2.0
16 | uvicorn==0.17.6
17 |
--------------------------------------------------------------------------------
/orders.csv:
--------------------------------------------------------------------------------
1 | order_no,customer_id,product_name,quantity,
2 | 46325,39,Product18,12,
3 | 12559,25,Product15,16,
4 | 8183,43,Product41,8,
5 | 75758,31,Product80,53,
6 | 1595,3,Product88,43,
7 | 75096,23,Product64,13,
8 | 89699,3,Product4,0,
9 | 30313,30,Product27,39,
10 | 80855,4,Product80,24,
11 | 60847,38,Product91,28,
12 | 88252,37,Product2,11,
13 | 32947,26,Product98,43,
14 | 63609,33,Product98,52,
15 | 58890,14,Product79,46,
16 | 19996,31,Product41,8,
17 | 83746,19,Product37,52,
18 | 78121,21,Product40,42,
19 | 62429,19,Product48,9,
20 | 42721,36,Product21,55,
21 | 89947,3,Product80,5,
22 | 6420,45,Product80,10,
23 | 80385,1,Product38,52,
24 | 15688,13,Product38,11,
25 | 43211,16,Product25,31,
26 | 66083,13,Product65,30,
27 | 81290,47,Product88,11,
28 | 11304,31,Product88,49,
29 | 89597,14,Product18,15,
30 | 38974,15,Product81,51,
31 | 49734,35,Product84,44,
32 | 85449,36,Product41,15,
33 | 6113,18,Product21,20,
34 | 5417,35,Product48,44,
35 | 88574,18,Product56,8,
36 | 86292,15,Product79,23,
37 | 35679,22,Product38,35,
38 | 87036,36,Product21,18,
39 | 19101,35,Product88,9,
40 | 99102,20,Product89,57,
41 | 94053,34,Product78,40,
42 | 13829,27,Product49,59,
43 | 21911,43,Product57,32,
44 | 31731,17,Product53,35,
45 | 67120,40,Product48,41,
46 | 99141,3,Product2,6,
47 | 80079,23,Product85,19,
48 | 13198,36,Product24,58,
49 | 52309,1,Product24,4,
50 | 85759,2,Product21,28,
51 | 46599,37,Product5,32,
52 | 65939,41,Product4,24,
53 | 43984,16,Product0,17,
54 | 89286,25,Product15,35,
55 | 21375,33,Product24,34,
56 | 4780,1,Product91,26,
57 | 11143,10,Product81,30,
58 | 22185,31,Product0,29,
59 | 16421,28,Product40,30,
60 | 42449,2,Product24,48,
61 | 72147,23,Product63,24,
62 | 36284,20,Product57,11,
63 | 60713,36,Product98,53,
64 | 28859,4,Product79,5,
65 | 21695,11,Product30,47,
66 | 94664,49,Product59,51,
67 | 29698,32,Product18,52,
68 | 19992,39,Product0,7,
69 | 16295,42,Product20,52,
70 | 34969,49,Product39,22,
71 | 35154,11,Product0,52,
72 | 96819,42,Product56,49,
73 | 73791,38,Product30,12,
74 | 70127,19,Product37,56,
75 | 95480,16,Product80,6,
76 | 60559,37,Product80,23,
77 | 19640,9,Product85,47,
78 | 47082,22,Product78,19,
79 | 93584,30,Product85,23,
80 | 75440,5,Product12,45,
81 | 84900,3,Product24,47,
82 | 26854,18,Product67,12,
83 | 54665,36,Product2,11,
84 | 67922,40,Product20,58,
85 | 89896,16,Product67,46,
86 | 914,39,Product67,8,
87 | 26470,29,Product80,11,
88 | 42206,27,Product59,28,
89 | 12033,18,Product7,46,
90 | 68357,14,Product30,27,
91 | 88746,11,Product5,23,
92 | 17009,36,Product65,57,
93 | 15723,29,Product15,32,
94 | 66973,36,Product38,53,
95 | 76977,9,Product48,45,
96 | 44123,13,Product7,52,
97 | 12650,22,Product21,6,
98 | 54323,33,Product79,48,
99 | 76328,15,Product65,24,
100 | 62981,47,Product69,1,
101 | 52545,35,Product10,59,
102 | 72012,1,Product57,50,
103 | 54521,29,Product78,40,
104 | 664,5,Product12,5,
105 | 54017,7,Product88,56,
106 | 55107,31,Product5,28,
107 | 98590,13,Product27,59,
108 | 12049,6,Product49,28,
109 | 84150,24,Product27,51,
110 | 58296,26,Product89,20,
111 | 62266,19,Product79,25,
112 | 82700,48,Product79,32,
113 | 37664,23,Product56,48,
114 | 84749,36,Product12,3,
115 | 50605,34,Product4,51,
116 | 7215,6,Product15,0,
117 | 12179,49,Product37,5,
118 | 11943,48,Product41,46,
119 | 45958,5,Product27,13,
120 | 41531,30,Product2,38,
121 | 63043,35,Product67,1,
122 | 56327,15,Product81,7,
123 | 53192,42,Product80,27,
124 | 40776,31,Product89,57,
125 | 41782,22,Product2,13,
126 | 83838,48,Product98,24,
127 | 50866,31,Product80,10,
128 | 4793,36,Product69,37,
129 | 48151,26,Product0,49,
130 | 67347,3,Product38,17,
131 | 14714,2,Product30,51,
132 | 21623,12,Product12,42,
133 | 71732,43,Product25,5,
134 | 75155,27,Product2,45,
135 | 68793,40,Product25,32,
136 | 99107,34,Product88,30,
137 | 30503,22,Product89,44,
138 | 84324,11,Product37,43,
139 | 23438,38,Product41,51,
140 | 15135,47,Product49,1,
141 | 48845,25,Product88,44,
142 | 26085,8,Product56,27,
143 | 19376,40,Product38,26,
144 | 52574,45,Product25,18,
145 | 85082,5,Product89,51,
146 | 11415,16,Product2,59,
147 | 80495,18,Product10,20,
148 | 60294,4,Product80,54,
149 | 9911,5,Product69,26,
150 | 56956,17,Product10,41,
151 | 96277,8,Product59,27,
152 | 75786,26,Product32,1,
153 | 68753,14,Product2,34,
154 | 69495,23,Product24,35,
155 | 84054,22,Product80,36,
156 | 29033,22,Product69,34,
157 | 29459,35,Product15,45,
158 | 64389,31,Product10,39,
159 | 23766,14,Product21,41,
160 | 16603,24,Product57,44,
161 | 39681,40,Product41,42,
162 | 29811,20,Product80,39,
163 | 25867,29,Product0,50,
164 | 39877,1,Product81,39,
165 | 99391,42,Product21,48,
166 | 57801,19,Product32,43,
167 | 17186,32,Product20,49,
168 | 89306,14,Product15,7,
169 | 53290,32,Product91,0,
170 | 61278,6,Product2,52,
171 | 19219,6,Product98,53,
172 | 39426,15,Product5,13,
173 | 65356,12,Product64,33,
174 | 48898,39,Product53,57,
175 | 4675,46,Product98,26,
176 | 89469,10,Product37,59,
177 | 6638,7,Product56,48,
178 | 494,6,Product81,4,
179 | 67787,8,Product27,19,
180 | 50248,45,Product49,41,
181 | 24182,48,Product2,54,
182 | 9568,12,Product79,40,
183 | 36869,14,Product48,6,
184 | 69906,13,Product21,36,
185 | 62216,41,Product10,36,
186 | 91228,41,Product84,43,
187 | 99198,11,Product65,30,
188 | 45966,16,Product2,6,
189 | 58372,11,Product91,25,
190 | 88544,6,Product88,32,
191 | 70416,27,Product65,14,
192 | 74502,25,Product10,51,
193 | 65273,12,Product88,0,
194 | 13940,12,Product37,57,
195 | 7682,45,Product30,19,
196 | 27236,40,Product7,16,
197 | 72548,35,Product4,43,
198 | 65869,47,Product4,32,
199 | 93568,34,Product2,43,
200 | 29528,2,Product24,46,
201 | 88516,17,Product49,37,
202 | 29407,25,Product69,41,
203 | 48518,1,Product56,53,
204 | 73815,18,Product48,59,
205 | 70087,44,Product4,38,
206 | 42961,26,Product24,50,
207 | 44127,41,Product48,22,
208 | 77977,1,Product20,43,
209 | 78736,36,Product0,46,
210 | 32446,34,Product7,1,
211 | 14988,32,Product91,46,
212 | 39103,31,Product12,48,
213 | 67604,33,Product89,50,
214 | 3800,23,Product30,52,
215 | 50549,37,Product98,57,
216 | 95928,30,Product91,10,
217 | 26917,49,Product18,52,
218 | 67407,28,Product85,49,
219 | 52092,36,Product49,32,
220 | 31253,46,Product2,7,
221 | 34935,13,Product69,24,
222 | 74708,28,Product18,39,
223 | 85314,17,Product0,28,
224 | 7874,4,Product7,51,
225 | 22321,13,Product63,9,
226 | 40046,25,Product89,16,
227 | 8764,13,Product89,13,
228 | 61169,12,Product80,57,
229 | 68255,16,Product18,19,
230 | 97791,47,Product98,1,
231 | 3944,4,Product69,17,
232 | 22898,2,Product84,6,
233 | 69829,17,Product64,45,
234 | 88054,13,Product5,56,
235 | 76047,5,Product24,34,
236 | 68229,35,Product80,4,
237 | 74478,1,Product38,45,
238 | 8454,17,Product59,59,
239 | 51635,10,Product85,22,
240 | 66373,7,Product89,3,
241 | 57024,29,Product49,28,
242 | 76782,37,Product0,56,
243 | 96346,40,Product64,52,
244 | 42245,31,Product30,17,
245 | 55715,16,Product65,13,
246 | 41638,14,Product20,9,
247 | 56688,40,Product15,29,
248 | 51011,39,Product39,40,
249 | 58225,9,Product5,42,
250 | 39281,40,Product65,5,
251 | 76243,20,Product39,35,
252 | 75449,28,Product27,48,
253 | 43732,17,Product69,31,
254 | 6836,42,Product53,29,
255 | 35275,22,Product78,47,
256 | 41845,21,Product81,26,
257 | 24661,33,Product88,18,
258 | 87987,19,Product2,58,
259 | 51431,38,Product79,4,
260 | 55389,24,Product15,11,
261 | 88844,26,Product38,55,
262 | 41232,35,Product81,37,
263 | 22799,18,Product32,25,
264 | 77314,7,Product48,48,
265 | 68808,20,Product69,2,
266 | 93303,20,Product24,2,
267 | 231,38,Product98,55,
268 | 15225,41,Product40,9,
269 | 87150,16,Product18,37,
270 | 6700,15,Product88,22,
271 | 63178,25,Product37,10,
272 | 35395,12,Product53,3,
273 | 62835,25,Product98,47,
274 | 72813,13,Product63,22,
275 | 77961,27,Product18,57,
276 | 80673,33,Product15,52,
277 | 31525,18,Product48,42,
278 | 20251,35,Product48,6,
279 | 32495,38,Product10,40,
280 | 40908,8,Product27,43,
281 | 47984,34,Product48,38,
282 | 34907,24,Product24,29,
283 | 21737,7,Product98,48,
284 | 55043,39,Product25,54,
285 | 61920,44,Product11,14,
286 | 66451,17,Product24,3,
287 | 30522,4,Product64,18,
288 | 21971,39,Product4,4,
289 | 2645,42,Product59,13,
290 | 59322,26,Product4,9,
291 | 59494,8,Product79,14,
292 | 4377,40,Product2,41,
293 | 34745,45,Product40,58,
294 | 49753,23,Product98,57,
295 | 21329,36,Product67,5,
296 | 6107,5,Product56,46,
297 | 89154,15,Product10,49,
298 | 71589,18,Product79,29,
299 | 23337,26,Product48,23,
300 | 99421,35,Product79,48,
301 | 74263,4,Product98,10,
302 | 95479,25,Product30,6,
303 | 72316,17,Product10,32,
304 | 64082,28,Product48,23,
305 | 49955,44,Product69,37,
306 | 61678,47,Product53,29,
307 | 42611,15,Product24,34,
308 | 17708,49,Product57,15,
309 | 18453,27,Product2,27,
310 | 49757,28,Product79,19,
311 | 46928,37,Product53,46,
312 | 11368,41,Product88,42,
313 | 12225,1,Product78,23,
314 | 34112,8,Product79,42,
315 | 18275,17,Product59,51,
316 | 66065,20,Product49,7,
317 | 88235,47,Product81,17,
318 | 69467,27,Product7,29,
319 | 5247,19,Product12,29,
320 | 88312,4,Product39,12,
321 | 61537,15,Product81,19,
322 | 35540,41,Product0,56,
323 | 5940,8,Product30,35,
324 | 94282,13,Product0,50,
325 | 81536,44,Product2,7,
326 | 10249,35,Product2,16,
327 | 30863,24,Product37,50,
328 | 14672,35,Product30,16,
329 | 62609,25,Product98,23,
330 | 53986,33,Product24,48,
331 | 19599,45,Product27,13,
332 | 38926,35,Product24,13,
333 | 68016,5,Product20,30,
334 | 99277,47,Product10,18,
335 | 11626,32,Product63,35,
336 | 50135,45,Product10,19,
337 | 53676,25,Product30,12,
338 | 9799,48,Product80,39,
339 | 51905,22,Product89,5,
340 | 99869,40,Product25,10,
341 | 14600,21,Product56,5,
342 | 26149,47,Product24,36,
343 | 90963,39,Product0,48,
344 | 67870,36,Product7,58,
345 | 24914,48,Product53,50,
346 | 2498,23,Product85,19,
347 | 11419,33,Product59,37,
348 | 4781,13,Product89,27,
349 | 24436,23,Product5,36,
350 | 43830,12,Product38,55,
351 | 93708,25,Product30,38,
352 | 47723,32,Product38,7,
353 | 25775,49,Product85,49,
354 | 72471,45,Product53,32,
355 | 54468,43,Product81,55,
356 | 81998,27,Product37,25,
357 | 24916,32,Product84,56,
358 | 94616,36,Product41,34,
359 | 39851,48,Product88,24,
360 | 38252,7,Product40,24,
361 | 79144,27,Product59,8,
362 | 54622,15,Product80,25,
363 | 35260,9,Product88,40,
364 | 75028,42,Product85,6,
365 | 18487,15,Product88,9,
366 | 70791,44,Product41,27,
367 | 1159,34,Product84,22,
368 | 91396,49,Product38,8,
369 | 53858,21,Product80,17,
370 | 63781,40,Product91,53,
371 | 77301,45,Product84,26,
372 | 12312,11,Product69,10,
373 | 47540,29,Product10,41,
374 | 42865,45,Product81,30,
375 | 46863,11,Product91,17,
376 | 32339,20,Product10,55,
377 | 21166,10,Product88,5,
378 | 73293,15,Product15,47,
379 | 49590,11,Product78,15,
380 | 59649,49,Product64,12,
381 | 91274,47,Product30,33,
382 | 81175,3,Product12,41,
383 | 23614,10,Product89,14,
384 | 36273,38,Product37,35,
385 | 90486,40,Product4,14,
386 | 48815,40,Product85,42,
387 | 38421,5,Product24,50,
388 | 91548,29,Product32,28,
389 | 26331,40,Product10,32,
390 | 86489,17,Product18,58,
391 | 12907,47,Product98,8,
392 | 83648,48,Product84,37,
393 | 45885,35,Product98,6,
394 | 5566,13,Product98,26,
395 | 53851,30,Product2,47,
396 | 75917,30,Product7,2,
397 | 60578,19,Product65,57,
398 | 94370,41,Product40,47,
399 | 83318,21,Product20,42,
400 | 47567,41,Product30,9,
401 | 25954,8,Product10,40,
402 | 22469,11,Product11,53,
403 | 603,20,Product80,12,
404 | 14616,20,Product80,9,
405 | 30290,34,Product30,33,
406 | 48326,26,Product30,59,
407 | 86626,19,Product78,33,
408 | 33431,44,Product2,54,
409 | 41673,15,Product79,8,
410 | 49465,40,Product81,19,
411 | 70760,15,Product11,46,
412 | 53343,40,Product79,5,
413 | 51704,48,Product21,22,
414 | 94436,22,Product7,49,
415 | 86395,46,Product21,39,
416 | 8756,15,Product32,50,
417 | 76742,21,Product48,5,
418 | 46010,32,Product2,46,
419 | 37182,45,Product40,31,
420 | 95472,48,Product67,10,
421 | 97382,31,Product53,39,
422 | 75561,17,Product21,50,
423 | 11944,12,Product21,58,
424 | 59676,27,Product5,36,
425 | 22674,30,Product25,23,
426 | 24883,26,Product56,27,
427 | 3215,4,Product20,14,
428 | 98532,47,Product49,15,
429 | 35321,25,Product30,28,
430 | 85143,34,Product53,42,
431 | 21007,9,Product59,36,
432 | 28550,4,Product21,46,
433 | 58521,28,Product56,43,
434 | 60211,28,Product0,47,
435 | 67617,23,Product12,38,
436 | 94986,45,Product20,32,
437 | 42868,7,Product7,56,
438 | 24856,41,Product88,53,
439 | 45394,46,Product7,47,
440 | 51936,7,Product24,46,
441 | 80322,27,Product98,36,
442 | 89584,5,Product10,18,
443 | 51282,28,Product49,25,
444 | 53742,12,Product18,33,
445 | 39909,29,Product56,58,
446 | 8879,27,Product0,50,
447 | 84537,16,Product37,31,
448 | 98185,7,Product2,3,
449 | 23504,6,Product15,2,
450 | 57268,43,Product12,37,
451 | 55740,22,Product84,17,
452 | 16412,49,Product24,8,
453 | 82538,2,Product11,12,
454 | 15557,28,Product79,48,
455 | 32400,45,Product2,22,
456 | 1426,48,Product39,45,
457 | 76991,8,Product91,18,
458 | 20500,11,Product89,12,
459 | 32605,14,Product80,51,
460 | 76207,28,Product11,33,
461 | 38131,48,Product78,52,
462 | 1186,6,Product98,27,
463 | 88788,40,Product78,9,
464 | 42118,48,Product64,59,
465 | 13392,12,Product7,25,
466 | 65505,32,Product24,33,
467 | 44692,45,Product5,33,
468 | 51272,25,Product59,42,
469 | 9191,28,Product91,33,
470 | 30137,48,Product91,13,
471 | 73120,30,Product32,15,
472 | 86242,24,Product32,11,
473 | 13412,4,Product41,19,
474 | 30279,9,Product39,11,
475 | 47346,33,Product30,18,
476 | 12833,36,Product57,6,
477 | 38626,4,Product2,34,
478 | 51279,41,Product80,33,
479 | 39350,36,Product24,3,
480 | 79808,8,Product69,22,
481 | 54645,10,Product80,20,
482 | 13173,22,Product80,20,
483 | 65663,4,Product10,31,
484 | 45591,37,Product63,49,
485 | 91527,7,Product25,1,
486 | 47660,3,Product10,39,
487 | 96157,25,Product59,20,
488 | 15637,34,Product67,37,
489 | 40223,46,Product98,7,
490 | 22500,43,Product37,30,
491 | 45375,12,Product69,4,
492 | 60839,2,Product98,22,
493 | 32034,4,Product59,14,
494 | 93655,45,Product79,3,
495 | 66073,26,Product80,38,
496 | 78775,10,Product32,52,
497 | 42114,25,Product32,41,
498 | 75061,22,Product57,40,
499 | 52493,9,Product18,18,
500 | 17237,2,Product91,2,
501 | 40093,32,Product24,18,
502 | 5590,3,Product37,20,
503 | 96800,49,Product32,47,
504 | 80832,46,Product81,2,
505 | 49642,28,Product10,37,
506 | 83899,17,Product12,9,
507 | 50515,23,Product81,52,
508 | 29669,1,Product25,33,
509 | 46282,25,Product24,35,
510 | 66135,33,Product85,5,
511 | 61898,8,Product48,24,
512 | 78023,9,Product69,34,
513 | 52759,11,Product0,4,
514 | 26222,1,Product98,44,
515 | 70264,49,Product37,28,
516 | 19649,37,Product59,6,
517 | 82707,9,Product10,49,
518 | 74203,20,Product79,26,
519 | 58054,47,Product2,30,
520 | 15074,38,Product78,33,
521 | 77744,1,Product10,11,
522 | 92123,1,Product80,51,
523 | 55159,4,Product56,27,
524 | 51425,10,Product79,58,
525 | 11227,37,Product24,37,
526 | 91526,15,Product81,38,
527 | 3240,24,Product24,8,
528 | 65510,4,Product25,54,
529 | 84374,4,Product11,42,
530 | 67351,21,Product10,19,
531 | 29987,24,Product39,26,
532 | 45503,6,Product64,6,
533 | 22095,38,Product37,39,
534 | 31871,8,Product30,10,
535 | 75276,20,Product2,49,
536 | 30987,38,Product91,48,
537 | 95479,18,Product24,6,
538 | 89620,10,Product5,46,
539 | 86440,31,Product80,32,
540 | 12455,35,Product32,21,
541 | 10453,41,Product40,57,
542 | 42128,8,Product11,10,
543 | 43109,47,Product11,28,
544 | 51553,35,Product63,30,
545 | 16309,14,Product89,10,
546 | 47336,49,Product81,44,
547 | 3710,43,Product4,32,
548 | 62358,45,Product98,47,
549 | 52251,48,Product4,19,
550 | 82706,40,Product30,20,
551 | 98838,48,Product5,3,
552 | 40241,2,Product63,30,
553 | 81451,14,Product89,55,
554 | 4275,23,Product32,18,
555 | 31642,31,Product10,31,
556 | 83908,19,Product24,14,
557 | 21918,25,Product30,59,
558 | 95283,42,Product0,36,
559 | 10648,36,Product4,8,
560 | 14421,39,Product57,47,
561 | 51236,24,Product63,0,
562 | 13729,34,Product65,59,
563 | 1611,47,Product20,54,
564 | 42941,17,Product10,39,
565 | 29558,10,Product65,11,
566 | 58085,45,Product12,44,
567 | 40707,19,Product38,56,
568 | 37798,16,Product24,10,
569 | 50091,6,Product69,22,
570 | 72599,24,Product30,0,
571 | 2923,1,Product67,33,
572 | 50018,29,Product79,56,
573 | 82662,22,Product80,13,
574 | 64416,19,Product81,36,
575 | 89340,38,Product59,38,
576 | 9617,36,Product15,38,
577 | 92875,29,Product30,29,
578 | 96738,45,Product67,19,
579 | 6497,48,Product5,36,
580 | 88352,27,Product69,36,
581 | 79736,1,Product69,24,
582 | 14197,19,Product48,38,
583 | 29043,1,Product32,25,
584 | 56604,4,Product80,54,
585 | 82046,26,Product2,3,
586 | 87765,13,Product38,8,
587 | 54732,8,Product40,15,
588 | 85082,48,Product18,46,
589 | 20086,6,Product30,46,
590 | 77820,10,Product81,44,
591 | 82309,40,Product5,28,
592 | 81200,22,Product2,34,
593 | 40796,10,Product78,32,
594 | 7152,45,Product10,54,
595 | 82215,32,Product88,25,
596 | 41464,8,Product25,14,
597 | 73463,22,Product69,14,
598 | 34863,21,Product88,30,
599 | 52016,19,Product12,22,
600 | 61116,32,Product2,18,
601 | 83535,18,Product38,56,
602 | 67789,22,Product7,18,
603 | 21665,16,Product37,48,
604 | 46449,38,Product24,43,
605 | 46792,34,Product49,36,
606 | 23339,4,Product11,39,
607 | 90008,23,Product20,22,
608 | 28498,28,Product49,29,
609 | 62420,37,Product24,0,
610 | 59741,18,Product67,21,
611 | 19651,3,Product10,4,
612 | 68592,15,Product10,40,
613 | 77574,17,Product24,46,
614 | 1005,5,Product56,15,
615 | 76722,41,Product40,18,
616 | 2360,49,Product80,18,
617 | 58191,11,Product10,2,
618 | 90083,7,Product25,46,
619 | 64846,4,Product38,5,
620 | 44324,34,Product84,47,
621 | 97225,28,Product5,11,
622 | 51029,45,Product24,23,
623 | 78858,11,Product11,14,
624 | 25408,38,Product84,43,
625 | 73563,46,Product79,52,
626 | 62350,40,Product89,13,
627 | 88381,2,Product2,7,
628 | 41168,40,Product88,37,
629 | 27765,30,Product15,7,
630 | 14758,23,Product38,49,
631 | 42058,14,Product85,44,
632 | 24565,48,Product2,46,
633 | 52882,11,Product67,30,
634 | 1670,36,Product37,4,
635 | 36530,13,Product98,36,
636 | 83592,7,Product38,16,
637 | 72189,3,Product39,33,
638 | 46515,17,Product89,59,
639 | 77875,6,Product4,45,
640 | 9958,1,Product63,54,
641 | 15267,15,Product10,9,
642 | 98698,21,Product30,56,
643 | 27705,11,Product78,1,
644 | 75630,38,Product27,40,
645 | 68566,1,Product79,32,
646 | 45286,30,Product20,30,
647 | 87764,48,Product98,29,
648 | 21256,32,Product78,49,
649 | 79970,1,Product24,0,
650 | 28238,42,Product20,6,
651 | 52280,36,Product81,14,
652 | 87552,23,Product0,43,
653 | 4194,11,Product41,4,
654 | 50841,9,Product57,54,
655 | 20994,44,Product88,15,
656 | 51179,7,Product67,33,
657 | 32523,27,Product10,10,
658 | 62728,40,Product78,3,
659 | 32943,12,Product25,37,
660 | 35842,16,Product98,38,
661 | 36171,47,Product37,26,
662 | 69722,1,Product84,4,
663 | 13177,47,Product65,0,
664 | 90097,36,Product39,17,
665 | 67615,44,Product4,12,
666 | 61084,20,Product5,24,
667 | 47471,1,Product49,3,
668 | 401,17,Product11,55,
669 | 67618,35,Product10,2,
670 | 75077,31,Product80,49,
671 | 37624,41,Product10,18,
672 | 23756,37,Product7,53,
673 | 1231,16,Product39,42,
674 | 424,28,Product20,54,
675 | 16812,28,Product48,43,
676 | 98276,44,Product30,40,
677 | 39222,47,Product59,42,
678 | 1962,6,Product10,23,
679 | 22371,17,Product40,14,
680 | 70171,20,Product89,7,
681 | 64353,8,Product48,32,
682 | 20623,47,Product12,11,
683 | 59255,30,Product98,0,
684 | 37542,47,Product5,39,
685 | 70325,42,Product89,2,
686 | 46677,7,Product65,16,
687 | 51703,24,Product78,51,
688 | 33089,7,Product24,27,
689 | 7027,46,Product39,9,
690 | 96384,44,Product39,39,
691 | 6978,29,Product49,54,
692 | 11153,18,Product57,33,
693 | 58999,41,Product79,18,
694 | 95551,33,Product98,46,
695 | 80878,28,Product79,17,
696 | 53241,1,Product2,56,
697 | 50771,44,Product2,37,
698 | 58350,45,Product32,51,
699 | 13840,25,Product78,13,
700 | 94563,27,Product24,31,
701 | 42663,3,Product0,6,
702 | 80719,46,Product57,29,
703 | 55892,31,Product32,12,
704 | 9768,34,Product30,43,
705 | 35203,12,Product48,26,
706 | 25865,3,Product12,22,
707 | 92952,35,Product88,29,
708 | 28832,20,Product80,30,
709 | 26083,38,Product20,10,
710 | 70070,6,Product30,55,
711 | 41593,6,Product41,20,
712 | 58939,27,Product64,9,
713 | 7178,34,Product25,2,
714 | 59738,45,Product37,35,
715 | 48401,46,Product98,50,
716 | 31340,13,Product39,59,
717 | 37331,21,Product41,34,
718 | 23679,18,Product30,32,
719 | 44313,46,Product37,7,
720 | 40233,43,Product38,46,
721 | 42008,5,Product80,57,
722 | 50307,1,Product27,25,
723 | 7281,30,Product48,2,
724 | 79679,2,Product15,5,
725 | 17408,24,Product69,47,
726 | 73726,22,Product18,15,
727 | 76274,28,Product65,35,
728 | 57188,32,Product80,40,
729 | 75805,38,Product11,49,
730 | 9986,31,Product2,32,
731 | 87465,19,Product27,1,
732 | 75662,15,Product25,42,
733 | 45828,22,Product63,13,
734 | 68612,2,Product84,32,
735 | 35020,42,Product2,48,
736 | 14303,46,Product24,45,
737 | 68131,31,Product80,13,
738 | 54669,9,Product21,17,
739 | 40760,33,Product25,56,
740 | 60048,18,Product80,33,
741 | 61060,34,Product65,47,
742 | 29857,36,Product91,53,
743 | 20883,32,Product67,19,
744 | 7480,29,Product15,2,
745 | 25450,16,Product56,38,
746 | 44792,39,Product63,46,
747 | 15156,24,Product10,54,
748 | 20177,49,Product2,52,
749 | 1780,19,Product2,31,
750 | 77832,5,Product65,18,
751 | 21153,41,Product11,20,
752 | 59051,20,Product39,29,
753 | 81616,27,Product10,23,
754 | 37258,32,Product30,48,
755 | 11469,8,Product88,33,
756 | 29828,43,Product27,27,
757 | 35618,46,Product0,6,
758 | 81395,18,Product10,13,
759 | 70810,17,Product48,46,
760 | 93259,2,Product30,57,
761 | 77084,38,Product49,52,
762 | 49761,49,Product98,12,
763 | 90492,45,Product18,36,
764 | 27913,24,Product48,39,
765 | 87110,16,Product41,43,
766 | 15744,5,Product32,20,
767 | 78396,7,Product20,21,
768 | 31068,48,Product18,59,
769 | 46634,13,Product25,4,
770 | 24347,34,Product2,55,
771 | 69333,14,Product39,45,
772 | 73810,18,Product98,18,
773 | 30147,6,Product56,10,
774 | 29548,43,Product11,27,
775 | 99934,7,Product0,10,
776 | 56218,20,Product24,20,
777 | 81553,16,Product49,26,
778 | 79021,13,Product32,30,
779 | 59547,26,Product2,21,
780 | 15238,9,Product78,42,
781 | 17597,16,Product81,3,
782 | 85053,5,Product85,18,
783 | 82047,5,Product98,31,
784 | 63074,49,Product59,32,
785 | 83942,45,Product25,42,
786 | 16952,10,Product84,37,
787 | 6377,27,Product24,9,
788 | 36791,49,Product15,45,
789 | 54253,29,Product78,59,
790 | 83823,22,Product48,18,
791 | 55093,44,Product49,57,
792 | 97655,35,Product4,19,
793 | 35884,43,Product40,35,
794 | 72845,27,Product11,59,
795 | 68290,30,Product5,54,
796 | 26351,11,Product20,4,
797 | 75236,11,Product65,49,
798 | 61218,35,Product63,33,
799 | 1519,20,Product10,9,
800 | 14143,30,Product80,21,
801 | 29997,45,Product53,36,
802 | 12349,5,Product30,35,
803 | 44808,18,Product0,23,
804 | 51893,18,Product2,32,
805 | 62315,21,Product88,9,
806 | 46461,31,Product11,24,
807 | 36744,46,Product98,59,
808 | 28263,2,Product5,33,
809 | 37390,34,Product98,47,
810 | 40372,9,Product27,13,
811 | 34323,4,Product20,53,
812 | 68482,49,Product10,32,
813 | 73628,30,Product59,18,
814 | 47237,31,Product32,11,
815 | 25835,24,Product91,2,
816 | 1982,8,Product65,37,
817 | 73523,14,Product27,49,
818 | 24652,6,Product24,28,
819 | 66619,21,Product63,29,
820 | 63379,30,Product24,8,
821 | 12291,2,Product18,47,
822 | 14993,11,Product39,26,
823 | 40305,34,Product7,30,
824 | 79316,3,Product85,34,
825 | 61971,24,Product10,52,
826 | 7538,44,Product98,12,
827 | 75847,40,Product79,49,
828 | 30686,20,Product56,50,
829 | 12869,23,Product12,18,
830 | 40499,7,Product64,59,
831 | 6725,15,Product24,41,
832 | 58532,47,Product21,54,
833 | 37925,3,Product0,13,
834 | 47253,14,Product0,42,
835 | 56647,23,Product79,10,
836 | 58012,31,Product21,28,
837 | 67766,7,Product38,48,
838 | 98530,47,Product56,20,
839 | 49459,7,Product18,38,
840 | 21893,5,Product11,41,
841 | 56850,42,Product0,30,
842 | 73932,13,Product84,44,
843 | 71698,35,Product24,59,
844 | 20446,25,Product38,33,
845 | 81970,28,Product0,3,
846 | 9833,31,Product21,46,
847 | 95071,17,Product30,8,
848 | 50975,23,Product41,8,
849 | 16328,10,Product0,2,
850 | 2700,14,Product20,28,
851 | 16358,23,Product81,53,
852 | 95820,44,Product41,23,
853 | 93721,18,Product20,0,
854 | 58123,36,Product85,30,
855 | 99060,11,Product80,11,
856 | 53835,29,Product15,56,
857 | 95616,28,Product98,5,
858 | 11079,22,Product38,49,
859 | 61484,11,Product21,29,
860 | 86022,15,Product37,11,
861 | 50879,39,Product79,56,
862 | 62949,10,Product30,32,
863 | 78941,17,Product67,58,
864 | 35005,12,Product32,22,
865 | 7423,23,Product30,45,
866 | 75818,36,Product39,21,
867 | 32291,42,Product53,39,
868 | 78642,18,Product20,28,
869 | 79648,41,Product10,17,
870 | 78728,7,Product10,11,
871 | 38298,34,Product53,48,
872 | 5503,12,Product2,13,
873 | 86396,39,Product63,8,
874 | 82328,21,Product7,10,
875 | 52419,17,Product24,59,
876 | 2331,28,Product2,16,
877 | 23040,28,Product59,44,
878 | 78841,6,Product11,7,
879 | 98765,20,Product2,51,
880 | 56363,32,Product37,32,
881 | 29112,9,Product98,40,
882 | 48113,35,Product24,30,
883 | 77604,20,Product2,25,
884 | 45264,26,Product80,18,
885 | 59362,25,Product4,45,
886 | 27833,21,Product24,41,
887 | 32879,36,Product53,13,
888 | 76502,49,Product37,45,
889 | 50986,12,Product59,5,
890 | 18898,15,Product56,12,
891 | 43363,27,Product37,48,
892 | 23232,28,Product2,32,
893 | 47798,13,Product7,3,
894 | 18997,41,Product2,18,
895 | 33406,42,Product78,52,
896 | 56687,3,Product2,36,
897 | 13892,8,Product15,48,
898 | 77459,37,Product78,19,
899 | 34765,44,Product4,38,
900 | 86003,18,Product0,15,
901 | 66196,24,Product24,41,
902 | 2777,32,Product41,23,
903 | 62396,23,Product98,54,
904 | 33458,21,Product10,31,
905 | 65989,9,Product11,3,
906 | 74672,6,Product78,34,
907 | 47508,46,Product15,4,
908 | 39814,15,Product69,18,
909 | 4148,33,Product64,31,
910 | 34575,5,Product39,55,
911 | 15595,32,Product27,1,
912 | 61985,39,Product49,25,
913 | 80647,29,Product89,20,
914 | 97935,18,Product79,25,
915 | 37163,21,Product32,26,
916 | 69730,27,Product24,25,
917 | 70631,42,Product49,3,
918 | 15894,33,Product7,45,
919 | 93949,22,Product80,23,
920 | 64008,44,Product38,54,
921 | 15570,41,Product67,13,
922 | 93920,28,Product27,1,
923 | 7993,16,Product24,47,
924 | 60626,38,Product88,56,
925 | 5915,13,Product15,51,
926 | 72163,33,Product24,7,
927 | 25878,7,Product48,20,
928 | 28486,46,Product79,11,
929 | 11044,31,Product59,16,
930 | 85645,16,Product89,41,
931 | 46898,36,Product41,31,
932 | 50865,36,Product79,5,
933 | 84371,2,Product80,13,
934 | 84099,10,Product84,39,
935 | 8014,21,Product2,45,
936 | 68899,48,Product64,46,
937 | 66849,32,Product0,38,
938 | 6635,47,Product89,51,
939 | 20411,19,Product81,48,
940 | 87343,22,Product30,21,
941 | 29389,6,Product59,14,
942 | 40309,15,Product27,42,
943 | 63015,12,Product10,10,
944 | 28488,36,Product57,8,
945 | 88795,1,Product67,55,
946 | 84999,37,Product32,26,
947 | 78789,19,Product37,2,
948 | 19575,22,Product53,27,
949 | 78496,36,Product40,50,
950 | 58241,12,Product11,7,
951 | 48225,31,Product37,37,
952 | 27898,46,Product91,24,
953 | 98226,35,Product80,19,
954 | 88499,42,Product98,24,
955 | 46790,36,Product25,12,
956 | 36790,39,Product39,22,
957 | 78049,7,Product25,1,
958 | 37643,10,Product64,11,
959 | 62766,48,Product57,26,
960 | 16055,3,Product49,50,
961 | 88472,16,Product10,20,
962 | 66961,32,Product67,32,
963 | 71155,25,Product91,5,
964 | 79477,26,Product59,55,
965 | 16711,25,Product10,49,
966 | 68533,6,Product53,46,
967 | 55647,48,Product41,9,
968 | 2261,28,Product49,37,
969 | 86233,3,Product4,38,
970 | 50126,38,Product10,7,
971 | 49671,38,Product85,57,
972 | 28568,36,Product65,14,
973 | 79777,2,Product30,35,
974 | 4547,31,Product30,4,
975 | 62628,12,Product40,42,
976 | 92179,1,Product40,57,
977 | 94677,30,Product10,23,
978 | 67128,40,Product20,55,
979 | 72239,35,Product21,49,
980 | 44936,1,Product27,57,
981 | 73118,44,Product4,36,
982 | 79659,34,Product30,29,
983 | 43977,11,Product64,34,
984 | 49348,30,Product80,23,
985 | 82524,3,Product21,12,
986 | 55468,27,Product98,46,
987 | 74848,1,Product39,29,
988 | 69924,32,Product69,14,
989 | 84157,34,Product12,27,
990 | 56465,11,Product10,46,
991 | 336,48,Product37,14,
992 | 34818,8,Product5,7,
993 | 23659,3,Product64,17,
994 | 94372,33,Product78,38,
995 | 25188,25,Product67,40,
996 |
--------------------------------------------------------------------------------
/price-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.9-slim
2 |
3 | WORKDIR /app
4 |
5 | COPY ./requirements.txt /app/requirements.txt
6 |
7 | RUN apt-get update \
8 | && apt-get install gcc -y \
9 | && apt-get clean
10 |
11 | RUN pip install -r /app/requirements.txt \
12 | && rm -rf /root/.cache/pip
13 |
14 | COPY . /app/
15 |
--------------------------------------------------------------------------------
/price-service/app/api/models.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Models to price-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Pydantic models to make docs and check types
24 | """
25 |
26 | from pydantic import BaseModel
27 | from typing import List, Optional
28 |
29 |
30 | class PriceIn(BaseModel):
31 | price_net: int
32 | customer_class: str
33 | vat_percentage: int
34 |
35 | class PriceOut(BaseModel):
36 | price_net: int
37 | price_gross: int
38 |
--------------------------------------------------------------------------------
/price-service/app/api/prices.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Routers for price-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Routers for operations with API
24 | """
25 |
26 | from typing import List
27 | from fastapi import APIRouter, HTTPException
28 |
29 | from app.api.models import PriceIn, PriceOut
30 |
31 | router = APIRouter()
32 |
33 |
34 | def rebate_class(price, customer_class):
35 | if customer_class == "Reseller":
36 | price *= 0.95
37 | elif customer_class == "ResellerHighVolume":
38 | price *= 0.93
39 | return price
40 |
41 | def rebate_quantity(price, quantity):
42 | if quantity > 50:
43 | price *= 0.98
44 | elif quantity > 10:
45 | price *= 0.99
46 | return price
47 |
48 | @router.get('/', response_model=PriceOut)
49 | async def get_price(quantity: int,
50 | price_net: int,
51 | vat_percentage: int,
52 | customer_class: str):
53 | price_net = rebate_class(price_net, customer_class)
54 | price_net = rebate_quantity(price_net, quantity)
55 | price_net *= quantity
56 | price_gross = price_net * (1 + vat_percentage / 100)
57 | response = {
58 | "price_net": price_net,
59 | "price_gross": price_gross
60 | }
61 | return response
62 |
--------------------------------------------------------------------------------
/price-service/app/main.py:
--------------------------------------------------------------------------------
1 | from fastapi import FastAPI
2 | from app.api.prices import router as prices_router
3 |
4 | app = FastAPI(openapi_url="/api/v1/prices/openapi.json",
5 | docs_url="/api/v1/prices/docs")
6 |
7 | app.include_router(prices_router, prefix='/api/v1/prices', tags=['prices'])
--------------------------------------------------------------------------------
/price-service/requirements.txt:
--------------------------------------------------------------------------------
1 | anyio==3.5.0
2 | asgiref==3.5.0
3 | asyncpg==0.25.0
4 | click==8.1.2
5 | databases==0.5.5
6 | fastapi==0.75.2
7 | greenlet==1.1.2
8 | h11==0.13.0
9 | idna==3.3
10 | psycopg2-binary==2.9.3
11 | pydantic==1.9.0
12 | sniffio==1.2.0
13 | SQLAlchemy==1.4.36
14 | starlette==0.17.1
15 | typing-extensions==4.2.0
16 | uvicorn==0.17.6
17 |
--------------------------------------------------------------------------------
/product-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.9-slim
2 |
3 | WORKDIR /app
4 |
5 | COPY ./requirements.txt /app/requirements.txt
6 |
7 | RUN apt-get update \
8 | && apt-get install gcc -y \
9 | && apt-get clean
10 |
11 | RUN pip install -r /app/requirements.txt \
12 | && rm -rf /root/.cache/pip
13 |
14 | COPY . /app/
15 |
--------------------------------------------------------------------------------
/product-service/app/api/db.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | DB module for product-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Make engine, connection to DB and tables
24 | """
25 |
26 | import os
27 | import sqlalchemy
28 | from databases import Database
29 |
30 | DATABASE_URI = os.getenv('DATABASE_URI')
31 | #DATABASE_URI = "postgresql://postgres:postgres@localhost:5432"
32 |
33 | engine = sqlalchemy.create_engine(DATABASE_URI)
34 | metadata = sqlalchemy.MetaData()
35 |
36 | products = sqlalchemy.Table(
37 | 'products',
38 | metadata,
39 | sqlalchemy.Column('product_id', sqlalchemy.BigInteger, primary_key=True),
40 | sqlalchemy.Column('name', sqlalchemy.String(50)),
41 | sqlalchemy.Column('price_net', sqlalchemy.Integer),
42 | sqlalchemy.Column('status', sqlalchemy.String(50)),
43 | )
44 | #products.drop(engine)
45 | #products.create(engine)
46 |
47 | database = Database(DATABASE_URI)
--------------------------------------------------------------------------------
/product-service/app/api/db_manager.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Manager to work with DB at product-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | CRUD operations to work with DB
24 | """
25 |
26 | from app.api.models import ProductIn, ProductOut, ProductUpdate
27 | from app.api.db import products, database
28 |
29 |
30 | async def add_product(payload: ProductIn):
31 | query = products.insert().values(**payload.dict())
32 | return await database.execute(query=query)
33 |
34 | async def get_all_products(name, status):
35 | if name and status:
36 | query = products.select(products.c.name==name and products.c.status==status)
37 | elif name:
38 | query = products.select(products.c.name==name)
39 | elif status:
40 | query = products.select(products.c.status==status)
41 | else:
42 | query = products.select()
43 | return await database.fetch_all(query=query)
44 |
45 | async def get_product(id):
46 | query = products.select(products.c.product_id==id)
47 | return await database.fetch_one(query=query)
48 |
49 | async def delete_product(id: int):
50 | query = products.delete().where(products.c.product_id==id)
51 | return await database.execute(query=query)
52 |
53 | async def update_product(id: int, payload: ProductIn):
54 | query = (
55 | products
56 | .update()
57 | .where(products.c.product_id == id)
58 | .values(**payload.dict())
59 | )
60 | return await database.execute(query=query)
--------------------------------------------------------------------------------
/product-service/app/api/models.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Models to product-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Pydantic models to make docs and check types
24 | """
25 |
26 | from pydantic import BaseModel
27 | from typing import List, Optional
28 | from enum import Enum
29 |
30 |
31 | class Status(str, Enum):
32 | active = 'Active'
33 | deleted = 'Inactive'
34 |
35 |
36 | class ProductIn(BaseModel):
37 | name: str
38 | price_net: int
39 | status: Status
40 |
41 |
42 | class ProductOut(ProductIn):
43 | product_id: int
44 |
45 |
46 | class ProductUpdate(ProductIn):
47 | name: Optional[str] = None
48 | customer_class: Optional[str] = None
49 | price_net: Optional[int] = None
50 | status: Optional[Status] = None
51 |
--------------------------------------------------------------------------------
/product-service/app/api/products.py:
--------------------------------------------------------------------------------
1 | """
2 | MicroAPI
3 | Routers for product-service
4 | Copyright (C) 2022
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | Author:
20 | Bengart Zakhar
21 |
22 | Description:
23 | Routers for operations with API
24 | """
25 |
26 | from typing import List, Optional
27 | from fastapi import APIRouter, HTTPException
28 |
29 | from app.api.models import ProductOut, ProductIn, ProductUpdate
30 | from app.api import db_manager
31 |
32 | router = APIRouter()
33 |
34 | @router.post('/', response_model=ProductOut, status_code=201)
35 | async def create_product(payload: ProductIn):
36 | product_id = await db_manager.add_product(payload)
37 | response = {
38 | 'product_id': product_id,
39 | **payload.dict()
40 | }
41 | return response
42 |
43 | @router.get('/', response_model=List[ProductOut])
44 | async def get_products(name: Optional[str] = None, status: Optional[str] = None):
45 | return await db_manager.get_all_products(name, status)
46 |
47 | @router.get('/{id}/', response_model=ProductOut)
48 | async def get_product(id: int):
49 | product = await db_manager.get_product(id)
50 | if not product:
51 | raise HTTPException(status_code=404, detail="Product not found")
52 | return product
53 |
54 | @router.put('/{id}/', response_model=ProductOut)
55 | async def update_product(id: int, payload: ProductUpdate):
56 | product = await db_manager.get_product(id)
57 | if not product:
58 | raise HTTPException(status_code=404, detail="Product not found")
59 | update_data = payload.dict(exclude_unset=True)
60 | product_in_db = ProductIn(**product)
61 | updated_product = product_in_db.copy(update=update_data)
62 | return await db_manager.update_product(id, updated_product)
63 |
64 | @router.delete('/{id}', response_model=None)
65 | async def delete_product(id: int):
66 | product = await db_manager.get_product(id)
67 | if not product:
68 | raise HTTPException(status_code=404, detail="Product not found")
69 | return await db_manager.delete_product(id)
70 |
--------------------------------------------------------------------------------
/product-service/app/main.py:
--------------------------------------------------------------------------------
1 | from fastapi import FastAPI
2 | from app.api.products import router as products_router
3 | from app.api.db import metadata, database, engine
4 |
5 | metadata.create_all(engine)
6 |
7 | app = FastAPI(openapi_url="/api/v1/products/openapi.json",
8 | docs_url="/api/v1/products/docs")
9 |
10 | @app.on_event("startup")
11 | async def startup():
12 | await database.connect()
13 |
14 | @app.on_event("shutdown")
15 | async def shutdown():
16 | await database.disconnect()
17 |
18 | app.include_router(products_router, prefix='/api/v1/products', tags=['products'])
--------------------------------------------------------------------------------
/product-service/requirements.txt:
--------------------------------------------------------------------------------
1 | anyio==3.5.0
2 | asgiref==3.5.0
3 | asyncpg==0.25.0
4 | click==8.1.2
5 | databases==0.5.5
6 | fastapi==0.75.2
7 | greenlet==1.1.2
8 | h11==0.13.0
9 | idna==3.3
10 | psycopg2-binary==2.9.3
11 | pydantic==1.9.0
12 | sniffio==1.2.0
13 | SQLAlchemy==1.4.36
14 | starlette==0.17.1
15 | typing-extensions==4.2.0
16 | uvicorn==0.17.6
17 |
--------------------------------------------------------------------------------