diff --git a/wtnt/team/like/service.py b/wtnt/team/like/service.py index fa77f2f..e04a014 100644 --- a/wtnt/team/like/service.py +++ b/wtnt/team/like/service.py @@ -1,3 +1,5 @@ +from django.core.cache import cache + import core.exception.notfound as notfound_exception import core.exception.team as team_exception from core.service import BaseService @@ -12,11 +14,21 @@ def like(self): team_id = self.kwargs.get("team_id") version = self.request.data.get("version") + cache_key = f"team_detail_{team_id}" + team_cache = cache.get(cache_key) + + if team_cache is not None: + cache_update = True + try: team = Team.objects.get(id=team_id) like = Likes.objects.get(team_id=team_id, user_id=user_id) if version == team.version: like.delete() + if cache_update: + team_cache["like"] -= 1 + team_cache["version"] += 1 + cache.set(cache_key, team_cache, timeout=60 * 10) team.like -= 1 team.version += 1 team.save() @@ -33,6 +45,10 @@ def like(self): serializer = TeamLikeSerializer(data={"team_id": team_id, "user_id": user_id}) if serializer.is_valid(): serializer.save() + if cache_update: + team_cache["like"] += 1 + team_cache["version"] += 1 + cache.set(cache_key, team_cache, timeout=60 * 10) team.like += 1 team.version += 1 team.save() diff --git a/wtnt/team/serializers.py b/wtnt/team/serializers.py index 18d13b1..feb668d 100644 --- a/wtnt/team/serializers.py +++ b/wtnt/team/serializers.py @@ -26,6 +26,7 @@ class TeamCreateSerializer(LeaderInfoIncludedSerializer): view = serializers.IntegerField(read_only=True) image = serializers.CharField(write_only=True) uuid = serializers.UUIDField(write_only=True) + is_approved = serializers.BooleanField(read_only=True) leader_id = serializers.IntegerField(write_only=True) image_url = serializers.SerializerMethodField() explain = BinaryField() @@ -48,6 +49,7 @@ class Meta: "url", "category", "uuid", + "is_approved", ] def get_image_url(self, obj): @@ -80,7 +82,7 @@ def validate(self, data): if not (0 < len(data.get("title")) <= 30): raise exception.TeamNameLengthError() - valid_genres = ["웹", "앱", "게임"] + valid_genres = ["웹", "안드로이드", "IOS", "크로스플랫폼", "게임", "기타"] if data.get("genre") not in valid_genres: raise exception.TeamGenreNotValidError() @@ -147,11 +149,24 @@ def get_user_info(self, obj): class TeamListSerializer(LeaderInfoIncludedSerializer): category = TeamTechCreateSerializer(many=True, read_only=True) image = serializers.CharField(write_only=True) + is_approved = serializers.BooleanField(read_only=True) image_url = serializers.SerializerMethodField() class Meta: model = Team - fields = ["id", "title", "image", "image_url", "category", "leader_info", "like", "version", "view", "genre"] + fields = [ + "id", + "title", + "image", + "image_url", + "category", + "leader_info", + "like", + "version", + "view", + "genre", + "is_approved", + ] def get_image_url(self, obj): return obj.image + "thumnail.jpg" diff --git a/wtnt/user/profile/service.py b/wtnt/user/profile/service.py index 7b90a78..b4c505d 100644 --- a/wtnt/user/profile/service.py +++ b/wtnt/user/profile/service.py @@ -182,6 +182,15 @@ def get_like_activity(self): return data + def get_not_approved_team(self): + owner_id = self.request.user.id + team_data = Team.objects.filter(leader_id=owner_id, is_approved=False) + serializer = TeamListSerializer(team_data, many=True) + + data = TeamResponse.get_team_list_response(serializer.data, owner_id) + + return data + class MyTeamManageService(BaseServiceWithCheckOwnership, BaseServiceWithCheckLeader): def get_my_teams(self): @@ -251,11 +260,29 @@ def get_my_team_detail(self): return data + def finish_project(self): + team_id = self.kwargs.get("team_id") + user_id = self.request.user.id + try: + team = Team.objects.select_related("leader").get(id=team_id) + except Team.DoesNotExist: + raise notfound_exception.TeamNotFoundError() + + self.check_leader(user_id, team.leader.id) + + team.is_accomplished = True + team.save() + + return {"detail": f"{team.title} is accomplished."} + def ban_user_from_team(self): team_id = self.kwargs.get("team_id") user_id = self.request.user.id - team = Team.objects.select_related("leader").get(id=team_id) + try: + team = Team.objects.select_related("leader").get(id=team_id) + except Team.DoesNotExist: + raise notfound_exception.TeamNotFoundError() self.check_leader(user_id, team.leader.id) diff --git a/wtnt/user/profile/urls.py b/wtnt/user/profile/urls.py index 89d7d1a..9c125b3 100644 --- a/wtnt/user/profile/urls.py +++ b/wtnt/user/profile/urls.py @@ -7,6 +7,7 @@ UserManageActivityView, UserManageActivityDetailView, UserLikeTeamView, + NotApprovedTeamView, ) urlpatterns = [ @@ -17,4 +18,5 @@ path("team-manage/", UserManageActivityView.as_view(), name="profile-team-manage"), path("like/", UserLikeTeamView.as_view(), name="like-team-list"), path("team-manage/detail/", UserManageActivityDetailView.as_view(), name="profile-team-manage-detail"), + path("/not-approved", NotApprovedTeamView.as_view(), name="not-approved-team"), ] diff --git a/wtnt/user/profile/views.py b/wtnt/user/profile/views.py index f35af9c..bcec3a5 100644 --- a/wtnt/user/profile/views.py +++ b/wtnt/user/profile/views.py @@ -113,6 +113,12 @@ def get(self, request, *args, **kwargs): return Response(data, status=status.HTTP_200_OK) + def patch(self, request, *args, **kwargs): + myteam_service = MyTeamManageService(request, **kwargs) + data = myteam_service.finish_project() + + return Response(data, status=status.HTTP_202_ACCEPTED) + def delete(self, request, *args, **kwargs): myteam_service = MyTeamManageService(request, **kwargs) data = myteam_service.ban_user_from_team() @@ -129,3 +135,14 @@ def get(self, request, *args, **kwargs): data = myactivity_service.get_like_activity() return Response({"team": data}, status=status.HTTP_200_OK) + + +class NotApprovedTeamView(APIView): + permission_classes = [IsApprovedUser] + + def get(self, request, *args, **kwargs): + myactivity_service = MyActivityServcie(request, **kwargs) + myactivity_service.check_ownership() + data = myactivity_service.get_not_approved_team() + + return Response({"team": data}, status=status.HTTP_200_OK)