Commit 0d50d560 authored by guillecxb's avatar guillecxb
Browse files

endpoints for add new config in capif and register

parent b4186291
Loading
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -142,3 +142,28 @@ def replaceConfiguration():
        return jsonify(message="Missing new configuration in request body"), 400

    return helper_operation.replace_configuration(new_config)


@helper_routes.route("/helper/addNewConfiguration", methods=["POST"])
def add_new_configuration():
    """Adds a new category inside 'settings'."""
    data = request.json
    category_name = data.get("category_name")
    category_values = data.get("category_values")

    if not category_name or not category_values:
        return jsonify(message="Missing 'category_name' or 'category_values' in request body"), 400

    return helper_operation.add_new_configuration(category_name, category_values)

@helper_routes.route("/helper/addNewConfigSetting", methods=["PATCH"])
def add_new_config_setting():
    """Adds a new configuration inside 'settings'."""
    data = request.json
    param_path = data.get("param_path")
    new_value = data.get("new_value")
    
    if not param_path or new_value is None:
        return jsonify(message="Missing 'param_path' or 'new_value' in request body"), 400
    
    return helper_operation.add_new_config_setting(param_path, new_value)
+31 −0
Original line number Diff line number Diff line
@@ -251,4 +251,35 @@ class HelperOperations:



    def add_new_configuration(self, category_name, category_values):
        """
        Adds a new category of parameters in 'settings'.
        """
        current_app.logger.debug(f"Añadiendo nueva categoría: {category_name} con valores: {category_values}")

        config_col = self.db.get_col_by_name(self.db.capif_configuration)

        # MongoDB $set para añadir la nueva categoría dentro de settings
        update_query = {"$set": {f"settings.{category_name}": category_values}}

        result = config_col.update_one({"config_name": "default"}, update_query)

        if result.modified_count == 0:
            return jsonify(message=f"No configuration found or category '{category_name}' not added"), 404

        return jsonify(message=f"Category '{category_name}' added successfully"), 200

    def add_new_config_setting(self, param_path, new_value):
        """Add a new parameter in 'settings'."""
        current_app.logger.debug(f"Adding new configuration setting: {param_path} with value: {new_value}")
        config_col = self.db.get_col_by_name(self.db.capif_configuration)
        
        update_query = {"$set": {f"settings.{param_path}": new_value}}
        result = config_col.update_one({"config_name": "default"}, update_query)
        
        if result.modified_count == 0:
            return jsonify(message=f"No configuration found or parameter '{param_path}' not updated"), 404
        
        return jsonify(message=f"Parameter '{param_path}' added successfully"), 200

+25 −0
Original line number Diff line number Diff line
@@ -192,3 +192,28 @@ def replace_register_configuration(username):
    current_app.logger.debug(f"Admin {username} is replacing the entire register configuration")
    return register_operation.replace_register_configuration(new_config)


@register_routes.route("/configuration/addNewCategory", methods=["POST"])
def add_new_category():
    """Adds a new category inside 'settings'."""
    data = request.json
    category_name = data.get("category_name")
    category_values = data.get("category_values")

    if not category_name or not category_values:
        return jsonify(message="Missing 'category_name' or 'category_values' in request body"), 400

    return register_operation.add_new_category(category_name, category_values)


@register_routes.route("/configuration/addNewParamConfigSetting", methods=["PATCH"])
def add_new_config_setting():
    """Adds a new configuration inside a category in 'settings'."""
    data = request.json
    param_path = data.get("param_path")
    new_value = data.get("new_value")
    
    if not param_path or new_value is None:
        return jsonify(message="Missing 'param_path' or 'new_value' in request body"), 400
    
    return register_operation.add_new_config_setting(param_path, new_value)
+28 −0
Original line number Diff line number Diff line
@@ -130,3 +130,31 @@ class RegisterOperations:
            return jsonify(message="No existing configuration found; a new one was created"), 201

        return jsonify(message="Register configuration replaced successfully"), 200
    

    def add_new_category(self, category_name, category_values):
        """Adds a new category of parameters in 'settings'."""
        current_app.logger.debug(f"Adding new category: {category_name} with values: {category_values}")
        config_col = self.db.get_col_by_name(self.db.capif_configuration)
        
        update_query = {"$set": {f"settings.{category_name}": category_values}}
        result = config_col.update_one({"config_name": "default"}, update_query)
        
        if result.modified_count == 0:
            return jsonify(message=f"No configuration found or category '{category_name}' not added"), 404
        
        return jsonify(message=f"Category '{category_name}' added successfully"), 200


    def add_new_config_setting(self, param_path, new_value):
        """Adds a new parameter inside a category in 'settings'."""
        current_app.logger.debug(f"Adding new configuration setting: {param_path} with value: {new_value}")
        config_col = self.db.get_col_by_name(self.db.capif_configuration)
        
        update_query = {"$set": {f"settings.{param_path}": new_value}}
        result = config_col.update_one({"config_name": "default"}, update_query)
        
        if result.modified_count == 0:
            return jsonify(message=f"No configuration found or parameter '{param_path}' not updated"), 404
        
        return jsonify(message=f"Parameter '{param_path}' added successfully"), 200