from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from django.views.generic import View

from gauth.models import Location

from .utils import get_review_count_by_month, get_review_count_by_month_all


class ChartDataByMonth(APIView):
    def get(self, request, *args, **kwargs):
        location_id = request.GET['location_id']
        if location_id == 'all':
            res = get_review_count_by_month_all()
        else:
            res = get_review_count_by_month(location_id)
        return Response(res)


class AnalyticsData(View):
    def get(self, request, *args, **kwargs):
        locations = Location.objects.all()
        return render(request, 'analytics.html', {'location_list': locations})
