forked from breatheco-de/apiv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
452 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Serializers | ||
|
||
A serializer is an element (a [class](<https://en.wikipedia.org/wiki/Class_(computer_programming)>) this case) that translates and [object](<https://en.wikipedia.org/wiki/Object_(computer_science)>) ([Object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming)) and generate an output that should be useful by something, in Django a serializer is used to format the object before be sent. We just using the [Django Rest Framework](https://www.django-rest-framework.org) Serializers for POST and PUT methods, for the GET method we are using [Serpy](../serpy/introduction) because it is faster than DRF Serializers. | ||
A serializer is an element (a [class](https://en.wikipedia.org/wiki/Class_(computer_programming)) in this case) that translates an [object](https://en.wikipedia.org/wiki/Object_(computer_science)) ([Object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming)) and generates an output that should be useful for something. In Django, a serializer is used to format the object before it is sent. We are using the [Django Rest Framework](https://www.django-rest-framework.org) Serializers for POST and PUT methods, and for the GET method we are using [Serpy](../../serpy/) because it is faster than DRF Serializers. | ||
|
||
Related articles: | ||
|
||
- [HTTP](https://en.wikipedia.org/wiki/HTTP). | ||
- [REST](https://en.wikipedia.org/wiki/REST). | ||
- [HTTP](https://en.wikipedia.org/wiki/HTTP) | ||
- [REST](https://en.wikipedia.org/wiki/REST) | ||
|
||
## Writing Serializers | ||
|
||
Read [this](https://www.django-rest-framework.org/tutorial/1-serialization/). | ||
|
||
## Where is the admin? | ||
## Where are the serializers? | ||
|
||
It where in `breathecode/APP_NAME/serializers.py`. | ||
They are located in `breathecode/APP_NAME/serializers.py`. |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Running tests | ||
|
||
## Run a test file | ||
|
||
```bash | ||
pipenv run test breathecode/payments/tests/urls/tests_me_service_slug_consumptionsession_hash.py | ||
``` | ||
|
||
### Pytest options | ||
|
||
- `-v`: verbose | ||
- `-vv`: more verbose | ||
- `-s`: don't capture the stdout, useful when the test execution won't end. | ||
- `-k`: only run test methods and classes that match the pattern or substring. | ||
|
||
## Run tests in parallel | ||
|
||
```bash | ||
pipenv run ptest | ||
``` | ||
|
||
## Run tests in parallel in a module | ||
|
||
```bash | ||
pipenv run ptest ./breathecode/ | ||
``` | ||
|
||
## Run coverage in parallel | ||
|
||
```bash | ||
pipenv run pcov | ||
``` | ||
|
||
## Run coverage in parallel in a module | ||
|
||
```bash | ||
pipenv run pcov breathecode.admissions | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# File uploading | ||
|
||
## Steps | ||
|
||
- Get operation type meta. | ||
- Split file into chunks. | ||
- Check if chunk lenght is less than `max_chunks` or `null`. | ||
- Upload each chunk. | ||
- Process the file and send the metadata if required. | ||
- If the file is not processed automatically you should pass the file id to another endpoint. | ||
|
||
### Notes | ||
|
||
- For user uploading, use `/v2/media/me/chunk` and `/v2/media/me/chunk/upload`. | ||
- For academy uploading, use `/v2/media/academy/chunk` and `/v2/media/academy/chunk/upload` with the `Academy` header. | ||
- Status `TRANSFERRING` means that the file is being processed. | ||
- Status `CREATED` means that the `file.id` must be provided to another endpoint for processing. | ||
|
||
## Get available operation types | ||
|
||
### Request | ||
|
||
```http | ||
GET /v2/media/operationtype HTTP/1.1 | ||
Host: breathecode.herokuapp.com | ||
``` | ||
|
||
### Response | ||
|
||
```json | ||
[ | ||
"media", | ||
"proof-of-payment" | ||
] | ||
``` | ||
|
||
## Get operation type meta | ||
|
||
### Request | ||
|
||
```http | ||
GET /v2/media/operationtype/media HTTP/1.1 | ||
Host: breathecode.herokuapp.com | ||
``` | ||
|
||
|
||
### Response | ||
|
||
```json | ||
{ | ||
"chunk_size": 10485760, | ||
"max_chunks": null | ||
} | ||
``` | ||
|
||
## Upload chunk | ||
|
||
### Request | ||
|
||
```http | ||
POST /v2/media/me/chunk HTTP/1.1 | ||
Host: breathecode.herokuapp.com | ||
Content-Type: multipart/form-data; boundary=... | ||
{ | ||
"operation_type": "media", | ||
"total_chunks": 3, | ||
"chunk": chunk, | ||
"chunk_index": 0 | ||
} | ||
``` | ||
|
||
### Response | ||
|
||
```json | ||
{ | ||
"academy": null, | ||
"chunk_index": 0, | ||
"mime": "image/png", | ||
"name": "chunk.png", | ||
"operation_type": "media", | ||
"total_chunks": 3, | ||
"user": 1 | ||
} | ||
``` | ||
|
||
## End file uploading and ask for processing | ||
|
||
### Request | ||
|
||
```http | ||
POST /v2/media/me/chunk/upload HTTP/1.1 | ||
Host: breathecode.herokuapp.com | ||
Content-Type: application/json | ||
{ | ||
"operation_type": "media", | ||
"total_chunks": 3, | ||
"filename": "chunk.png", | ||
"mime": "image/png", | ||
"meta": "{\"slug\":\"my-media\",\"name\":\"my-name\",\"categories\":[\"my-category\"],\"academy\":1}" | ||
} | ||
``` | ||
|
||
### Response | ||
|
||
```json | ||
{ | ||
"id": 1, | ||
"academy": null, | ||
"mime": "image/png", | ||
"name": "a291e39ac495b2effd38d508417cd731", | ||
"operation_type": "media", | ||
"user": 1, | ||
"status": "TRANSFERRING" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters