Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions getcloser/backend/app/models/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
class UserChallengeStatus(Base):
__tablename__ = "user_challenge_status"

user_id = Column(Integer, primary_key=True, index=True)
challenge_id = Column(Integer, ForeignKey("challenge_questions.id"), index=True)
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, index=True)
challenge_id = Column(Integer, ForeignKey("challenge_questions.id"), nullable=True)

is_correct = Column(Boolean, default=False)
submitted_at = Column(DateTime(timezone=True))
Expand Down
22 changes: 21 additions & 1 deletion getcloser/backend/app/services/challenge_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,34 @@ def assign_challenges_logic(my_id: str, members: list, db: Session) -> list:
available_ids = members.copy()
random.shuffle(available_ids)

members = list(set(members))
Copy link
Collaborator

@daclouds daclouds Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복이 있는 상태에서 set 에 넣어 중복을 제거하는 것 보단 중복을 만들지 않는 게 어떨까요? 😉 #267

for user_id in members:
possible_ids = [uid for uid in available_ids if uid != user_id]
if not possible_ids:
raise ValueError(f"{user_id}에게 할당할 문제 부족")

assigned_user_id = random.choice(possible_ids)
assigned_question = random.choice([q for q in team_questions if q.user_id == assigned_user_id])

available_ids.remove(assigned_user_id)
Comment on lines 40 to 48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 에러날 수도 있겠는데요?
members = [2, 3, 4, 5]
available_ids = [3, 2, 5, 4]

user_id = 2
possible_ids = [3, 5, 4]
assigned_user_id = 3
available_ids = [2, 5, 4]

user_id = 3
possible_ids = [2, 5, 4]
assigned_user_id = 4
available_ids = [2, 5]

user_id = 4
possible_ids = [2, 5]
assigned_user_id = 2
available_ids = [5]

user_id = 5
possible_ids = []

이렇게 되면 ValueError(f"{user_id}에게 할당할 문제 부족")가 나올 것 같아요

Copy link
Collaborator

@daclouds daclouds Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저는 중복 허용하고 문제만 중복되지 않게 하는 건 어떨까요? 👀
category 가 3개라면 len(mebmers) * category 가 되어서 문제는 충분 할 것 같거든요.

2번 유저의 문제를 푸는 사람이 4, 5 일 수 있게?!


# ✅ UserChallengeStatus 업데이트
user_status = (
db.query(UserChallengeStatus)
.filter(UserChallengeStatus.user_id == user_id)
.first()
)

if not user_status:
raise HTTPException(status_code=404, detail="UserChallengeStatus 없음")

user_status.challenge_id = assigned_question.id
user_status.submitted_at = None
user_status.is_correct = False
user_status.is_redeemed = False

db.add(user_status)

assigned_list.append(AssignedChallenge(
user_id=user_id,
assigned_challenge_id=assigned_question.id,
Expand All @@ -54,6 +72,8 @@ def assign_challenges_logic(my_id: str, members: list, db: Session) -> list:
answer=assigned_question.answer
))

db.commit()

return assigned_list[0]


Expand Down
Loading