import json
import models
import schemas
import falcon
from google.appengine.ext import ndb


class BaseResponse(object):
    def on_get(self, req, resp, *args, **kwargs):
        resp.body = json.dumps({'status':'ok'})


class ProjectStatus(BaseResponse):
    validator = schemas.ProjectSchema()

    def on_get(self, req, resp):
        # TODO: paginate this!
        results = models.Project.query() #.fetch()
        resp.body = self.validator.dumps([i for i in results], many=True).data


class ProjectDetail(BaseResponse):
    validator = schemas.ProjectSchema()

    def on_get(self, req, resp, status_id):
        # query = models.Project.get_by_id(long(status_id))
        query = ndb.Key("Project", long(status_id)).get()
        resp.body = self.validator.dumps(query).data

