from flask.ext.restful import Resource

from .application import app
from .models import Location


class GetLocationsResource(Resource):

    def get(self):
        locations = app.db.session.query(Location).all()

        locations_json = []
        for location in locations:
            loc = {
                "name": location.name,
            }

            if location.services is not None:
                services_json = []
                for service in location.services:
                    services_json.append(str(service))

                if len(services_json) > 0:
                    loc["services"] = services_json

            if location.days_of_week is not None:
                days_of_week_json = []
                for day in location.days_of_week:
                    days_of_week_json.append(str(day))

                if len(days_of_week_json) > 0:
                    loc["days"] = days_of_week_json

            if location.description is not None:
                loc["description"] = str(location.description)

            if location.address_line1 is not None:
                loc["address_line1"] = str(location.address_line1)

            if location.address_line2 is not None:
                loc["address_line2"] = str(location.address_line2)

            if location.address_line3 is not None:
                loc["address_line3"] = str(location.address_line3)

            if location.phone is not None:
                loc["phone"] = str(location.phone)

            if location.contact_email is not None:
                loc["contact_email"] = str(location.contact_email)

            if location.website is not None:
                loc["website"] = str(location.website)

            if location.opening_time is not None:
                loc["opening_time"] = str(location.opening_time)

            if location.closing_time is not None:
                loc["closing_time"] = str(location.closing_time)

            locations_json.append(loc)

        return ({
            "locations": locations_json
        }, 200)


def api_initialize():
    app.api.add_resource(GetLocationsResource, '/api/getlocations')

@@ -83,23 +83,209 @@
 import L
-ocation
+astUpdate, Location%0A%0A%0Aclass GetDataVersion(Resource):%0A%0A    def get(self):%0A        dt = app.db.session.query(LastUpdate).first().last_update%0A%0A        return int(dt.strftime(%22%25Y%25m%25d%25H%25M%25S%22)), 200
 %0A%0A%0Aclass
@@ -2265,16 +2265,80 @@
 lize():%0A
+    app.api.add_resource(GetDataVersion, '/api/getdataversion')%0A
     app.

Add /api/getdataversion resource