Skip to content

Commit

Permalink
Merge pull request #283 from 2023-Winter-Bootcamp-Team-N/BE/fix/#279
Browse files Browse the repository at this point in the history
[fix] 요약본 중복 저장 수정
  • Loading branch information
wndjs803 authored Jan 30, 2024
2 parents b2e6e6c + ca70744 commit 3f1c490
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions backend/summary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from drf_yasg.utils import swagger_auto_schema
import re

class SummaryAPIView(APIView):
@swagger_auto_schema(operation_summary="요약본 저장", request_body=SummarySaveCompositeSerializer, responses={"201":MessageResponseSerializer})
Expand All @@ -26,10 +27,23 @@ def post(self, request):
summary_data = request.data.get('summary')
category_list = request.data.get('category')
summary_by_times = request.data.get('summary_by_times', [])

save.delay(summary_data, category_list, summary_by_times)

return Response({"message": "요약본 저장 중"}, status=status.HTTP_201_CREATED)
user_id = summary_data.get('user_id')
youtube_url = summary_data.get('youtube_url')

video_id_match = re.search(r'(?<=v=)[^&]+', youtube_url)
if video_id_match:
video_id = video_id_match.group()
else:
return Response({"message": "유효한 YouTube URL이 아닙니다"}, status=status.HTTP_400_BAD_REQUEST)

if not Summary.objects.filter(user_id=user_id, youtube_url__contains=video_id).exists():

save.delay(summary_data, category_list, summary_by_times)
return Response({"message": "요약본 저장 중"}, status=status.HTTP_201_CREATED)

else:
return Response({"message": "이미 존재하는 요약본입니다."}, status=status.HTTP_400_BAD_REQUEST)

class SummaryDeleteAPIView(APIView):
@swagger_auto_schema(operation_summary="요약본 삭제", query_serializer=SummaryDeleteSerializer, responses = {"200":MessageResponseSerializer})
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
python manage.py makemigrations subscribe && \
python manage.py makemigrations summary && \
python manage.py migrate && python manage.py loaddata test.json && \
daphne -b 0.0.0.0 -p 8000 nTeamProject.asgi:application"
python manage.py runserver 0.0.0.0:8000"
ports:
- 8000:8000
volumes:
Expand Down

0 comments on commit 3f1c490

Please sign in to comment.