Skip to content

Commit 6725e1d

Browse files
committed
feat(getcloser): 에러 수정
1 parent cbeae77 commit 6725e1d

3 files changed

Lines changed: 42 additions & 31 deletions

File tree

getcloser/backend/app/schemas/challenge_schema.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,48 @@
33
from typing import List, Optional
44

55
class ChallengeRequest(BaseModel):
6-
team_id: int
7-
my_id: int
8-
members_ids: List[int]
6+
team_id: int
7+
my_id: int
8+
members_ids: List[int]
99

1010
class AssignedChallenge(BaseModel):
11-
user_id: int
12-
assigned_challenge_id: int
13-
from_user_id: int
14-
category: str
15-
answer: str
11+
user_id: int
12+
assigned_challenge_id: int
13+
from_user_id: int
14+
category: str
15+
answer: str
16+
17+
class Config:
18+
json_schema_extra = {
19+
"example": {
20+
"team_id": 0,
21+
"my_id": 1,
22+
"members_ids": [
23+
2, 3, 4, 5
24+
]
25+
}
26+
}
1627

1728
class AnswerSubmitRequest(BaseModel):
18-
user_id: int
19-
challenge_id: int
20-
submitted_answer: str
21-
22-
# class Config:
23-
# json_schema_extra = {
24-
# "example": {
25-
# "user_id": 1,
26-
# "challenge_id": 1,
27-
# "submitted_answer": "LLM"
28-
# }
29-
# }
29+
user_id: int
30+
challenge_id: int
31+
submitted_answer: str
32+
33+
class Config:
34+
json_schema_extra = {
35+
"example": {
36+
"user_id": 1,
37+
"challenge_id": 1,
38+
"submitted_answer": "LLM"
39+
}
40+
}
3041

3142
class AnswerSubmitResponse(BaseModel):
32-
is_correct: bool
43+
is_correct: bool
3344

3445
class ChallengeResponse(BaseModel):
35-
team_id: int
36-
my_assigned: AssignedChallenge
46+
team_id: int
47+
my_assigned: AssignedChallenge
3748

3849
class GoodsRedeemRequest(BaseModel):
3950
user_id: int

getcloser/backend/app/scripts/challenge_question.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def seed_challenge_questions_from_csv(file_path: str):
1313
reader = csv.DictReader(csvfile)
1414
for row in reader:
1515
challenge = ChallengeQuestion(
16-
id=int(row["challenge_id"]),
16+
id=int(row["id"]),
1717
user_id=int(row["user_id"]),
1818
category=row["category"],
1919
answer=row["answer"]

getcloser/backend/app/services/challenge_service.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def assign_challenges_logic(my_id: str, members: list, db: Session) -> list:
4040

4141
def submit_challenges_logic(user_id: str, challenge_id: int, submitted_answer: str, db: Session) -> bool:
4242
# 1. 사용자가 푼 문제 찾기
43-
challenge = db.query(AssignedChallenge).filter(
44-
AssignedChallenge.user_id == user_id,
45-
AssignedChallenge.assigned_challenge_id == challenge_id
43+
challenge = db.query(ChallengeQuestion).filter(
44+
ChallengeQuestion.user_id == user_id,
45+
ChallengeQuestion.id == challenge_id
4646
).first()
4747

4848
if not challenge:
4949
raise ValueError("해당 사용자의 할당된 문제가 없습니다.")
5050

5151
# 2. 원본 문제에서 정답 확인
5252
question = db.query(ChallengeQuestion).filter(
53-
ChallengeQuestion.id == challenge.assigned_challenge_id
53+
ChallengeQuestion.id == challenge.id
5454
).first()
5555

5656
if not question:
@@ -60,9 +60,9 @@ def submit_challenges_logic(user_id: str, challenge_id: int, submitted_answer: s
6060
is_correct = (submitted_answer.strip().lower() == question.answer.strip().lower())
6161

6262
# 4. 결과 저장
63-
# challenge.is_correct = is_correct
64-
# challenge.submitted_answer = submitted_answer
65-
# db.commit()
63+
challenge.is_correct = is_correct
64+
challenge.submitted_answer = submitted_answer
65+
db.commit()
6666

6767
# 5. 결과 반환
6868
return is_correct

0 commit comments

Comments
 (0)