[API][BOT] New endpoint to retrieve campus associated to discord id #84
|
@ -2,6 +2,8 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('bot/discord', views.discord_bot, name='discord_bot'),
|
path('bot/discord', views.bot_discord_rank, name='bot_discord_rank'), # legacy, to remove when new bot is deployed
|
||||||
|
path('bot/discord/rank', views.bot_discord_rank, name='bot_discord_rank'), # use this
|
||||||
|
path('bot/discord/campus', views.bot_discord_campus, name='bot_discord_campus'),
|
||||||
path('events/<str:event_slug>', views.events_data, name='events_data'),
|
path('events/<str:event_slug>', views.events_data, name='events_data'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,8 +7,7 @@ from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
def bot_discord_rank(request):
|
||||||
def discord_bot(request):
|
|
||||||
if request.method != 'GET':
|
if request.method != 'GET':
|
||||||
return JsonResponse({'error':'bad request'})
|
return JsonResponse({'error':'bad request'})
|
||||||
|
|
||||||
|
@ -28,6 +27,24 @@ def discord_bot(request):
|
||||||
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
def bot_discord_campus(request):
|
||||||
|
if request.method != 'GET':
|
||||||
|
return JsonResponse({'error':'bad request'})
|
||||||
|
|
||||||
|
token = request.GET.get('token')
|
||||||
|
auth_token = os.getenv('BOT_TOKEN')
|
||||||
|
|
||||||
|
if (token != auth_token or not auth_token):
|
||||||
|
return JsonResponse({'error':'not authorized'})
|
||||||
|
|
||||||
|
all_users = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')
|
||||||
|
data = {}
|
||||||
|
for user in all_users:
|
||||||
|
if user.discord_id:
|
||||||
|
data[user.discord_id] = user.campus
|
||||||
|
|
||||||
|
return JsonResponse(data)
|
||||||
|
|
||||||
def events_data(request, event_slug):
|
def events_data(request, event_slug):
|
||||||
if request.method != 'GET':
|
if request.method != 'GET':
|
||||||
return JsonResponse({'error':'bad request'})
|
return JsonResponse({'error':'bad request'})
|
||||||
|
|
Loading…
Reference in New Issue