Example #1
0
def create_user_service(id_user):
    body = request.get_json()
    try:
        exists = Services.query.filter_by(
            id_service_type=body["id_service_type"],
            id_user_offer=id_user).scalar()

        if exists == None:
            new_service = Services(id_service_type=body["id_service_type"],
                                   id_user_offer=id_user,
                                   description=body["description"],
                                   price_h=body["price_h"],
                                   is_active=body["is_active"])
            new_service.create_service()
            return jsonify(new_service.serialize()), 200
        else:
            service = Services.query.filter_by(
                id_service_type=body["id_service_type"]).first()
            is_active = service.is_active
            if is_active == True:
                new_service = Services(id_service_type=body["id_service_type"],
                                       id_user_offer=id_user,
                                       description=body["description"],
                                       price_h=body["price_h"],
                                       is_active=True)
                new_service.update_services(body["id_service_type"], id_user,
                                            body["description"],
                                            body["price_h"])
                return jsonify(new_service.serialize()), 200
            else:
                return "Couldn't create the service", 404
    except:
        return "Couldn't create the service", 404
Example #2
0
def update_user_service(id_user):
    body = request.get_json()
    try:
        update_service = Services(id_service_type=body["id_service_type"],
                                  id_user_offer=id_user,
                                  description=body["description"],
                                  price_h=body["price_h"],
                                  is_active=True)
        update_service.update_services(body["id_service_type"], id_user,
                                       body["description"], body["price_h"])
        return jsonify(update_service.serialize()), 200
    except:
        return "Couldn't update the service", 404