-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
42 lines (33 loc) · 1003 Bytes
/
model.py
File metadata and controls
42 lines (33 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
""" Database Band Model """
from datetime import datetime
from typing import List
from fastapi.encoders import jsonable_encoder
class Band:
def __init__(self, raw_data: dict):
"""
Expects a dictionary to fill required fields
"""
self._id: str = raw_data["_id"]
self.nome: str = raw_data["nome"]
self.banda: str = raw_data["banda"]
self.ano: str = raw_data["ano"]
self.categorias: List[str] = raw_data["categorias"]
self.data_registro: datetime = raw_data["data_registro"]
def json(self):
"""
Returns parsed json data
"""
return jsonable_encoder(self, exclude_none=True)
if __name__ == "__main__":
# Testing
band = Band(
{
"_id": "nODDmTpAf",
"nome": "All Star",
"banda": "Smash Mouth",
"ano": "1999",
"categorias": ["pop", "rock"],
"data_registro": None,
}
)
print(band.json())