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

    @log
    def get_all(self):
        entities = [Entity(int(x[0]), x[1]) for x in self.repository.get_all()]
        return json.dumps(entities, cls=EntityJsonEncoder)

    @log
    def get_by_id(self, id):
        r = self.repository.get_by_id(id)
        entity = r and Entity(int(r[0]), r[1]) or Entity()
        return json.dumps(entity, cls=EntityJsonEncoder)

    @log
    def save(self, entity):
        return json.dumps(self.repository.save(
            json.loads(entity, cls=EntityJsonDecoder)),
                          cls=EntityJsonEncoder)

    @log
    def delete_by_id(self, id):
        return json.dumps(self.repository.delete_by_id(id))

    @log
    def update(self, entity):
        return json.dumps(self.repository.update(
            json.loads(entity, cls=EntityJsonDecoder)),
                          cls=EntityJsonEncoder)
Exemplo n.º 2
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)
Exemplo n.º 3
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)