mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
import os
|
|
from fastapi_users_db_sqlalchemy import GUID
|
|
from sqlalchemy import Column, Integer, String, Float, ForeignKey, Date, func
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy_utils import EncryptedType
|
|
from sqlalchemy_utils.types.encrypted.encrypted_type import FernetEngine
|
|
|
|
from app.core.base import Base
|
|
from app.models.categories import association_table
|
|
|
|
SECRET_KEY = os.environ.get("DB_ENCRYPTION_KEY", "localdev")
|
|
|
|
|
|
class Transaction(Base):
|
|
__tablename__ = "transaction"
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
amount = Column(EncryptedType(Float, SECRET_KEY, engine=FernetEngine), nullable=False)
|
|
description = Column(EncryptedType(String(length=255), SECRET_KEY, engine=FernetEngine), nullable=True)
|
|
date = Column(Date, nullable=False, server_default=func.current_date())
|
|
user_id = Column(GUID, ForeignKey("user.id"), nullable=False)
|
|
|
|
# Relationship
|
|
user = relationship("User", back_populates="transactions")
|
|
categories = relationship("Category", secondary=association_table, back_populates="transactions", passive_deletes=True)
|