From c63ab0be5add5f37a11c3e8a7de33bb75a3eccae Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 2 Aug 2024 14:38:47 +0200 Subject: Add endpoint to fetch filters in JSON format While this is an API endpoint consumed by the bot, keep it in the `resources` app instead of the `api` app, as all the logic and data for resources is contained within the `resources` app and we don't want to start messing around with that. The response format from the endpoint is as follows: { "topics": [ "algorithms-and-data-structures", "data-science", "databases", "discord-bots", "game-development", "general", "microcontrollers", "security", "software-design", "testing", "tooling", "user-interface", "web-development", "other" ], "payment_tiers": [ "free", "paid", "subscription" ], "type": [ "book", "community", "course", "interactive", "podcast", "project-ideas", "tool", "tutorial", "video" ], "difficulty": [ "beginner", "intermediate" ] } Closes #710. --- pydis_site/apps/resources/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pydis_site/apps/resources/views.py') diff --git a/pydis_site/apps/resources/views.py b/pydis_site/apps/resources/views.py index 3632b2e2..6683299f 100644 --- a/pydis_site/apps/resources/views.py +++ b/pydis_site/apps/resources/views.py @@ -2,7 +2,7 @@ import json from django.apps import apps from django.core.handlers.wsgi import WSGIRequest -from django.http import HttpResponse, HttpResponseNotFound +from django.http import HttpResponse, HttpResponseNotFound, JsonResponse from django.shortcuts import render from django.views import View @@ -38,3 +38,12 @@ class ResourceView(View): "resource_type": resource_type, } ) + + +class ResourceFilterView(View): + """Exposes resource filters for the bot.""" + + def get(self, request: WSGIRequest) -> HttpResponse: + """Return resource filters as JSON.""" + app = apps.get_app_config(APP_NAME) + return JsonResponse(app.valid_filters) -- cgit v1.2.3