Skip to content

Commit

Permalink
feat(activities): /crew/activity/{id} 에 현재 사용자가 제출했는지 여부를 출력하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hepheir committed Sep 27, 2024
1 parent fcbca3b commit eca799c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/apps/activities/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CrewActivityProblemDetailDTO(ProblemDetailDTO):
@dataclass
class CrewActivityProblemExtraDetailDTO(CrewActivityProblemDTO):
submissions: List[SubmissionDTO]
my_submission: Optional[SubmissionDTO]
has_submitted: bool


@dataclass
Expand Down
11 changes: 3 additions & 8 deletions app/apps/activities/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,11 @@ def as_extra_detail_dto(self, user: User) -> dto.CrewActivityProblemExtraDetailD
return dto.CrewActivityProblemExtraDetailDTO(
**self.as_dto().__dict__,
submissions=self.submissions(),
my_submission=self.submission_of_user(user),
has_submitted=self.has_submitted(user),
)

def submissions(self) -> List[SubmissionDTO]:
return [obj.as_dto() for obj in Submission.objects.problem(self)]

def submission_of_user(self, user: User) -> Optional[SubmissionDTO]:
try:
obj = Submission.objects.problem(self).submitted_by(user).latest()
except Submission.DoesNotExist:
return None
else:
return obj.as_dto()
def has_submitted(self, user: User) -> bool:
return Submission.objects.problem(self).submitted_by(user).exists()
6 changes: 4 additions & 2 deletions app/apps/activities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CrewActivityProblemDetailDTOSerializer(ProblemDetailDTOSerializer):

class CrewActivityProblemExtraDetailDTOSerializer(CrewActivityProblemDTOSerializer):
submissions = SubmissionDTOSerializer(many=True)
my_submission = SubmissionDTOSerializer(required=False, default=None)
has_submitted = serializers.BooleanField()


class CrewActivityDTOSerializer(serializers.Serializer):
Expand Down Expand Up @@ -57,7 +57,9 @@ class Meta:
@property
def data(self):
self.instance: proxy.CrewActivity
return CrewActivityDetailDTOSerializer(self.instance.as_detail_dto()).data
user = self.context['request'].user
assert user.is_authenticated
return CrewActivityExtraDetailDTOSerializer(self.instance.as_extra_detail_dto(user)).data

def save(self, **kwargs):
problem_ref_ids = self.validated_data.pop('problem_refs')
Expand Down
2 changes: 1 addition & 1 deletion app/apps/activities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CrewActivityRetrieveUpdateAPIView(mixins.CrewActivityUrlKwargMixin, generi
serializer_class = serializers.CrewActivityDAOSerializer
permission_classes = [permissions.IsCaptain | permissions.IsMemberAndReadOnly]

@swagger_auto_schema(responses={status.HTTP_201_CREATED: serializers.CrewActivityProblemDetailDTOSerializer})
@swagger_auto_schema(responses={status.HTTP_201_CREATED: serializers.CrewActivityExtraDetailDTOSerializer})
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)

Expand Down

0 comments on commit eca799c

Please sign in to comment.