jwt&dbの操作 実装
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from app.db.session import *
|
||||
from app.db.models import *
|
||||
@@ -67,3 +67,52 @@ def edit_user(
|
||||
db.commit()
|
||||
db.refresh(db_user)
|
||||
return db_user
|
||||
|
||||
|
||||
def get_appsetting(db: Session, id: int):
|
||||
app = db.query(models.AppSetting).get(id)
|
||||
if not app:
|
||||
raise HTTPException(status_code=404, detail="App not found")
|
||||
return app
|
||||
|
||||
def create_appsetting(db: Session, app: schemas.AppBase):
|
||||
db_app = models.AppSetting(
|
||||
appid=app.appid,
|
||||
setting=app.setting,
|
||||
)
|
||||
db.add(db_app)
|
||||
db.commit()
|
||||
db.refresh(db_app)
|
||||
return db_app
|
||||
|
||||
def delete_appsetting(db: Session, id: int):
|
||||
app = get_appsetting(db, id)
|
||||
if not app:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="App not found")
|
||||
db.delete(app)
|
||||
db.commit()
|
||||
return app
|
||||
|
||||
|
||||
def edit_appsetting(
|
||||
db: Session, id: int, app: schemas.AppBase
|
||||
) -> schemas.App:
|
||||
db_app = get_appsetting(db, id)
|
||||
if not db_app:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="App not found")
|
||||
update_data = app.dict(exclude_unset=True)
|
||||
|
||||
for key, value in update_data.items():
|
||||
setattr(db_app, key, value)
|
||||
|
||||
db.add(db_app)
|
||||
db.commit()
|
||||
db.refresh(db_app)
|
||||
return db_app
|
||||
|
||||
|
||||
def get_kintones(db: Session, type: int):
|
||||
kintones = db.query(models.Kintone).filter(models.Kintone.type == type).all()
|
||||
if not kintones:
|
||||
raise HTTPException(status_code=404, detail="Data not found")
|
||||
return kintones
|
||||
@@ -7,9 +7,25 @@ class User(Base):
|
||||
__tablename__ = "user"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String, unique=True, index=True, nullable=False)
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
hashed_password = Column(String, nullable=False)
|
||||
email = Column(String(50), unique=True, index=True, nullable=False)
|
||||
first_name = Column(String(100))
|
||||
last_name = Column(String(100))
|
||||
hashed_password = Column(String(200), nullable=False)
|
||||
is_active = Column(Boolean, default=True)
|
||||
is_superuser = Column(Boolean, default=False)
|
||||
|
||||
class AppSetting(Base):
|
||||
__tablename__ = "appsetting"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
appid = Column(String(100), index=True, nullable=False)
|
||||
setting = Column(String(1000))
|
||||
|
||||
class Kintone(Base):
|
||||
__tablename__ = "kintone"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
type = Column(Integer, index=True, nullable=False)
|
||||
name = Column(String(100), nullable=False)
|
||||
desc = Column(String(500))
|
||||
content = Column(String(2000))
|
||||
@@ -43,3 +43,29 @@ class Token(BaseModel):
|
||||
class TokenData(BaseModel):
|
||||
email: str = None
|
||||
permissions: str = "user"
|
||||
|
||||
|
||||
class AppEdit(BaseModel):
|
||||
setting: str = None
|
||||
|
||||
class AppBase(BaseModel):
|
||||
appid: str
|
||||
setting: str = None
|
||||
|
||||
|
||||
class App(AppBase):
|
||||
id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class Kintone(BaseModel):
|
||||
id: int
|
||||
type: int
|
||||
name: str = None
|
||||
desc: str = None
|
||||
content: str = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
Reference in New Issue
Block a user