domain
This commit is contained in:
@@ -33,7 +33,7 @@ async def login(
|
||||
expires_delta=access_token_expires,
|
||||
)
|
||||
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
return {"access_token": access_token, "token_type": "bearer","user_name":user.first_name + " " + user.last_name,"user_id" : user.id}
|
||||
|
||||
|
||||
@r.post("/signup")
|
||||
|
||||
@@ -140,18 +140,17 @@ async def flow_delete(
|
||||
return delete_flow(db, flowid)
|
||||
|
||||
@r.get(
|
||||
"/domain/{userid}",
|
||||
"/domains/{tenantid}",
|
||||
response_model=List[Domain],
|
||||
response_model_exclude_none=True,
|
||||
)
|
||||
async def domain_details(
|
||||
request: Request,
|
||||
userid: str,
|
||||
tenantid:str,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
domains = get_domain(db, userid)
|
||||
domains = get_domains(db,tenantid)
|
||||
return domains
|
||||
|
||||
|
||||
@r.post("/domain", response_model=Domain, response_model_exclude_none=True)
|
||||
async def domain_create(
|
||||
@@ -174,16 +173,79 @@ async def domain_edit(
|
||||
|
||||
|
||||
@r.delete(
|
||||
"/domain/{userid}/{id}", response_model=Domain, response_model_exclude_none=True
|
||||
"/domain/{id}", response_model=Domain, response_model_exclude_none=True
|
||||
)
|
||||
async def domain_delete(
|
||||
request: Request,
|
||||
userid: int,
|
||||
id: int,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
|
||||
return delete_domain(db, userid,id)
|
||||
return delete_domain(db,id)
|
||||
|
||||
@r.get(
|
||||
"/domain/{userid}",
|
||||
response_model=List[Domain],
|
||||
response_model_exclude_none=True,
|
||||
)
|
||||
async def userdomain_details(
|
||||
request: Request,
|
||||
userid: str,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
domains = get_domain(db, userid)
|
||||
return domains
|
||||
|
||||
@r.post(
|
||||
"/domain/{userid}",
|
||||
response_model_exclude_none=True,
|
||||
)
|
||||
async def create_userdomain(
|
||||
request: Request,
|
||||
userid: int,
|
||||
domainids:list,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
domain = add_userdomain(db, userid,domainids)
|
||||
return domain
|
||||
|
||||
@r.delete(
|
||||
"/domain/{domainid}/{userid}", response_model_exclude_none=True
|
||||
)
|
||||
async def userdomain_delete(
|
||||
request: Request,
|
||||
domainid:int,
|
||||
userid: int,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
return delete_userdomain(db, userid,domainid)
|
||||
|
||||
|
||||
@r.get(
|
||||
"/activedomain/{userid}",
|
||||
response_model=Domain,
|
||||
response_model_exclude_none=True,
|
||||
)
|
||||
async def get_useractivedomain(
|
||||
request: Request,
|
||||
userid: int,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
domain = get_activedomain(db, userid)
|
||||
return domain
|
||||
|
||||
@r.put(
|
||||
"/activedomain/{userid}/{domainid}",
|
||||
response_model_exclude_none=True,
|
||||
)
|
||||
async def update_activeuserdomain(
|
||||
request: Request,
|
||||
userid: int,
|
||||
domainid:int,
|
||||
db=Depends(get_db),
|
||||
):
|
||||
domain = active_userdomain(db, userid,domainid)
|
||||
return domain
|
||||
|
||||
|
||||
@r.get(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import and_
|
||||
import typing as t
|
||||
|
||||
from . import models, schemas
|
||||
@@ -182,8 +183,8 @@ def get_flows_by_app(db: Session, appid: str):
|
||||
return flows
|
||||
|
||||
def create_domain(db: Session, domain: schemas.DomainBase):
|
||||
db_domain = models.UserDomain(
|
||||
userid=domain.userid,
|
||||
db_domain = models.Domain(
|
||||
tenantid = domain.tenantid,
|
||||
name=domain.name,
|
||||
url=domain.url,
|
||||
kintoneuser=domain.kintoneuser,
|
||||
@@ -194,9 +195,9 @@ def create_domain(db: Session, domain: schemas.DomainBase):
|
||||
db.refresh(db_domain)
|
||||
return db_domain
|
||||
|
||||
def delete_domain(db: Session, userid: int,id: int):
|
||||
db_domain = db.query(models.UserDomain).get(id)
|
||||
if not db_domain or db_domain.userid != userid:
|
||||
def delete_domain(db: Session,id: int):
|
||||
db_domain = db.query(models.Domain).get(id)
|
||||
if not db_domain:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||
db.delete(db_domain)
|
||||
db.commit()
|
||||
@@ -206,8 +207,8 @@ def delete_domain(db: Session, userid: int,id: int):
|
||||
def edit_domain(
|
||||
db: Session, domain: schemas.DomainBase
|
||||
) -> schemas.Domain:
|
||||
db_domain = db.query(models.UserDomain).get(domain.id)
|
||||
if not db_domain or db_domain.userid != domain.userid:
|
||||
db_domain = db.query(models.Domain).get(domain.id)
|
||||
if not db_domain:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||
update_data = domain.dict(exclude_unset=True)
|
||||
|
||||
@@ -220,8 +221,52 @@ def edit_domain(
|
||||
db.refresh(db_domain)
|
||||
return db_domain
|
||||
|
||||
def add_userdomain(db: Session, userid:int,domainids:list):
|
||||
for domainid in domainids:
|
||||
db_domain = models.UserDomain(
|
||||
userid = userid,
|
||||
domainid = domainid
|
||||
)
|
||||
db.add(db_domain)
|
||||
db.commit()
|
||||
db.refresh(db_domain)
|
||||
return db_domain
|
||||
|
||||
def delete_userdomain(db: Session, userid: int,domainid: int):
|
||||
db_domain = db.query(models.UserDomain).filter(and_(models.UserDomain.userid == userid,models.UserDomain.domainid == domainid)).first()
|
||||
if not db_domain:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||
db.delete(db_domain)
|
||||
db.commit()
|
||||
return db_domain
|
||||
|
||||
def active_userdomain(db: Session, userid: int,domainid: int):
|
||||
db_userdomains = db.query(models.UserDomain).filter(models.UserDomain.userid == userid).all()
|
||||
if not db_userdomains:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||
for domain in db_userdomains:
|
||||
if domain.domainid == domainid:
|
||||
domain.active = True
|
||||
else:
|
||||
domain.active = False
|
||||
db.add(domain)
|
||||
db.commit()
|
||||
return db_userdomains
|
||||
|
||||
def get_activedomain(db: Session, userid: int):
|
||||
db_domain = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(and_(models.UserDomain.userid == userid,models.UserDomain.active == True)).first()
|
||||
if not db_domain:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||
return db_domain
|
||||
|
||||
def get_domain(db: Session, userid: str):
|
||||
domains = db.query(models.UserDomain).filter(models.UserDomain.userid == userid).all()
|
||||
domains = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(models.UserDomain.userid == userid).all()
|
||||
if not domains:
|
||||
raise HTTPException(status_code=404, detail="Data not found")
|
||||
return domains
|
||||
|
||||
def get_domains(db: Session,tenantid:str):
|
||||
domains = db.query(models.Domain).filter(models.Domain.tenantid == tenantid ).all()
|
||||
if not domains:
|
||||
raise HTTPException(status_code=404, detail="Data not found")
|
||||
return domains
|
||||
|
||||
@@ -50,14 +50,30 @@ class Flow(Base):
|
||||
name = Column(String(200))
|
||||
content = Column(String)
|
||||
|
||||
class UserDomain(Base):
|
||||
__tablename__ = "userdomain"
|
||||
class Tenant(Base):
|
||||
__tablename__ = "tenant"
|
||||
|
||||
userid = Column(Integer,ForeignKey("user.id"))
|
||||
tenantid = Column(String(100), index=True, nullable=False)
|
||||
name = Column(String(200))
|
||||
licence = Column(String(200))
|
||||
startdate = Column(DateTime)
|
||||
enddate = Column(DateTime)
|
||||
|
||||
class Domain(Base):
|
||||
__tablename__ = "domain"
|
||||
|
||||
tenantid = Column(String(100), index=True, nullable=False)
|
||||
name = Column(String(100), nullable=False)
|
||||
url = Column(String(200), nullable=False)
|
||||
kintoneuser = Column(String(100), nullable=False)
|
||||
kintonepwd = Column(String(100), nullable=False)
|
||||
|
||||
|
||||
class UserDomain(Base):
|
||||
__tablename__ = "userdomain"
|
||||
|
||||
userid = Column(Integer,ForeignKey("user.id"))
|
||||
domainid = Column(Integer,ForeignKey("domain.id"))
|
||||
active = Column(Boolean, default=False)
|
||||
|
||||
class Event(Base):
|
||||
|
||||
@@ -106,21 +106,19 @@ class Flow(Base):
|
||||
|
||||
class DomainBase(BaseModel):
|
||||
id: int
|
||||
userid: int
|
||||
tenantid: str
|
||||
name: str
|
||||
url: str
|
||||
kintoneuser: str
|
||||
kintonepwd: str
|
||||
active:bool = False
|
||||
|
||||
class Domain(Base):
|
||||
id: int
|
||||
userid: str
|
||||
tenantid: str
|
||||
name: str
|
||||
url: str
|
||||
kintoneuser: str
|
||||
kintonepwd: str
|
||||
active:bool
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
Reference in New Issue
Block a user