mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-02-16 19:41:00 +03:00
Add explicit sections for example services
This commit is contained in:
parent
be20a60cb0
commit
294aa0bf24
|
@ -27,6 +27,8 @@
|
||||||
* [Methods](#methods)
|
* [Methods](#methods)
|
||||||
* [Testing](#testing)
|
* [Testing](#testing)
|
||||||
- [Services](#services)
|
- [Services](#services)
|
||||||
|
* [Example - function-based service](#example---function-based-service)
|
||||||
|
* [Example - class-based service](#example---class-based-service)
|
||||||
* [Naming convention](#naming-convention)
|
* [Naming convention](#naming-convention)
|
||||||
* [Modules](#modules)
|
* [Modules](#modules)
|
||||||
* [Selectors](#selectors)
|
* [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.
|
- 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.
|
- 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:
|
An example service that creates a user:
|
||||||
|
|
||||||
```python
|
```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.
|
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.
|
**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:
|
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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user