-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
67 lines (55 loc) · 2.21 KB
/
models.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import List
from dataclasses import dataclass
from datetime import time
from sqlalchemy import Column, Integer, String, Time, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase, relationship
from sqlalchemy_utils.types.encrypted.encrypted_type import StringEncryptedType, AesEngine, AesGcmEngine
from database import Base
@dataclass
class User(Base):
__tablename__ = "users"
id: int
name: str
email: str
phone_number: str
id = Column(Integer, primary_key=True)
name = Column(StringEncryptedType(String, length=120, key='secret', padding='pkcs5'))
email = Column(StringEncryptedType(String, length=120, key='secret', padding='pkcs5'))
phone_number = Column(StringEncryptedType(String, length=255, key='secret', padding='pkcs5'))
payment_methods: Mapped[List["PaymentMethod"]] = relationship()
transactions: Mapped[List["Transactions"]] = relationship()
def __init__(self, id, name=None, email=None, phone_number=None):
self.id = id
self.name = name
self.email = email
self.phone_number = phone_number
def __repr__(self):
return f'<User {self.name!r}>'
@dataclass
class PaymentMethod(Base):
__tablename__ = "payment_methods"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
attrs: str
attrs = Column(StringEncryptedType(String, length=255, key='secret', padding='pkcs5', engine=AesEngine))
def __init__(self, user_id=None, attrs=None):
self.user_id = user_id
self.attrs = attrs
def __repr__(self):
return f'<PaymentMethod {self.id!r}>'
@dataclass
class Transactions(Base):
__tablename__ = "transactions"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
timestamp: time
amount: int
description: str
timestamp = Column(Time)
amount = Column(Integer)
description = Column(StringEncryptedType(String, length=255, key='secret', padding='pkcs5'))
def __init__(self, user_id=None, attrs=None):
self.user_id = user_id
self.attrs = attrs
def __repr__(self):
return f'<User {self.id!r}>'