Add additional ORM relations and thumbs in API responses
This commit is contained in:
parent
791a79249c
commit
4272f2878e
9 changed files with 37 additions and 6 deletions
|
@ -25,3 +25,4 @@ class ChargePoint(Base):
|
|||
connectors = relationship("Connector", cascade="delete, delete-orphan")
|
||||
transactions = relationship("Transaction", cascade="delete, delete-orphan")
|
||||
variables = relationship("ChargepointVariable", cascade="delete, delete-orphan")
|
||||
firmware_updates = relationship("FirmwareUpdate", cascade="delete, delete-orphan")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, Integer, String, Text, Uuid
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
from app.schemas.firmware_update import FirmwareUpdateStatus
|
||||
|
@ -20,3 +21,4 @@ class FirmwareUpdate(Base):
|
|||
signature = Column(String, nullable=True)
|
||||
|
||||
chargepoint_id = Column(Uuid, ForeignKey("chargepoints.id"), index=True)
|
||||
chargepoint = relationship("ChargePoint", back_populates="firmware_updates")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Uuid, Column, DateTime, Enum, Float, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
from app.schemas.meter_value import Measurand, PhaseType
|
||||
|
@ -14,4 +15,5 @@ class MeterValue(Base):
|
|||
unit = Column(String, nullable=True)
|
||||
value = Column(Float)
|
||||
|
||||
transaction_id = Column(String, ForeignKey("transactions.id"), index=True)
|
||||
transaction_id = Column(String, ForeignKey("transactions.id"), index=True)
|
||||
transaction = relationship("Transaction", back_populates="meter_values")
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String, Uuid
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
@ -11,4 +12,5 @@ class Session(Base):
|
|||
refresh_token = Column(String, nullable=False, unique=True, index=True)
|
||||
last_used = Column(DateTime(timezone=True))
|
||||
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user = relationship("User", back_populates="sessions")
|
|
@ -1,4 +1,5 @@
|
|||
from sqlalchemy import String, Uuid, Column, DateTime, Enum, Numeric, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.schemas.transaction import TransactionEventTriggerReason, TransactionStatus
|
||||
from app.database import Base
|
||||
|
@ -16,4 +17,9 @@ class Transaction(Base):
|
|||
price = Column(Numeric(10,2))
|
||||
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=True, index=True)
|
||||
user = relationship("User", back_populates="transactions")
|
||||
|
||||
chargepoint_id = Column(Uuid, ForeignKey("chargepoints.id"), index=True)
|
||||
chargepoint = relationship("ChargePoint", back_populates="transactions")
|
||||
|
||||
meter_values = relationship("MeterValue", cascade="delete, delete-orphan")
|
||||
|
|
|
@ -17,3 +17,4 @@ class User(Base):
|
|||
|
||||
id_tokens = relationship("IdToken", back_populates="owner", cascade="delete, delete-orphan")
|
||||
transactions = relationship("Transaction", cascade="delete, delete-orphan")
|
||||
sessions = relationship("Session", cascade="delete, delete-orphan")
|
||||
|
|
|
@ -36,6 +36,15 @@ class ChargePoint(ChargePointBase):
|
|||
from_attributes = True
|
||||
json_encoders = {Decimal: decimal_encoder}
|
||||
|
||||
class ChargePointThumb(BaseModel):
|
||||
id: UUID
|
||||
identity: str
|
||||
price: Decimal
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
json_encoders = {Decimal: decimal_encoder}
|
||||
|
||||
class ChargePointPassword(BaseModel):
|
||||
password: str
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import enum
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
import enum
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.schemas.chargepoint import ChargePointThumb
|
||||
from app.schemas.user import UserThumb
|
||||
from app.util.encoders import decimal_encoder
|
||||
|
||||
class TransactionStatus(enum.Enum):
|
||||
|
@ -47,8 +48,8 @@ class Transaction(BaseModel):
|
|||
meter_end: Optional[Decimal] = None
|
||||
end_reason: Optional[TransactionEventTriggerReason] = None
|
||||
price: Decimal
|
||||
user_id: Optional[UUID] = None
|
||||
chargepoint_id: UUID
|
||||
user: UserThumb
|
||||
chargepoint: ChargePointThumb
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
|
@ -30,6 +30,13 @@ class User(UserBase):
|
|||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class UserThumb(BaseModel):
|
||||
id: UUID
|
||||
friendly_name: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class PasswordUpdate(BaseModel):
|
||||
old_password: str = Field(max_length=100)
|
||||
new_password: str = Field(max_length=100)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue