Ejemplo n.º 1
0
class OfficeControllerById(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.interface = FirebaseInterface()

    def get(self, office_id):
        dic = {"data": self.interface.getData("offices", office_id)}

        data = json.dumps(dic)
        data_json = json.loads(data)
        return data_json

    def delete(self, office_id):
        self.interface.deleteData("offices", office_id)

    def put(self, office_id):
        http_return_code = 201
        result = request.get_json()

        try:
            Office(result)
            self.interface.addData(result, "offices", office_id)
        except Exception as e:
            http_return_code = 400
            result = str(e)
        return result, http_return_code
Ejemplo n.º 2
0
class UsersControllerById(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.interface = FirebaseInterface()

    def get(self, user_mail):
        dic = {"data": self.interface.getData("users", user_mail)}

        data = json.dumps(dic)
        data_json = json.loads(data)
        return data_json

    def delete(self, user_mail):
        self.interface.deleteData("users", user_mail)

    def put(self, user_mail):
        result = request.get_json()
        http_return_code = 200

        try:
            User(result)
            self.interface.addData(result, "users", user_mail)
        except Exception as e:
            http_return_code = 400
            result = str(e)

        return result, http_return_code
Ejemplo n.º 3
0
class TrucksControllerById(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.interface = FirebaseInterface()

    def get(self, truck_id):
        dic = {"data": self.interface.getData("trucks", truck_id)}

        data = json.dumps(dic)
        data_json = json.loads(data)
        return data_json

    def delete(self, truck_id):
        self.interface.deleteData("trucks", truck_id)

    def put(self, truck_id):
        result = request.get_json()
        self.interface.addData(result, "trucks", truck_id)
Ejemplo n.º 4
0
class ServicesController(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.interface = FirebaseInterface()

    def get(self):
        try:
            dic = {"data": self.interface.getData("services")}

            data = json.dumps(dic)
            result = json.loads(data)
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code

    def post(self):
        req = request.get_json()

        try:
            name = req["nome"]
            price = req["preco"]

            service = Service(name, price)
            service.validateFields()

            self.interface.setData(service.__dict__, "services", name)
            result = "Serviço cadastrado com sucesso"
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code

    def delete(self, service):
        try:
            self.interface.deleteData("services", service)

            result = "Serviço removido com sucesso"
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code

    def put(self):
        req = request.get_json()

        try:
            name = req["nome"]
            price = req["preco"]

            service = Service(name, price)
            service.validateFields()

            self.interface.updateData(service.__dict__, "services", name)

            result = "Serviço alterado com sucesso"
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code