from rest_framework.decorators import api_view
from django.http import JsonResponse

from roombookings.decorators import does_token_exist, log_api_call, throttle

import os
import requests


@api_view(['GET'])
@does_token_exist
@throttle
@log_api_call
def people(request):
    if "query" not in request.GET:
        return JsonResponse({
            "ok": False,
            "error": "No query provided"
        })

    query = request.GET["query"]

    url = (
        "{}?{}={}"
        .format(
            os.environ["SEARCH_API_URL"],
            os.environ["SEARCH_API_QUERY_PARAMS"],
            query,
        )
    )

    r = requests.get(url)

    results = r.json()["response"]["resultPacket"]["results"][:20]

    def serialize_person(person):
        return {
            "name": person["title"],
            "department": person["metaData"].get("7", ""),
            "email": person["metaData"].get("E", ""),
            "status": person["metaData"].get("g", ""),
        }

    people = [serialize_person(person) for person in results]

    return JsonResponse({
        "ok": True,
        "people": people
    })

backend/uclapi/search/views.py
from rest_framework.decorators import api_view
from django.http import JsonResponse

from roombookings.decorators import does_token_exist, log_api_call, throttle

import os
import requests


@api_view(['GET'])
@does_token_exist
@throttle
@log_api_call
def people(request):
    if "query" not in request.GET:
        response = JsonResponse({
            "ok": False,
            "error": "No query provided."
        })
        response.status_code = 400
        return response

    query = request.GET["query"]

    url = (
        "{}?{}={}"
        .format(
            os.environ["SEARCH_API_URL"],
            os.environ["SEARCH_API_QUERY_PARAMS"],
            query,
        )
    )

    r = requests.get(url)

    results = r.json()["response"]["resultPacket"]["results"][:20]

    def serialize_person(person):
        return {
            "name": person["title"],
            "department": person["metaData"].get("7", ""),
            "email": person["metaData"].get("E", ""),
            "status": person["metaData"].get("g", ""),
        }

    people = [serialize_person(person) for person in results]

    return JsonResponse({
        "ok": True,
        "people": people
    })

backend/uclapi/search/views.py
diff --git a/backend/uclapi/search/views.py b/backend/uclapi/search/views.py
index bbff34ec1..fd044531a 100644
--- a/backend/uclapi/search/views.py
+++ b/backend/uclapi/search/views.py
@@ -13,10 +13,12 @@
 @log_api_call
 def people(request):
     if "query" not in request.GET:
-        return JsonResponse({
+        response = JsonResponse({
             "ok": False,
-            "error": "No query provided"
+            "error": "No query provided."
         })
+        response.status_code = 400
+        return response
 
     query = request.GET["query"]
 

[Bug] Search People should return HTTP status 400 when query is missing
Currently, the `/search/people` returns a HTTP 200 code when even for an incorrect API request. For example, if you leave out the `query` param it returns the following body:

```json
{ "error": "No query provided", "ok": false}
```

Yet, the HTTP status code is 200, while it should be 400.

