Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added REST function project create
Fixes #24622
  • Loading branch information
andersruneson authored and vboctor committed Aug 20, 2018
1 parent 9522424 commit 5f75d23
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api/rest/restcore/projects_rest.php
Expand Up @@ -25,6 +25,8 @@
$g_app->group('/projects', function() use ( $g_app ) {
$g_app->get( '', 'rest_projects_get' );
$g_app->get( '/', 'rest_projects_get' );
$g_app->post( '', 'rest_project_add' );
$g_app->post( '/', 'rest_project_add' );
$g_app->get( '/{id}', 'rest_projects_get' );
$g_app->get( '/{id}/', 'rest_projects_get' );

Expand Down Expand Up @@ -105,3 +107,28 @@ 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 add a new project.
*
* @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_add( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_payload = $p_request->getParsedBody();
if( $t_payload === null ) {
return $p_response->withStatus( HTTP_STATUS_BAD_REQUEST, "Unable to parse body, specify content type" );
}

$t_project_id = mc_project_add( /* username */ '', /* password */ '', (object) $t_payload );
ApiObjectFactory::throwIfFault( $t_project_id );

$t_user_id = auth_get_current_user_id();
$t_lang = mci_get_user_lang( $t_user_id );
$t_project = mci_project_get( $t_project_id, $t_lang, /* detail */ true );

return $p_response->withStatus( HTTP_STATUS_CREATED, "Project created with id $t_project_id" )->
withJson( array( 'project' => $t_project ) );
}

0 comments on commit 5f75d23

Please sign in to comment.