From ab4c4de954e9d6f35a0f0a03d51984b6ab45acdc Mon Sep 17 00:00:00 2001 From: ericguo202 Date: Wed, 18 Feb 2026 20:59:59 -0500 Subject: [PATCH 1/2] implemented studygroup_views.py and added routes to urls.py --- backend/config/urls.py | 8 ++++ backend/hoagiehelp/api/studygroup_views.py | 56 +++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/backend/config/urls.py b/backend/config/urls.py index 48bd3f0..778787d 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -20,6 +20,7 @@ from hoagiehelp.api.answer_views import AnswerDetailView, AnswerListView from hoagiehelp.api.comment_views import CommentDetailView, CommentListView from hoagiehelp.api.question_views import QuestionDetailView, QuestionListView +from hoagiehelp.api.studygroup_views import StudyGroupDetailView, StudyGroupListView from hoagiehelp.api.user_views import ( UserView, user_answers, @@ -52,6 +53,13 @@ path( "comments//", CommentDetailView.as_view(), name="comment-detail" ), + # Study Groups + path("study-groups/", StudyGroupListView.as_view(), name="studygroup-list"), + path( + "study-groups//", + StudyGroupDetailView.as_view(), + name="studygroup-detail", + ), # Users path("users//", UserView.as_view(), name="user-detail"), path("users//questions/", user_questions, name="user-questions"), diff --git a/backend/hoagiehelp/api/studygroup_views.py b/backend/hoagiehelp/api/studygroup_views.py index 8a6eb39..2ffe473 100644 --- a/backend/hoagiehelp/api/studygroup_views.py +++ b/backend/hoagiehelp/api/studygroup_views.py @@ -1,4 +1,6 @@ -from rest_framework import serializers +from rest_framework import serializers, status +from rest_framework.response import Response +from rest_framework.views import APIView from hoagiehelp.models.studygroup import StudyGroup @@ -18,3 +20,55 @@ class Meta: "created_at", "updated_at", ) + + +class StudyGroupListView(APIView): + """Handle collection operations for study groups.""" + + def get(self, request) -> Response: + """List all study groups.""" + queryset = StudyGroup.objects.all() + serializer = StudyGroupSerializer(queryset, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + + def post(self, request) -> Response: + """Create a new study group.""" + serializer = StudyGroupSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + +class StudyGroupDetailView(APIView): + """Handle individual study group operations.""" + + def get(self, request, studygroup_id: str) -> Response: + """Get all details associated with a given study group.""" + try: + study_group = StudyGroup.objects.get(id=studygroup_id) + except StudyGroup.DoesNotExist: + return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + serializer = StudyGroupSerializer(study_group) + return Response(serializer.data) + + def put(self, request, studygroup_id: str) -> Response: + """Update an existing study group.""" + try: + study_group = StudyGroup.objects.get(id=studygroup_id) + except StudyGroup.DoesNotExist: + return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + serializer = StudyGroupSerializer(study_group, data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + def delete(self, request, studygroup_id: str) -> Response: + """Delete an existing study group.""" + try: + study_group = StudyGroup.objects.get(id=studygroup_id) + except StudyGroup.DoesNotExist: + return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + study_group.delete() + return Response(status=status.HTTP_204_NO_CONTENT) From d2dda995fb7581bb72c1e0acb0a4cc5df15a0a2d Mon Sep 17 00:00:00 2001 From: issacli-0821 Date: Thu, 26 Feb 2026 14:09:56 -0500 Subject: [PATCH 2/2] Lint study group views and renamed file --- backend/config/urls.py | 2 +- .../{studygroup_views.py => study_group_views.py} | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) rename backend/hoagiehelp/api/{studygroup_views.py => study_group_views.py} (86%) diff --git a/backend/config/urls.py b/backend/config/urls.py index 778787d..6169f85 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -20,7 +20,7 @@ from hoagiehelp.api.answer_views import AnswerDetailView, AnswerListView from hoagiehelp.api.comment_views import CommentDetailView, CommentListView from hoagiehelp.api.question_views import QuestionDetailView, QuestionListView -from hoagiehelp.api.studygroup_views import StudyGroupDetailView, StudyGroupListView +from backend.hoagiehelp.api.study_group_views import StudyGroupDetailView, StudyGroupListView from hoagiehelp.api.user_views import ( UserView, user_answers, diff --git a/backend/hoagiehelp/api/studygroup_views.py b/backend/hoagiehelp/api/study_group_views.py similarity index 86% rename from backend/hoagiehelp/api/studygroup_views.py rename to backend/hoagiehelp/api/study_group_views.py index 2ffe473..27cb53f 100644 --- a/backend/hoagiehelp/api/studygroup_views.py +++ b/backend/hoagiehelp/api/study_group_views.py @@ -48,7 +48,9 @@ def get(self, request, studygroup_id: str) -> Response: try: study_group = StudyGroup.objects.get(id=studygroup_id) except StudyGroup.DoesNotExist: - return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + return Response( + {"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND + ) serializer = StudyGroupSerializer(study_group) return Response(serializer.data) @@ -57,7 +59,9 @@ def put(self, request, studygroup_id: str) -> Response: try: study_group = StudyGroup.objects.get(id=studygroup_id) except StudyGroup.DoesNotExist: - return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + return Response( + {"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND + ) serializer = StudyGroupSerializer(study_group, data=request.data) if serializer.is_valid(): serializer.save() @@ -69,6 +73,8 @@ def delete(self, request, studygroup_id: str) -> Response: try: study_group = StudyGroup.objects.get(id=studygroup_id) except StudyGroup.DoesNotExist: - return Response({"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND) + return Response( + {"detail": "Study group not found"}, status=status.HTTP_404_NOT_FOUND + ) study_group.delete() return Response(status=status.HTTP_204_NO_CONTENT)