Ejemplo n.º 1
0
class Service(object, metaclass=Singleton):
    def __init__(self):
        self.repository = Repository()

    @log
    def save(self, body):
        entity = json.loads(body, cls=EntityDecoder)
        return json.dumps(self.repository.save(entity=entity),
                          cls=EntityEncoder)

    @log
    def update(self, body):
        entity = json.loads(body, cls=EntityDecoder)
        return json.dumps(self.repository.update(entity=entity),
                          cls=EntityEncoder)

    @log
    def remove(self, body):
        entity = json.loads(body, cls=EntityDecoder)
        return json.dumps(self.repository.remove(entity=entity))

    @log
    def remove_by_id(self, body):
        return json.dumps(
            self.repository.remove_by_id(entity_id=json.loads(body)['id']))

    @log
    def get(self, entity_id):
        return json.dumps(self.repository.get(entity_id=entity_id),
                          cls=EntityEncoder)
Ejemplo n.º 2
0
class Service(object, metaclass=Singleton):
    def __init__(self):
        self.repository = Repository()

    @log()
    @to_json(clazz=Entity)
    def save(self, body):
        return self.repository.save(body)

    @log()
    @to_json(clazz=Entity)
    def get(self, id):
        return self.repository.get(id)

    @log()
    def remove(self, id):
        return self.repository.remove(id)

    @log()
    @to_json(clazz=Entity)
    def update(self, body):
        return self.repository.update(body)
Ejemplo n.º 3
0
class AppHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.repository = Repository()

    def get(self):
        self.write(
            json.dumps(self.repository.get(self.get_argument('id')),
                       cls=EntityEncoder))

    def post(self):
        self.write(
            json.dumps(self.repository.update(
                json.loads(self.request.body, cls=EntityDecoder)),
                       cls=EntityEncoder))

    def put(self):
        self.write(
            json.dumps(self.repository.create(
                json.loads(self.request.body, cls=EntityDecoder)),
                       cls=EntityEncoder))

    def delete(self):
        self.write(json.dumps(self.repository.remove(self.get_argument('id'))))
Ejemplo n.º 4
0
class Service(metaclass=Singleton):
    def __init__(self):
        self.repository = Repository()

    @log
    def save(self, body):
        entity = json.loads(body, cls=EntityDecoder)

        return json.dumps(self.repository.create(entity), cls=EntityEncoder)

    @log
    def remove(self, id):
        return json.dumps(self.repository.remove(id), cls=EntityEncoder)

    @log
    def get(self, id):
        return json.dumps(self.repository.get(id), cls=EntityEncoder)

    @log
    def update(self, body):
        entity = json.loads(body, cls=EntityDecoder)

        return json.dumps(self.repository.update(entity), cls=EntityEncoder)