Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created API's for Get Open and Closed Issues #2090

Merged
merged 16 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
from website.api.views import (
BugHuntApiViewset,
BugHuntApiViewsetV2,
ClosedIssuesViewSet,
CompanyViewSet,
DomainViewSet,
FlagIssueApiView,
InviteFriendApiViewset,
IssueViewSet,
LeaderboardApiViewSet,
LikeIssueApiView,
OpenIssuesViewSet,
StatsApiViewset,
UrlCheckApiViewset,
UserIssueViewSet,
Expand Down Expand Up @@ -117,6 +119,8 @@
handler500 = "website.views.handler500"

urlpatterns = [
path("open-issues/", OpenIssuesViewSet.as_view({"get": "get"}), name="open-issues"),
path("closed-issues/", ClosedIssuesViewSet.as_view({"get": "get"}), name="closed-issues"),
path("company/", CompanyViewSet.as_view({"get": "list", "post": "create"}), name="company"),
path("invite-friend/", website.views.invite_friend, name="invite_friend"),
path("referral/", website.views.referral_signup, name="referral_signup"),
Expand Down
38 changes: 38 additions & 0 deletions website/api/views.py
Uttkarsh-raj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import uuid
from datetime import datetime
from json import JSONDecodeError

from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.core.files.storage import default_storage
from django.core.mail import send_mail
from django.db.models import Q, Sum
Expand Down Expand Up @@ -617,3 +619,39 @@ class CompanyViewSet(viewsets.ModelViewSet):
filter_backends = (filters.SearchFilter,)
search_fields = ("id", "name")
http_method_names = ("get", "post", "put")


class OpenIssuesViewSet(viewsets.ModelViewSet):
queryset = Issue.objects.all()
serializer_class = IssueSerializer

def get(self, request, *args, **kwargs):
try:
domainUrl = request.GET.get("domain")
domainData = Domain.objects.get(url=domainUrl)
Uttkarsh-raj marked this conversation as resolved.
Show resolved Hide resolved
data = Issue.objects.filter(domain=domainData.id, status="open")
serializer = IssueSerializer(data, many=True)
return Response({"count": len(serializer.data), "result": serializer.data}, status=200)
except ObjectDoesNotExist:
Uttkarsh-raj marked this conversation as resolved.
Show resolved Hide resolved
return Response({"result": [], "message": "Object does not exist"}, status=404)
except JSONDecodeError:
return Response({"result": "error", "message": "Json decoding error"}, status=400)


class ClosedIssuesViewSet(viewsets.ModelViewSet):
queryset = Issue.objects.all()
serializer_class = IssueSerializer

def get(self, request, *args, **kwargs):
try:
domainUrl = request.GET.get("domain")
domainData = Domain.objects.get(url=domainUrl)
data = Issue.objects.filter(domain=domainData.id, status="closed")
serializer = IssueSerializer(data, many=True)
return Response(
{"count": len(serializer.data), "response": serializer.data, "status": 200}
)
except ObjectDoesNotExist:
return Response({"result": "error", "message": "Domain does not exist"}, status=404)
except JSONDecodeError:
return Response({"result": "error", "message": "Json decoding error"}, status=400)
2 changes: 1 addition & 1 deletion website/tests_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def tearDownClass(cls):

def test_responses(
self,
allowed_http_codes=[200, 302, 405, 401],
allowed_http_codes=[200, 302, 405, 401, 404],
credentials={},
default_kwargs={},
):
Expand Down
Loading