generated from Luis/nextjs-python-web-template
Refactored api calls to REST. Clients endpoint is now services without self. repository view is the same as get all services.
This commit is contained in:
@@ -2,15 +2,11 @@ from sqlalchemy import (
|
||||
JSON,
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from .sql_db import Base
|
||||
|
||||
@@ -34,9 +30,6 @@ class Entity(Base):
|
||||
|
||||
## Relations ##
|
||||
services = relationship("Service", back_populates="entity")
|
||||
clients = relationship("Client", back_populates="entity")
|
||||
repository = relationship("Repository", back_populates="entity")
|
||||
# TODO maby refactor to repositories
|
||||
|
||||
|
||||
class ServiceAbstract(Base):
|
||||
@@ -57,55 +50,7 @@ class ServiceAbstract(Base):
|
||||
class Service(ServiceAbstract):
|
||||
__tablename__ = "services"
|
||||
|
||||
# Usage is the clients column
|
||||
|
||||
## Relations ##
|
||||
# One entity can have many services
|
||||
entity = relationship("Entity", back_populates="services")
|
||||
entity_did = Column(String, ForeignKey("entities.did"))
|
||||
|
||||
# One service has many clients
|
||||
clients = relationship("Client", back_populates="service")
|
||||
|
||||
|
||||
class Client(Base):
|
||||
__tablename__ = "clients"
|
||||
|
||||
## Queryable body ##
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
## Non queryable body ##
|
||||
other = Column(JSON)
|
||||
|
||||
## Relations ##
|
||||
# one entity can have many clients
|
||||
entity = relationship("Entity", back_populates="clients")
|
||||
entity_did = Column(String, ForeignKey("entities.did"))
|
||||
|
||||
# one client has one service
|
||||
service = relationship("Service", back_populates="clients")
|
||||
service_uuid = Column(String, ForeignKey("services.uuid"))
|
||||
|
||||
__table_args__ = (UniqueConstraint("service_uuid", "entity_did"),)
|
||||
|
||||
|
||||
class Repository(ServiceAbstract):
|
||||
__tablename__ = "repositories"
|
||||
|
||||
time_created = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# one repository has one entity
|
||||
entity = relationship("Entity", back_populates="repository")
|
||||
entity_did = Column(Integer, ForeignKey("entities.did"))
|
||||
|
||||
|
||||
# TODO: Ask how this works exactly
|
||||
class Resolution(Base):
|
||||
__tablename__ = "resolutions"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
requester_name = Column(String, index=True)
|
||||
requester_did = Column(String, index=True)
|
||||
resolved_did = Column(String, index=True)
|
||||
other = Column(JSON)
|
||||
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
Reference in New Issue
Block a user