xbackend/api/api_v1/endpoints/dashboard.py
2021-04-30 09:36:12 +08:00

69 lines
2.7 KiB
Python

from datetime import timedelta
from typing import Any, List
from fastapi import APIRouter, Body, Depends, HTTPException, Request
from sqlalchemy.orm import Session
import crud, models, schemas
from api import deps
router = APIRouter()
@router.get('/')
def read_dashboard(project_id: int = Depends(deps.check_project),
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
dashboard = crud.authority.get_my_dashboard(db=db, project_id=project_id, user_id=current_user.id)
return dashboard
# 新建看板
@router.post("/create-dashboard")
def create_dashboard(dashboard_in: schemas.DashboardCreate,
project_id: int = Depends(deps.check_project),
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)) -> Any:
dashboard = crud.dashboard.create_with_dashboard(db=db, obj_in=dashboard_in, user_id=current_user.id)
# 自己创建的拥有权限
crud.authority.create_with_authority(db=db, obj_in=schemas.AuthorityCreate(
dashboard_id=dashboard.id,
project_id=project_id,
authority='rw',
space_id=dashboard.space_id,
folder_id=dashboard.folder_id
), user_id=current_user.id)
return {"msg": "新建成功", 'code': 0}
@router.post("/create-folder")
def create_folder(folder_in: schemas.FolderCreate, project_id: int = Depends(deps.check_project),
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)) -> Any:
folder = crud.folder.create_with_folder(db=db, obj_in=folder_in, user_id=current_user.id, project_id=project_id)
# 自己创建的拥有权限
crud.authority.create_with_authority(db=db, obj_in=schemas.AuthorityCreate(
project_id=project_id,
authority='rw',
space_id=folder.space_id,
folder_id=folder.id
), user_id=current_user.id)
return {"msg": "新建成功", 'code': 0}
@router.post("/create-space")
def create_space(space_in: schemas.SpaceCreate, project_id: int = Depends(deps.check_project),
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)) -> Any:
space = crud.space.create_with_space(db=db, obj_in=space_in, user_id=current_user.id,project_id=project_id)
# 自己创建的拥有权限
crud.authority.create_with_authority(db=db, obj_in=schemas.AuthorityCreate(
project_id=project_id,
authority='rw',
space_id=space.id,
), user_id=current_user.id)
return {"msg": "新建成功", 'code': 0}