Skip to content

Commit 5dfe968

Browse files
Style: Auto-formatting fixes (Black)
1 parent aab3494 commit 5dfe968

File tree

20 files changed

+146
-129
lines changed

20 files changed

+146
-129
lines changed

app/api/deps.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
from app.schemas.user import UserResponse
1919

2020
# OAuth2 scheme for JWT token in Authorization header
21-
reusable_oauth2 = OAuth2PasswordBearer(
22-
tokenUrl=f"{settings.api_v1_str}/admin/auth/login"
23-
)
21+
reusable_oauth2 = OAuth2PasswordBearer(tokenUrl=f"{settings.api_v1_str}/admin/auth/login")
2422
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
2523

2624

@@ -41,14 +39,14 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
4139
async def get_current_user(session: SessionDep, token: TokenDep) -> User:
4240
"""
4341
Dependency to get the current authenticated user from JWT.
44-
42+
4543
Raises:
4644
HTTPException: If token is invalid or user not found.
4745
"""
4846
try:
4947
payload = security.verify_token(token)
5048
if payload is None:
51-
raise HTTPException(
49+
raise HTTPException(
5250
status_code=status.HTTP_401_UNAUTHORIZED,
5351
detail="Could not validate credentials",
5452
headers={"WWW-Authenticate": "Bearer"},
@@ -59,20 +57,19 @@ async def get_current_user(session: SessionDep, token: TokenDep) -> User:
5957
status_code=status.HTTP_403_FORBIDDEN,
6058
detail="Could not validate credentials",
6159
)
62-
60+
6361
user = await user_repo.get(session, token_data.sub) # type: ignore # sub is UUID in string
6462
if not user:
6563
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
66-
64+
6765
if not user.is_active:
6866
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Inactive user")
69-
67+
7068
return user
7169

7270

7371
async def get_current_client(
74-
session: SessionDep,
75-
api_key: str = Security(api_key_header)
72+
session: SessionDep, api_key: str = Security(api_key_header)
7673
) -> Client:
7774
"""
7875
Dependency to authenticate a B2B client via API Key.
@@ -82,28 +79,28 @@ async def get_current_client(
8279
status_code=status.HTTP_401_UNAUTHORIZED,
8380
detail="Missing X-API-Key header",
8481
)
85-
82+
8683
# verify key format
8784
key_hash = auth_client.hash_key(api_key)
88-
85+
8986
# Check DB
9087
db_key = await api_key_repo.get_by_hash(session, key_hash=key_hash)
9188
if not db_key or not db_key.is_valid:
92-
raise HTTPException(
89+
raise HTTPException(
9390
status_code=status.HTTP_401_UNAUTHORIZED,
9491
detail="Invalid or expired API Key",
9592
)
96-
93+
9794
# Update last used (fire and forget / async task in real app)
9895
# db_key.last_used_at = datetime.utcnow()
99-
# await session.commit()
100-
96+
# await session.commit()
97+
10198
if not db_key.client.is_license_valid:
10299
raise HTTPException(
103100
status_code=status.HTTP_403_FORBIDDEN,
104101
detail="Client license expired or inactive",
105102
)
106-
103+
107104
return db_key.client
108105

109106

@@ -113,9 +110,9 @@ def get_content_service() -> "ContentService":
113110
In a real app with more complex deps, this could initialize the service.
114111
"""
115112
from app.services.content import ContentService, content_service as _content_service
113+
116114
return _content_service
117115

118116

119117
CurrentUser = Annotated[User, Depends(get_current_user)]
120118
CurrentClient = Annotated[Client, Depends(get_current_client)]
121-

app/api/v1/admin/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ async def login_access_token(
2727
raise HTTPException(
2828
status_code=status.HTTP_400_BAD_REQUEST, detail="Incorrect email or password"
2929
)
30-
30+
3131
if not user.is_active:
3232
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Inactive user")
33-
33+
3434
access_token_expires = timedelta(minutes=settings.jwt_access_token_expire_minutes)
3535
access_token = security.create_access_token(
3636
data={"sub": str(user.id)}, expires_delta=access_token_expires
3737
)
38-
38+
3939
return Token(access_token=access_token, token_type="bearer")

app/api/v1/content/guides.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ async def read_guides(
2626
"""
2727
Retrieve guides (Global + Private).
2828
"""
29-
return await service.get_guides(
30-
session, current_client=current_client, skip=skip, limit=limit
31-
)
29+
return await service.get_guides(session, current_client=current_client, skip=skip, limit=limit)
3230

3331

3432
@router.post("/", response_model=GuideListResponse)
@@ -42,9 +40,7 @@ async def create_guide(
4240
"""
4341
Create a new guide.
4442
"""
45-
return await service.create_guide(
46-
session, current_client=current_client, guide_in=guide_in
47-
)
43+
return await service.create_guide(session, current_client=current_client, guide_in=guide_in)
4844

4945

5046
@router.get("/{guide_id}", response_model=GuideDetailResponse)
@@ -58,9 +54,7 @@ async def read_guide(
5854
"""
5955
Get guide by ID.
6056
"""
61-
guide = await service.get_guide(
62-
session, current_client=current_client, guide_id=guide_id
63-
)
57+
guide = await service.get_guide(session, current_client=current_client, guide_id=guide_id)
6458
if not guide:
6559
raise HTTPException(
6660
status_code=status.HTTP_404_NOT_FOUND,

app/api/v1/content/topics.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ async def read_topics(
2222
Retrieve topics.
2323
Clients only see Global topics or their own Private topics.
2424
"""
25-
return await service.get_topics(
26-
session, current_client=current_client, skip=skip, limit=limit
27-
)
25+
return await service.get_topics(session, current_client=current_client, skip=skip, limit=limit)
2826

2927

3028
@router.post("/", response_model=TopicResponse)
@@ -38,9 +36,7 @@ async def create_topic(
3836
"""
3937
Create a new topic.
4038
"""
41-
return await service.create_topic(
42-
session, current_client=current_client, topic_in=topic_in
43-
)
39+
return await service.create_topic(session, current_client=current_client, topic_in=topic_in)
4440

4541

4642
@router.put("/{topic_id}", response_model=TopicResponse)
@@ -77,9 +73,7 @@ async def read_topic(
7773
"""
7874
Get topic by ID.
7975
"""
80-
topic = await service.get_topic(
81-
session, current_client=current_client, topic_id=topic_id
82-
)
76+
topic = await service.get_topic(session, current_client=current_client, topic_id=topic_id)
8377
if not topic:
8478
raise HTTPException(
8579
status_code=status.HTTP_404_NOT_FOUND,

app/core/auth_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
def generate_api_key(prefix: str = "keng_live_") -> tuple[str, str, str]:
77
"""
88
Generate a new API key.
9-
9+
1010
Returns:
1111
tuple: (full_key, key_hash, key_prefix)
1212
"""
1313
# 32 bytes of randomness encoded as hex (64 chars)
1414
random_part = secrets.token_hex(32)
1515
full_key = f"{prefix}{random_part}"
16-
16+
1717
key_hash = hash_key(full_key)
1818
return full_key, key_hash, prefix
1919

app/models/api_key.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class APIKey(Base):
3838
) # Optional name ("Production Key", etc.)
3939
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False, index=True)
4040
last_used_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
41-
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc))
41+
created_at: Mapped[datetime] = mapped_column(
42+
DateTime, default=lambda: datetime.now(timezone.utc)
43+
)
4244
expires_at: Mapped[datetime | None] = mapped_column(
4345
DateTime, nullable=True
4446
) # None = no expiration

app/models/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class Client(Base):
4141
)
4242
is_active = Column(Boolean, default=True, nullable=False, index=True)
4343
license_expires_at = Column(DateTime, nullable=True) # None = permanent
44-
created_at = Column(
45-
DateTime, default=lambda: datetime.now(timezone.utc), nullable=False
46-
)
44+
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
4745
updated_at = Column(
4846
DateTime,
4947
default=lambda: datetime.now(timezone.utc),

app/models/guide.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class Guide(Base):
5858
SQLEnum(ComplexityLevel), nullable=False, index=True
5959
)
6060
estimated_read_time = Column(Integer, default=0) # minutes
61-
created_at = Column(
62-
DateTime, default=lambda: datetime.now(timezone.utc), nullable=False
63-
)
61+
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
6462
updated_at = Column(
6563
DateTime,
6664
default=lambda: datetime.now(timezone.utc),

app/models/section.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ class Section(Base):
4747
content = Column(Text, nullable=False) # Markdown content
4848
order = Column(Integer, nullable=False, index=True) # For sequencing
4949
section_type: Mapped[SectionType] = mapped_column(SQLEnum(SectionType), nullable=False)
50-
created_at = Column(
51-
DateTime, default=lambda: datetime.now(timezone.utc), nullable=False
52-
)
50+
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
5351
updated_at = Column(
5452
DateTime,
5553
default=lambda: datetime.now(timezone.utc),

app/models/snippet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class Snippet(Base):
5858
language = Column(String(50), nullable=True) # For code snippets: "python", "bash", etc.
5959
is_featured = Column(Boolean, default=False, nullable=False, index=True)
6060
embedding = Column(Vector(1536)) # OpenAI embeddings dimensionality
61-
created_at = Column(
62-
DateTime, default=lambda: datetime.now(timezone.utc), nullable=False
63-
)
61+
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
6462

6563
# Relationships
6664
section: Mapped[Optional["Section"]] = relationship("Section", back_populates="snippets")

0 commit comments

Comments
 (0)