Skip to content

Commit

Permalink
Merge pull request #89 from whatTeamNaeTeam/feat-not_approved_team
Browse files Browse the repository at this point in the history
Feat not approved team
  • Loading branch information
fnzksxl authored Aug 28, 2024
2 parents b8b8988 + 4eca9ee commit 4fe05ca
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
16 changes: 16 additions & 0 deletions wtnt/team/like/service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down
19 changes: 17 additions & 2 deletions wtnt/team/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -48,6 +49,7 @@ class Meta:
"url",
"category",
"uuid",
"is_approved",
]

def get_image_url(self, obj):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
29 changes: 28 additions & 1 deletion wtnt/user/profile/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions wtnt/user/profile/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
UserManageActivityView,
UserManageActivityDetailView,
UserLikeTeamView,
NotApprovedTeamView,
)

urlpatterns = [
Expand All @@ -17,4 +18,5 @@
path("team-manage/<int:user_id>", UserManageActivityView.as_view(), name="profile-team-manage"),
path("like/<int:user_id>", UserLikeTeamView.as_view(), name="like-team-list"),
path("team-manage/detail/<int:team_id>", UserManageActivityDetailView.as_view(), name="profile-team-manage-detail"),
path("<int:user_id>/not-approved", NotApprovedTeamView.as_view(), name="not-approved-team"),
]
17 changes: 17 additions & 0 deletions wtnt/user/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit 4fe05ca

Please sign in to comment.