Fakultas Ilmu Komputer UI

Commit 4bcadd8b authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

[GREEN] Added weekly_report_id parameter in get weekly report comment API

parent 6db385bd
Pipeline #80788 passed with stages
in 15 minutes and 25 seconds
......@@ -3,7 +3,8 @@ from .views import WeeklyReportViewSet, WeeklyReportCommentViewSet
router = routers.SimpleRouter()
router.register('progress/user_report', WeeklyReportViewSet)
router.register('progress/nutritionist_comment', WeeklyReportCommentViewSet)
router.register('progress/nutritionist_comment', WeeklyReportCommentViewSet, \
basename='WeeklyReportComment')
urlpatterns = []
......
......@@ -52,4 +52,25 @@ class WeeklyReportViewSet(viewsets.ModelViewSet):
class WeeklyReportCommentViewSet(viewsets.ModelViewSet):
serializer_class = WeeklyReportCommentSerializer
queryset = WeeklyReportComment.objects.all()
def get_queryset(self):
queryset = WeeklyReportComment.objects.all()
weekly_report_id = self.request.query_params.get('weekly_report_id')
if weekly_report_id is not None:
try:
weekly_report = WeeklyReport.objects.get(pk=weekly_report_id)
except WeeklyReport.DoesNotExist:
return None
queryset = queryset.filter(Q(weekly_report=weekly_report))
return queryset
def list(self, request):
queryset = self.get_queryset()
if queryset is None:
return Response({'message': 'Weekly Report does not exist.'}, \
status=status.HTTP_400_BAD_REQUEST)
serializer = WeeklyReportCommentSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment