-
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
5 changed files
with
95 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,18 @@ | |
"name": "Gabe Lewis", | ||
"dept": "C-Level", | ||
"role": "CEO" | ||
}, | ||
"[email protected]": { | ||
"name": "Pam Beasly", | ||
"dept": "General", | ||
"role": "Recepcionist" | ||
} | ||
}, | ||
"balance": { | ||
"[email protected]": 653, | ||
"[email protected]": 253, | ||
"[email protected]": 200 | ||
"[email protected]": 200, | ||
"[email protected]": 500 | ||
}, | ||
"movement": { | ||
"[email protected]": [ | ||
|
@@ -137,6 +143,13 @@ | |
"actor": "solermvictor", | ||
"value": 100 | ||
} | ||
], | ||
"[email protected]": [ | ||
{ | ||
"date": "2024-07-15T18:20:06.454769", | ||
"actor": "system", | ||
"value": 500 | ||
} | ||
] | ||
}, | ||
"users": { | ||
|
@@ -148,6 +161,9 @@ | |
}, | ||
"[email protected]": { | ||
"password": "SR2jr3iG" | ||
}, | ||
"[email protected]": { | ||
"password": "BdO3tMuX" | ||
} | ||
} | ||
} |
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,3 +1,4 @@ | ||
Jim Halpert, Sales, Salesman, [email protected] | ||
Dwight Schrute, Sales, Manager, [email protected] | ||
Gabe Lewis, C-Level, CEO, [email protected] | ||
Pam Beasly, General, Recepcionist, [email protected] |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""Model of database.""" | ||
|
||
from datetime import datetime | ||
from decimal import Decimal | ||
|
||
from pydantic import BaseModel, field_validator | ||
from dundie.database import connect | ||
|
||
from dundie.utils.email import check_valid_email | ||
|
||
|
||
class InvalidEmailError(Exception): | ||
"""Class that represents an Error for invalid e-mails.""" | ||
|
||
... | ||
|
||
|
||
class Person(BaseModel): | ||
"""Class that represents a person.""" | ||
|
||
pk: str | ||
name: str | ||
dept: str | ||
role: str | ||
|
||
@field_validator("pk") | ||
def validate_email(cls, v): | ||
"""Validate e-mail received as primary key.""" | ||
if not check_valid_email(v): | ||
raise InvalidEmailError(f"Invalid e-mail for {v!r}") | ||
return v | ||
|
||
def __str__(self): | ||
"""Change the visualizing in output for name - role.""" | ||
return f"{self.name} - {self.role}" | ||
|
||
|
||
class Balance(BaseModel): | ||
"""Class that represents the balance of a person.""" | ||
|
||
person: Person | ||
value: Decimal | ||
|
||
@field_validator("value", mode="before") | ||
def value_logic(cls, v): | ||
"""Value Logic.""" | ||
return Decimal(v) * 2 | ||
|
||
class Config: | ||
"""Configuration for json encoder.""" | ||
|
||
json_encoders = {Person: lambda p: p.name} | ||
|
||
|
||
class Movement(BaseModel): | ||
"""Class that represents a the movements of a person.""" | ||
|
||
person: Person | ||
date: datetime | ||
actor: str | ||
value: Decimal | ||
|
||
|
||
db = connect() | ||
|
||
for pk, data in db["people"].items(): | ||
p = Person(pk=pk, **data) | ||
|
||
# print(p) | ||
# print(p.json()) | ||
|
||
|
||
balance = Balance(person=p, value=500) | ||
print(balance) | ||
print(balance.json()) |
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,3 +1,4 @@ | ||
click | ||
rich | ||
rich-click | ||
pydantic |