Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL0809 committed May 22, 2024
1 parent c2f3474 commit 2499989
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 3 additions & 7 deletions api/change_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseModel
from starlette import status

from auth import get_current_active_user
from auth import get_current_active_user, roles_required
from auth_schema import User
from database import get_db
from config import RoomStatus
Expand All @@ -23,7 +23,7 @@
class ChangeRoomRecv(BaseModel):
old_room_number: str
new_room_number: str
client_name: str
client_id: int


class ChangeRoomResp(BaseModel):
Expand Down Expand Up @@ -88,15 +88,11 @@ def get_room_status(db, room_number: str):


@router.post("/change_room", response_model=ChangeRoomResp)
@roles_required("admin")
async def change_room(
change_room_recv: ChangeRoomRecv,
current_user: User = Depends(get_current_active_user),
db: Session = Depends(get_db),
):
if current_user.role != "admin":
return ChangeRoomResp(
status=status.HTTP_401_UNAUTHORIZED, details="没有访问权限"
)
if (
get_room_status(db, change_room_recv.old_room_number) == occupied
and get_room_status(db, change_room_recv.new_room_number) == free
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
version: '3.8'
services:
web:
build: .
image: pccms:latest
ports:
- "8000:80"
depends_on:
- db
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- SHOW_DOCS=true
db:
image: postgres:16-bullseye
environment:
Expand All @@ -16,7 +17,6 @@ services:
POSTGRES_DB: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
command: ["-c", "max_connections=500","-c", "shared_buffers=1024MB"]

volumes:
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from datetime import datetime, timedelta, timezone
from typing import Union

Expand All @@ -23,8 +24,8 @@
from fastapi.middleware.cors import CORSMiddleware

model.Base.metadata.create_all(bind=engine)

app = FastAPI()
SHOW_DOCS = os.getenv("SHOW_DOCS", "false").lower() == "true"
app = FastAPI(docs_url="/docs" if SHOW_DOCS else None)
app.include_router(change_room_router)
app.include_router(reserve_router)
app.include_router(get_all_rooms_router)
Expand Down

0 comments on commit 2499989

Please sign in to comment.