Skip to content

Commit a0178b3

Browse files
[pre-commit.ci] auto fixes from pre-commit hooks
1 parent 7fc1ad8 commit a0178b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1663
-1664
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"""pdfGUI Migration Backend - FastAPI Application"""
2+
23
__version__ = "1.0.0"
Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
"""API dependencies."""
2+
3+
from uuid import UUID
4+
25
from fastapi import Depends, HTTPException, status
3-
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
6+
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
47
from sqlalchemy.orm import Session
8+
59
from ..core.database import get_db
610
from ..core.security import decode_token
711
from ..models.user import User
8-
from uuid import UUID
912

1013
security = HTTPBearer()
1114

1215

1316
def get_current_user(
14-
credentials: HTTPAuthorizationCredentials = Depends(security),
15-
db: Session = Depends(get_db)
17+
credentials: HTTPAuthorizationCredentials = Depends(security), db: Session = Depends(get_db)
1618
) -> User:
1719
"""Get current authenticated user from JWT token."""
1820
token = credentials.credentials
1921

2022
payload = decode_token(token)
2123
if not payload:
22-
raise HTTPException(
23-
status_code=status.HTTP_401_UNAUTHORIZED,
24-
detail="Invalid or expired token"
25-
)
24+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid or expired token")
2625

2726
if payload.get("type") != "access":
28-
raise HTTPException(
29-
status_code=status.HTTP_401_UNAUTHORIZED,
30-
detail="Invalid token type"
31-
)
27+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token type")
3228

3329
user_id = payload.get("sub")
3430
if not user_id:
35-
raise HTTPException(
36-
status_code=status.HTTP_401_UNAUTHORIZED,
37-
detail="Invalid token payload"
38-
)
31+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token payload")
3932

4033
user = db.query(User).filter(User.id == UUID(user_id)).first()
4134
if not user:
42-
raise HTTPException(
43-
status_code=status.HTTP_401_UNAUTHORIZED,
44-
detail="User not found"
45-
)
35+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="User not found")
4636

4737
if not user.is_active:
48-
raise HTTPException(
49-
status_code=status.HTTP_403_FORBIDDEN,
50-
detail="User account is disabled"
51-
)
38+
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="User account is disabled")
5239

5340
return user

pdfgui-migration/backend/app/api/v1/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""API v1 router."""
2+
23
from fastapi import APIRouter
3-
from .endpoints import auth, projects, fittings, phases, datasets, files
4+
5+
from .endpoints import auth, datasets, files, fittings, phases, projects
46

57
api_router = APIRouter()
68

pdfgui-migration/backend/app/api/v1/endpoints/auth.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Authentication endpoints."""
2-
from fastapi import APIRouter, Depends, HTTPException, status, Request
2+
3+
from fastapi import APIRouter, Depends, HTTPException, Request, status
34
from sqlalchemy.orm import Session
5+
46
from ....core.database import get_db
5-
from ....schemas.user import UserCreate, UserLogin, UserResponse, Token, TokenRefresh
7+
from ....schemas.user import Token, TokenRefresh, UserCreate, UserLogin, UserResponse
68
from ....services.auth_service import AuthService
79

810
router = APIRouter()
@@ -17,39 +19,29 @@ def register(user_data: UserCreate, db: Session = Depends(get_db)):
1719
email=user_data.email,
1820
password=user_data.password,
1921
first_name=user_data.first_name,
20-
last_name=user_data.last_name
22+
last_name=user_data.last_name,
2123
)
2224
return user
2325
except ValueError as e:
2426
raise HTTPException(status_code=400, detail=str(e))
2527

2628

2729
@router.post("/login", response_model=Token)
28-
def login(
29-
credentials: UserLogin,
30-
request: Request,
31-
db: Session = Depends(get_db)
32-
):
30+
def login(credentials: UserLogin, request: Request, db: Session = Depends(get_db)):
3331
"""Authenticate user and get tokens."""
3432
auth_service = AuthService(db)
3533
user = auth_service.authenticate(credentials.email, credentials.password)
3634

3735
if not user:
38-
raise HTTPException(
39-
status_code=status.HTTP_401_UNAUTHORIZED,
40-
detail="Invalid credentials"
41-
)
36+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
4237

4338
if not user.is_active:
44-
raise HTTPException(
45-
status_code=status.HTTP_403_FORBIDDEN,
46-
detail="User account is disabled"
47-
)
39+
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="User account is disabled")
4840

4941
tokens = auth_service.create_session(
5042
user,
5143
ip_address=request.client.host if request.client else None,
52-
user_agent=request.headers.get("user-agent")
44+
user_agent=request.headers.get("user-agent"),
5345
)
5446

5547
return tokens
@@ -62,10 +54,7 @@ def refresh_token(token_data: TokenRefresh, db: Session = Depends(get_db)):
6254
tokens = auth_service.refresh_access_token(token_data.refresh_token)
6355

6456
if not tokens:
65-
raise HTTPException(
66-
status_code=status.HTTP_401_UNAUTHORIZED,
67-
detail="Invalid refresh token"
68-
)
57+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid refresh token")
6958

7059
return tokens
7160

0 commit comments

Comments
 (0)