from flask import request, Response
from db.repository import Repository
from db.entities import Location

repo = Repository()

def post():
    body = request.json
    _insert_location(body)
    return Response(status=201)

def post_many():
    body = request.json
    for location in body:
        _insert_location(location)
    return Response(status=201)

def get():
    return [l.to_serializable_dict() for l in repo.get_locations()]

def _insert_location(location_data: dict):
    repo.add_location(Location(location_data))
