Skip to content

Commit 955d9b1

Browse files
My local changes
1 parent 761fa92 commit 955d9b1

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

app/api/routes/auth.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any
33

44
from fastapi import APIRouter, Depends, HTTPException, status
5-
from fastapi.security import OAuth2PasswordRequestForm
65
from sqlalchemy.orm import Session
76

87
from app.api.deps import get_current_user
@@ -11,22 +10,34 @@
1110
from app.crud.crud_user import user
1211
from app.schemas.user import User, UserCreate, Token
1312
from app.db.session import get_db
13+
from pydantic import BaseModel, EmailStr
1414

1515
router = APIRouter()
1616

1717

18+
class LoginRequest(BaseModel):
19+
email: EmailStr = "demo@example.com"
20+
password: str = "password123"
21+
22+
class Config:
23+
schema_extra = {
24+
"example": {"email": "user@example.com", "password": "supersecret"}
25+
}
26+
27+
1828
@router.post("/login", response_model=Token, status_code=status.HTTP_200_OK)
1929
def login_access_token(
20-
db: Session = Depends(get_db), form_data: OAuth2PasswordRequestForm = Depends()
30+
login_data: LoginRequest,
31+
db: Session = Depends(get_db)
2132
) -> Any:
2233
"""
23-
OAuth2 compatible token login, get an access token for future requests.
34+
Token login with JSON, get an access token for future requests.
2435
25-
- **username**: Email address
36+
- **email**: Email address
2637
- **password**: User password
2738
"""
2839
user_obj = user.authenticate(
29-
db, email=form_data.username, password=form_data.password
40+
db, email=login_data.email, password=login_data.password
3041
)
3142
if not user_obj:
3243
raise HTTPException(
@@ -70,10 +81,9 @@ def create_user(
7081

7182
@router.get("/me", response_model=User)
7283
def read_users_me(
73-
84+
current_user: User = Depends(get_current_user)
7485
) -> Any:
7586
"""
7687
Get current user.
7788
"""
78-
current_user = Depends(get_current_user)
7989
return current_user

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def custom_openapi():
8585

8686
@app.get("/", tags=["Root"])
8787
async def root():
88-
return {"message": "Welcome to the Healthcare Appointment System API"}
88+
return {"message": "Welcome to the Healthcare Appointment System API /docs for docs"}
8989

9090
@app.get("/health", tags=["Health"])
9191
async def health_check(db: Session = Depends(get_db)):

app/schemas/doctor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,3 @@ class Availability(AvailabilityInDBBase):
6767

6868
class DoctorWithAvailability(Doctor):
6969
availabilities: List[Availability] = []
70-

0 commit comments

Comments
 (0)