Skip to content

Commit 32c994b

Browse files
ImTotemclaude
andcommitted
refactor: extract shared constants to common/constants.py
Move ORG_ID, GRADE_MAP, STATUS_RELATION from individual files to common/constants.py. Domain-specific constants (_MUTABLE, _RESERVED, _MAX_RETRIES) stay in their files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7f34a1a commit 32c994b

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/bcsd_api/common/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ORG_ID = "bcsdlab"
2+
3+
GRADE_MAP = {"1학년": 1, "2학년": 2, "3학년": 3, "4학년": 4, "대학원": 5}
4+
5+
STATUS_RELATION = {"Beginner": "beginner", "Regular": "regular"}

src/bcsd_api/domain/apply/service.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
from collections.abc import Sequence
22
from datetime import datetime
33

4-
from bcsd_api.global_.exception import BadRequest, Conflict, Forbidden, NotFound
5-
from bcsd_api.domain.form.repository import PgFormRepository, PgQuestionRepository
64
from bcsd_api.common.id_gen import generate_id
5+
from bcsd_api.common.timezone import KST
6+
from bcsd_api.domain.form.repository import PgFormRepository, PgQuestionRepository
77
from bcsd_api.domain.member.repository import PgMemberRepository
88
from bcsd_api.domain.setting.repository import PgSettingRepository
9-
from bcsd_api.common.timezone import KST
10-
11-
from .repository import PgAnswerRepository, PgApplicationRepository
9+
from bcsd_api.global_.exception import BadRequest, Conflict, Forbidden, NotFound
1210
from .model import (
1311
AnswerRequest,
1412
AnswerResponse,
1513
ApplicationListResponse,
1614
MyApplicationResponse,
1715
PaymentInfoResponse,
1816
)
17+
from .repository import PgAnswerRepository, PgApplicationRepository
1918

2019

2120
def _now() -> str:
@@ -191,16 +190,15 @@ def approve(
191190
return approved
192191

193192

194-
_STATUS_RELATION = {"Beginner": "beginner", "Regular": "regular"}
195-
196-
197193
def _add_org_relation(authz, member_id: str, status: str) -> None:
198194
if not authz:
199195
return
200-
relation = _STATUS_RELATION.get(status)
196+
from bcsd_api.common.constants import ORG_ID, STATUS_RELATION
197+
198+
relation = STATUS_RELATION.get(status)
201199
if not relation:
202200
return
203-
authz.add_relation("organization", "bcsdlab", relation, member_id)
201+
authz.add_relation("organization", ORG_ID, relation, member_id)
204202

205203

206204
def cancel(

src/bcsd_api/global_/auth/service.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
from sqlalchemy import Connection, select
44

55
from bcsd_api.common.config import Settings
6-
from bcsd_api.infra.email.sender import EmailSender
7-
from bcsd_api.global_.exception import Conflict, Unauthorized
86
from bcsd_api.common.id_gen import generate_id
9-
from bcsd_api.domain.member.repository import PgMemberRepository
107
from bcsd_api.common.tables import app_settings
118
from bcsd_api.common.timezone import KST
12-
9+
from bcsd_api.domain.member.repository import PgMemberRepository
10+
from bcsd_api.global_.exception import Conflict, Unauthorized
11+
from bcsd_api.infra.email.sender import EmailSender
1312
from . import google as google_auth
1413
from . import token as jwt_token
1514
from . import verify
@@ -111,12 +110,11 @@ def _build_row(
111110
}
112111

113112

114-
_GRADE_MAP = {"1학년": 1, "2학년": 2, "3학년": 3, "4학년": 4, "대학원": 5}
115-
116-
117113
def _resolve_routing(grade: str, conn: Connection) -> str:
114+
from bcsd_api.common.constants import GRADE_MAP
115+
118116
threshold = _grade_threshold(conn)
119-
level = _GRADE_MAP.get(grade, 1)
117+
level = GRADE_MAP.get(grade, 1)
120118
if level >= threshold:
121119
return "conversion"
122120
return "beginner"

src/bcsd_api/global_/authz/check.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
22

3+
from bcsd_api.common.constants import ORG_ID
34
from bcsd_api.global_.exception import Forbidden
45

56
logger = logging.getLogger(__name__)
67

7-
ORG_ID = "bcsdlab"
8-
98

109
def require_permission(authz, permission: str, user_id: str) -> None:
1110
if not authz:

0 commit comments

Comments
 (0)