Esempio n. 1
0
                    return {'message': 'Asset already assigned to this user..'}
                else:
                    assign_asset = AssignedAsset(get_asset.id, get_user.id,
                                                 employee_id, get_category.id,
                                                 date_assigned)
                    AssignedAsset.save_assignedasset(assign_asset)
                    return {'success': 'Asset assigned successful!'}, 201
            except Exception as e:
                print(e)
                return {'Error': 'Unable to assign asset.'}, 404


class AssignedAssetRes(Resource):
    def get(self, name):

        try:
            userid = User.query.filter_by(username=name).first()
            all_assignedasset = AssignedAsset.query.filter_by(
                user_id=userid.id)
            result = assignasset_schema.dump(all_assignedasset)
            return jsonify({"Assigned Assets": result.data})
        except Exception as e:
            print('Error', e)
            return {'Not Found': 'Record not found.'}, 404


api.add_resource(AssetResource, '/api/asset')
api.add_resource(AssignAssetResource, '/api/assetassign')
api.add_resource(AssignedAssetRes, '/api/assignedasset/<string:name>')
app.register_blueprint(asset_bp)
Esempio n. 2
0
            User.save_data(user)
            return {'success': 'User creation successful!'}, 201
        else:
            return {'message': 'Something went wrong'}


obj_user = UserResource()


class UserRes(Resource):
    def delete(self, name):
        print("*******************", name)
        try:
            org = User.query.filter_by(id=1).first()
            # result = organization_schema.dump(org)
            # org_id = json.dump(org.id)
            print('********', org, org.id)
            # department = Department.query.filter_by(organization_id=org.id).first()
            # print(department.id)
            db.session.delete(org.id)
            # db.session.delete(department.id)
            db.session.commit()
        except:
            return {'message': 'Something went wrong'}, 400
        return {'Success': 'User delete successful'}, 200


api.add_resource(UserResource, '/api/user')
# api.add_resource(UserRes, '/api/user/<string:name>')
app.register_blueprint(user_bp)
Esempio n. 3
0
api = Api(department)


class DepartmentResource(Resource):
    def get(self):
        dept_name = Department.query.all()
        result = department_schema.dump(dept_name)
        return jsonify({"Department": result.data})

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

        if request.method == "POST":
            try:
                org_id = Organization.query.filter(
                    Organization.organization_name == data['orgname']).first()
                # print('************',org_id.id)
                dept = Department(data['dp_name'], org_id.id)
                Department.save_data(dept)
                success = {"message": "Department created successfully"}

            except:
                return {'message': 'Something went wrong'}, 400
            return success, 201
        else:
            return {'message': 'Something went wrong'}


api.add_resource(DepartmentResource, '/api/department')
app.register_blueprint(department)
Esempio n. 4
0
            return {'message': 'Something went wrong'}


class OrganizationRes(Resource):
    def get(self, id):
        try:
            org_details = Organization.query.filter_by(id=id)
            result = organization_schema.dump(org_details)
            return jsonify({"Organization": result.data})
        except Exception as e:
            print('Error', e)
            return {'Not Found': 'Record not found.'}, 404

    # def delete(self, id):
    #     try:
    #         org = Organization.query.filter_by(id=id).delete()
    #         # result = organization_schema.dump(org)
    #         # org_id = json.dump(org.id)
    #         print('********',org, org.id)
    #         # db.session.delete(org.id)
    #         # db.session.delete(department.id)
    #         db.session.commit()
    #         return {'Success': 'Organization delete successful'}, 200
    #     except:
    #         return {'message': 'Something went wrong'}, 400


api.add_resource(OrganizationResource, '/api/organization')
api.add_resource(OrganizationRes, '/api/organization/<int:id>')
app.register_blueprint(organization)
Esempio n. 5
0
                    category = Category(category, subcategory)
                    Category.save_category(category)
                    return {'success': 'Category creation successful!'}, 201
            except None:
                return {'error': 'Error occurred while category creation...'}
        else:
            return {'message': 'Something went wrong'}


class CategoryRes(Resource):
    def delete(self, name):
        print("*******************", name)
        try:
            cat = Category.query.filter_by(id=1).first()
            # result = organization_schema.dump(org)
            # org_id = json.dump(org.id)
            # print('********',org, org.id)
            # department = Department.query.filter_by(organization_id=org.id).first()
            # print(department.id)
            db.session.delete(cat.id)
            # db.session.delete(department.id)
            db.session.commit()
        except:
            return {'message': 'Something went wrong'}, 400
        return {'Success': 'Category delete successful'}, 200


api.add_resource(CategoryResource, '/api/category')
api.add_resource(CategoryRes, '/api/category/<string:name>')
app.register_blueprint(category_bp)