Exemplo n.º 1
0
    def post():
        """
        Saves the database.
        Returns:
            Information and the status of database if it is saved otherwise the error message.
        """
        inputs = DatabaseInputs(request)
        if not inputs.validate():
            return jsonify(success=False, errors=inputs.errors)

        database = [database for database in DATABASES if database['name'] == request.json['name']]
        if len(database) != 0:
            return make_response(jsonify({'error': 'database name already exists'}), 404)

        if not DATABASES:
            database_id = 1
        else:
            database_id = DATABASES[-1]['id'] + 1
        database = {
            'id': database_id,
            'name': request.json['name'],
            'deployment': request.json.get('deployment', ""),
            'members': []
        }
        DATABASES.append(database)

        # Create new deployment

        with open("deployment.json") as json_file:
            deployment = json.load(json_file)
            deployment['databaseid'] = database_id

        DEPLOYMENT.append(deployment)
        return jsonify({'database': database, 'status': 1}), 201
Exemplo n.º 2
0
    def put(database_id):
        """
        Updates the database with specified database_id.
        Args:
            database_id (int): The first parameter.
        Returns:
            Information and the status of database if it is updated otherwise the error message.
        """
        inputs = DatabaseInputs(request)
        if not inputs.validate():
            return jsonify(success=False, errors=inputs.errors)

        current_database = [database for database in DATABASES if database['id'] == database_id]
        if len(current_database) == 0:
            abort(404)

        current_database[0]['name'] = request.json.get('name', current_database[0]['name'])
        current_database[0]['deployment'] = \
            request.json.get('deployment', current_database[0]['deployment'])
        return jsonify({'database': current_database[0], 'status': 1})