Skip to content

Commit

Permalink
Use VersionDeleteCommand in REST API
Browse files Browse the repository at this point in the history
Fixes #30415
  • Loading branch information
vboctor committed Apr 28, 2023
1 parent c407d11 commit c50890a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions api/rest/restcore/projects_rest.php
Expand Up @@ -44,6 +44,8 @@
# Project versions
$g_app->post( '/{id}/versions', 'rest_project_version_add' );
$g_app->post( '/{id}/versions/', 'rest_project_version_add' );
$g_app->delete( '/{id}/versions/{version_id}', 'rest_project_version_remove' );
$g_app->delete( '/{id}/versions/{version_id}/', 'rest_project_version_remove' );

# Project hierarchy (subprojects)
$g_app->post( '/{id}/subprojects', 'rest_project_hierarchy_add' );
Expand Down Expand Up @@ -210,6 +212,36 @@ function rest_project_version_add( \Slim\Http\Request $p_request, \Slim\Http\Res
return $p_response->withStatus( HTTP_STATUS_NO_CONTENT, "Version created with id $t_version_id" );
}

/**
* A method to delete a project version.
*
* @param \Slim\Http\Request $p_request The request.
* @param \Slim\Http\Response $p_response The response.
* @param array $p_args Arguments
* @return \Slim\Http\Response The augmented response.
*/
function rest_project_version_remove( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_project_id = isset( $p_args['id'] ) ? $p_args['id'] : $p_request->getParam( 'id' );
if( is_blank( $t_project_id ) ) {
$t_message = "Project id is missing.";
return $p_response->withStatus( HTTP_STATUS_BAD_REQUEST, $t_message );
}

$t_old_version_id = isset( $p_args['version_id'] ) ? $p_args['version_id'] : $p_request->getParam( 'version_id' );

$t_data = array(
'query' => array(
'project_id' => $t_project_id,
'version_id' => $t_old_version_id,
)
);

$t_command = new VersionDeleteCommand( $t_data );
$t_command->execute();

return $p_response->withStatus( HTTP_STATUS_NO_CONTENT, "Version deleted" );
}

/**
* A method to add a project to the project hierarchy (subproject).
*
Expand Down

0 comments on commit c50890a

Please sign in to comment.