Skip to content

Commit f28fc84

Browse files
authored
Merge pull request #2 from partner-up-dev:copilot/refactor-main-communication-usage
Refactor settings to pydantic-settings with nested models and remove simple CRUD endpoints
2 parents de3b832 + 6ac97e5 commit f28fc84

File tree

17 files changed

+567
-551
lines changed

17 files changed

+567
-551
lines changed

.env.example

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# ====================================
22
# Environment Variables Configuration
33
# ====================================
4-
# Copy this file to .env and fill in your actual SECRET values
4+
# For production: Copy this file to /run/secrets/.env and fill in your actual SECRET values
5+
# For development: Copy this file to .env and set ENV_FILE=.env
6+
#
7+
# The default env file location is /run/secrets/.env
8+
# Override with: export ENV_FILE=.env (for development)
9+
#
510
# DO NOT commit the .env file to version control
11+
#
12+
# Settings use nested delimiter '__' to map to nested model fields.
13+
# Example: DATABASE__URL maps to settings.database.url
614
# ====================================
715

816
# Environment (development, production)
@@ -12,59 +20,59 @@ ENV=development
1220
# Database Configuration
1321
# ====================================
1422
# PostgreSQL connection URL
15-
DATABASE_URL=postgresql://user:password@localhost:5432/partnerup
23+
DATABASE__URL=postgresql://user:password@localhost:5432/partnerup
1624

1725
# ====================================
1826
# Redis Configuration
1927
# ====================================
20-
REDIS_HOST=localhost
21-
REDIS_PORT=6379
22-
REDIS_PASSWORD=your-redis-password
23-
REDIS_DB=0
28+
REDIS__HOST=localhost
29+
REDIS__PORT=6379
30+
REDIS__PASSWORD=your-redis-password
31+
REDIS__DB=0
2432

2533
# ====================================
2634
# Auth / JWT Configuration
2735
# ====================================
28-
JWT_SECRET_KEY=your-jwt-secret-key-here
29-
JWT_ALGORITHMS=["HS256"]
30-
JWT_ALLOWED_AUDIENCES=authenticated,anon,service_role
36+
AUTH__JWT_SECRET_KEY=your-jwt-secret-key-here
37+
AUTH__JWT_ALGORITHMS=["HS256"]
38+
AUTH__JWT_ALLOWED_AUDIENCES=authenticated,anon,service_role
3139

3240
# ====================================
3341
# HTTP Server Configuration
3442
# ====================================
35-
HTTP_HOST=0.0.0.0
36-
HTTP_PORT=8000
37-
HTTP_REAL_HOST=localhost
43+
HTTP__HOST=0.0.0.0
44+
HTTP__PORT=8000
45+
HTTP__REAL_HOST=localhost
3846

3947
# ====================================
4048
# Supabase Configuration
4149
# ====================================
42-
SUPABASE_URL=https://your-project.supabase.co
43-
SUPABASE_SERV_KEY=your-service-key-here
44-
SUPABASE_ANON_KEY=your-anon-key-here
50+
SUPABASE__URL=https://your-project.supabase.co
51+
SUPABASE__SERV_KEY=your-service-key-here
52+
SUPABASE__ANON_KEY=your-anon-key-here
4553

4654
# ====================================
4755
# WeChat Configuration
4856
# ====================================
4957
# WeChat Mini Program
50-
WEIXIN_PARTNER_UP_WXMP_APPID=wx7674f72ff1eb49e6
51-
WEIXIN_PARTNER_UP_WXMP_SECRET=your-wxmp-secret-here
58+
WEIXIN__PARTNER_UP_WXMP_APPID=wx7674f72ff1eb49e6
59+
WEIXIN__PARTNER_UP_WXMP_SECRET=your-wxmp-secret-here
5260

5361
# WeChat Service Account
54-
WEIXIN_PARTNER_UP_WXSA_APPID=your-wxsa-appid-here
55-
WEIXIN_PARTNER_UP_WXSA_SECRET=your-wxsa-secret-here
62+
WEIXIN__PARTNER_UP_WXSA_APPID=your-wxsa-appid-here
63+
WEIXIN__PARTNER_UP_WXSA_SECRET=your-wxsa-secret-here
5664

5765
# ====================================
5866
# WeChat Pay Configuration
5967
# ====================================
60-
WECHAT_PAY_MCHID=your-merchant-id
61-
WECHAT_PAY_PRI_KEY_PATH=data/keys/wechat_pay_private_key.pem
62-
WECHAT_PAY_SERIAL_NO=your-serial-number
63-
WECHAT_PAY_API_V3_KEY=your-api-v3-key-here
64-
WECHAT_PAY_SIGN_TYPE=RSA
65-
WECHAT_PAY_CERT_DIR=data/keys/wechat_pay_certs
68+
WECHAT_PAY__MCHID=your-merchant-id
69+
WECHAT_PAY__PRI_KEY_PATH=data/keys/wechat_pay_private_key.pem
70+
WECHAT_PAY__SERIAL_NO=your-serial-number
71+
WECHAT_PAY__API_V3_KEY=your-api-v3-key-here
72+
WECHAT_PAY__SIGN_TYPE=RSA
73+
WECHAT_PAY__CERT_DIR=data/keys/wechat_pay_certs
6674

6775
# ====================================
6876
# LBS Configuration
6977
# ====================================
70-
LBS_APIKEY=your-lbs-api-key-here
78+
LBS__APIKEY=your-lbs-api-key-here

account/managers/account.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ class SupabaseAuth:
2424
def get_anon_client(cls) -> AsyncGoTrueClient:
2525
settings = get_settings()
2626
return AsyncGoTrueClient(
27-
url=settings.supabase_url + "/auth/v1",
27+
url=settings.supabase.url + "/auth/v1",
2828
headers={
29-
"apiKey": settings.supabase_anon_key,
30-
"authorization": f"Bearer {settings.supabase_anon_key}",
29+
"apiKey": settings.supabase.anon_key,
30+
"authorization": f"Bearer {settings.supabase.anon_key}",
3131
},
3232
)
3333

3434
@classmethod
3535
def get_authenticated_client(cls, access_token: str) -> AsyncGoTrueClient:
3636
settings = get_settings()
3737
return AsyncGoTrueClient(
38-
url=settings.supabase_url + "/auth/v1",
38+
url=settings.supabase.url + "/auth/v1",
3939
headers={
40-
"apiKey": settings.supabase_anon_key,
40+
"apiKey": settings.supabase.anon_key,
4141
"authorization": f"Bearer {access_token}",
4242
},
4343
)
@@ -46,10 +46,10 @@ def get_authenticated_client(cls, access_token: str) -> AsyncGoTrueClient:
4646
def get_serv_client(cls) -> AsyncGoTrueClient:
4747
settings = get_settings()
4848
return AsyncGoTrueClient(
49-
url=settings.supabase_url + "/auth/v1",
49+
url=settings.supabase.url + "/auth/v1",
5050
headers={
51-
"apiKey": settings.supabase_serv_key,
52-
"authorization": f"Bearer {settings.supabase_serv_key}",
51+
"apiKey": settings.supabase.serv_key,
52+
"authorization": f"Bearer {settings.supabase.serv_key}",
5353
},
5454
)
5555

account/managers/wxmp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ async def wxmp_login(
9797
}
9898
access_token = jwt.encode(
9999
payload,
100-
key=settings.jwt_secret_key,
101-
algorithm=settings.jwt_algorithms[0],
100+
key=settings.auth.jwt_secret_key,
101+
algorithm=settings.auth.jwt_algorithms[0],
102102
)
103103

104104
profile = db.get(BaseProfile, wxmp_account.id)

account/routes.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
"""Account App Routes."""
1+
"""Account App Routes.
2+
3+
Business logic endpoints for account management.
4+
Simple CRUD operations (get, create, put, delete, upsert) are handled by direct
5+
database access from the client.
6+
"""
27

38
import fastapi
49
from fastapi import Depends, HTTPException
@@ -8,7 +13,6 @@
813
import sqlmodel
914

1015
from .schemas import (
11-
AccountRef,
1216
BaseProfile,
1317
BaseProfileEditable,
1418
AccountConfig,
@@ -18,18 +22,6 @@
1822
router = fastapi.APIRouter()
1923

2024

21-
@router.get("/profile/{account_id}")
22-
def get_profile(
23-
account_id: AccountRef,
24-
db: sqlmodel.Session = Depends(get_db_session),
25-
) -> BaseProfile:
26-
"""Get account profile by ID."""
27-
profile = db.get(BaseProfile, account_id)
28-
if not profile:
29-
raise HTTPException(status_code=404, detail="Profile not found")
30-
return profile
31-
32-
3325
@router.get("/profile/me")
3426
def get_my_profile(
3527
auth: AuthInfo = Depends(require_auth),
@@ -48,7 +40,10 @@ def update_my_profile(
4840
auth: AuthInfo = Depends(require_auth),
4941
db: sqlmodel.Session = Depends(get_db_session),
5042
) -> BaseProfile:
51-
"""Update current user's profile."""
43+
"""Update current user's profile.
44+
45+
Only updates fields that are provided (partial update).
46+
"""
5247
profile = db.get(BaseProfile, auth.user_id)
5348
if not profile:
5449
raise HTTPException(status_code=404, detail="Profile not found")

communication/managers/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
"""沟通服务的管理器模块"""
2+
3+
__all__ = [
4+
"ChatManager",
5+
"MessageManager",
6+
]
7+
8+
from .chat import ChatManager
9+
from .message import MessageManager

0 commit comments

Comments
 (0)