Skip to content

Commit 1cbc8e2

Browse files
authored
Merge pull request #293 from Pseudo-Lab/deploy/cert-develop
Deploy/cert develop
2 parents d324a9f + 7900a9f commit 1cbc8e2

13 files changed

Lines changed: 439 additions & 68 deletions

File tree

โ€Žcert/.gitignoreโ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ Thumbs.db
7373
# Temporary files
7474
*.tmp
7575
*.temp
76+
77+
backend/scripts
78+
backend/src/assets/templates/*.png
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"3": { "start": "2021-07-16", "end": "2021-10-08" },
3+
"4": { "start": "2022-03-07", "end": "2022-05-29" },
4+
"5": { "start": "2022-09-05", "end": "2022-11-27" },
5+
"6": { "start": "2023-03-15", "end": "2023-06-07" },
6+
"7": { "start": "2023-08-21", "end": "2023-11-12" },
7+
"8": { "start": "2024-03-03", "end": "2024-05-26" },
8+
"9": { "start": "2024-08-04", "end": "2024-10-27" },
9+
"10": { "start": "2025-03-02", "end": "2025-05-25" },
10+
"11": { "start": "2025-09-08", "end": "2025-11-30" }
11+
}
2.74 MB
Binary file not shown.
2.67 MB
Binary file not shown.

โ€Žcert/backend/src/models/certificate.pyโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CertificateStatus(str, Enum):
77
"""์ˆ˜๋ฃŒ์ฆ ์ƒํƒœ"""
88
PENDING = "Pending"
99
NOT_ELIGIBLE = "Not Eligible"
10+
REISSUED = "Reissued"
1011
ISSUED = "Issued"
1112
SYSTEM_ERROR = "System Error"
1213

โ€Žcert/backend/src/services/certificate_service.pyโ€Ž

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,30 @@ async def create_certificate(certificate_data: dict) -> CertificateResponse:
6060

6161
# ๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ ํ™•์ธ์ด ์„ฑ๊ณตํ•˜๊ณ  ๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์žฌ๋ฐœ๊ธ‰ ์ฒ˜๋ฆฌ
6262
if existing_cert and existing_cert.get("found"):
63+
existing_status = existing_cert.get("status", "")
64+
if existing_status in [CertificateStatus.ISSUED, CertificateStatus.REISSUED]:
65+
logger.info(
66+
"๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ ๋ฐœ๊ฒฌ (์žฌ๋ฐœ๊ธ‰ ์ง„ํ–‰)",
67+
extra={
68+
"certificate_number": existing_cert.get("certificate_number"),
69+
"applicant_name": certificate_data.get("applicant_name"),
70+
"season": certificate_data.get("season"),
71+
"status": existing_status,
72+
},
73+
)
74+
return await CertificateService._reissue_certificate(
75+
certificate_data, existing_cert, notion_client
76+
)
77+
6378
logger.info(
64-
"๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ ๋ฐœ๊ฒฌ",
79+
"๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ ๋ฐœ๊ฒฌํ–ˆ์ง€๋งŒ ์ƒํƒœ๊ฐ€ Issued/Reissued๊ฐ€ ์•„๋‹˜. ์‹ ๊ทœ ๋ฐœ๊ธ‰์œผ๋กœ ์ง„ํ–‰",
6580
extra={
6681
"certificate_number": existing_cert.get("certificate_number"),
6782
"applicant_name": certificate_data.get("applicant_name"),
6883
"season": certificate_data.get("season"),
84+
"status": existing_status,
6985
},
7086
)
71-
return await CertificateService._reissue_certificate(
72-
certificate_data, existing_cert, notion_client
73-
)
7487

7588
# 2. ์‹ ๊ทœ ์ˆ˜๋ฃŒ์ฆ ๋ฐœ๊ธ‰ ์ฒ˜๋ฆฌ
7689
return await CertificateService._create_new_certificate(
@@ -140,6 +153,9 @@ async def _reissue_certificate(
140153
extra={"certificate_number": existing_cert_number},
141154
)
142155

156+
# ๋ฐœ๊ธ‰์ผ(์žฌ๋ฐœ๊ธ‰ ์‹œ์  ๊ธฐ์ค€)
157+
issue_date = datetime.now().strftime("%Y-%m-%d")
158+
143159
# PDF ์ˆ˜๋ฃŒ์ฆ ์žฌ์ƒ์„ฑ
144160
pdf_generator = PDFGenerator()
145161
pdf_bytes = pdf_generator.create_certificate(
@@ -148,6 +164,8 @@ async def _reissue_certificate(
148164
course_name=certificate_data["course_name"],
149165
role=participation_info["user_role"],
150166
period=participation_info["period"],
167+
certificate_number=existing_cert_number,
168+
issue_date=issue_date,
151169
)
152170

153171
# ์ด๋ฉ”์ผ ์žฌ๋ฐœ์†ก
@@ -160,6 +178,22 @@ async def _reissue_certificate(
160178
role=participation_info["user_role"],
161179
certificate_bytes=pdf_bytes
162180
)
181+
182+
# ์žฌ๋ฐœ๊ธ‰ ๋กœ๊ทธ ๊ธฐ๋ก
183+
reissue_log = await notion_client.log_certificate_reissue(
184+
certificate_data=certificate_data,
185+
certificate_number=existing_cert_number,
186+
role=participation_info["user_role"],
187+
issue_date=issue_date
188+
)
189+
if not reissue_log:
190+
logger.warning(
191+
"์žฌ๋ฐœ๊ธ‰ ๋กœ๊ทธ ๊ธฐ๋ก ์‹คํŒจ",
192+
extra={
193+
"certificate_number": existing_cert_number,
194+
"recipient_email": certificate_data["recipient_email"],
195+
},
196+
)
163197

164198
# ๊ธฐ์กด ์ˆ˜๋ฃŒ์ฆ ์ƒํƒœ๋ฅผ ์žฌ๋ฐœ๊ธ‰์œผ๋กœ ์—…๋ฐ์ดํŠธ
165199
await notion_client.update_certificate_status(
@@ -185,7 +219,7 @@ async def _reissue_certificate(
185219
name=certificate_data["applicant_name"],
186220
recipient_email=certificate_data["recipient_email"],
187221
certificate_number=existing_cert_number,
188-
issue_date=datetime.now().strftime("%Y-%m-%d"),
222+
issue_date=issue_date,
189223
certificate_status=CertificateStatus.ISSUED,
190224
season=certificate_data["season"],
191225
course_name=certificate_data["course_name"],
@@ -226,6 +260,7 @@ async def _create_new_certificate(
226260

227261
# TODO: ์ž„์‹œ ๊ฐ’, ์ถ”ํ›„ ์ˆ˜์ • ํ•„์š”
228262
certificate_number = f"CERT-{datetime.now().year}{participation_info['project_code']}{str(uuid.uuid4())[:2].upper()}"
263+
issue_date = datetime.now().strftime("%Y-%m-%d")
229264

230265
# PDF ์ˆ˜๋ฃŒ์ฆ ์ƒ์„ฑ
231266
pdf_generator = PDFGenerator()
@@ -235,6 +270,8 @@ async def _create_new_certificate(
235270
course_name=certificate_data["course_name"],
236271
role=participation_info["user_role"],
237272
period=participation_info["period"],
273+
certificate_number=certificate_number,
274+
issue_date=issue_date,
238275
)
239276
# ์ด๋ฉ”์ผ ๋ฐœ์†ก
240277
email_sender = EmailSender()
@@ -281,7 +318,7 @@ async def _create_new_certificate(
281318
name=certificate_data["applicant_name"],
282319
recipient_email=certificate_data["recipient_email"],
283320
certificate_number=certificate_number,
284-
issue_date=datetime.now().strftime("%Y-%m-%d"),
321+
issue_date=issue_date,
285322
certificate_status=CertificateStatus.ISSUED,
286323
season=certificate_data["season"],
287324
course_name=certificate_data["course_name"],

0 commit comments

Comments
ย (0)