Add explicit sections for example services

This commit is contained in:
Radoslav Georgiev 2022-04-06 14:34:55 +03:00
parent be20a60cb0
commit 294aa0bf24
No known key found for this signature in database
GPG Key ID: 0B7753A4DFCE646D

View File

@ -27,6 +27,8 @@
* [Methods](#methods)
* [Testing](#testing)
- [Services](#services)
* [Example - function-based service](#example---function-based-service)
* [Example - class-based service](#example---class-based-service)
* [Naming convention](#naming-convention)
* [Modules](#modules)
* [Selectors](#selectors)
@ -494,6 +496,8 @@ In most cases, a service can be simple function that:
- Interacts with the database, other resources & other parts of your system.
- Does business logic - from simple model creation to complex cross-cutting concerns, to calling external services & tasks.
### Example - function-based service
An example service that creates a user:
```python
@ -516,6 +520,8 @@ As you can see, this service calls 2 other services - `profile_create` and `conf
In this example, everything related to the user creation is in one place and can be traced.
### Example - class-based service
**Additionally, we can have "class-based" services**, which is a fancy way of saying - wrap the logic in a class.
Here's an example, taken straight from the [Django Styleguide Example](https://github.com/HackSoftware/Django-Styleguide-Example/blob/master/styleguide_example/files/services.py#L22), related to file upload: