Skip to content

Commit

Permalink
REST: Extend get issue to return 1 or many
Browse files Browse the repository at this point in the history
- Use consistent response payload when returning 1 or many.  This changed the
payload when getting a single issue.
- Support pagination when returning multiple issues.
- Support returning multiple issues based on a `project_id`.
- Support returning multiple issues based on a filter id + `project_id`.
  • Loading branch information
vboctor committed Apr 22, 2017
1 parent fbf5cbb commit 709fbde
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions api/rest/restcore/issues_rest.php
Expand Up @@ -40,11 +40,43 @@
* @return \Slim\Http\Response The augmented response.
*/
function rest_issue_get( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
# Username and password below are ignored, since middleware already done the auth.
$t_result = mc_issue_get( /* username */ '', /* password */ '', $p_request->getParam( 'id' ) );
$t_issue_id = $p_request->getParam( 'id' );

if( ApiObjectFactory::isFault( $t_result ) ) {
return $p_response->withStatus( $t_result->status_code, $t_result->fault_string );
if( !is_blank( $t_issue_id ) ) {
# Get Issue By Id

# Username and password below are ignored, since middleware already done the auth.
$t_issue = mc_issue_get( /* username */ '', /* password */ '', $t_issue_id );

if( ApiObjectFactory::isFault( $t_issue ) ) {
return $p_response->withStatus( $t_result->status_code, $t_result->fault_string );
}

$t_result = array( 'issues' => array( $t_issue ) );
} else {
$t_page_number = $p_request->getParam( 'page', 1 );
$t_page_size = $p_request->getParam( 'page_size', 50 );

# Get a set of issues
$t_project_id = (int)$p_request->getParam( 'project_id', ALL_PROJECTS );
if( $t_project_id != ALL_PROJECTS && !project_exists( $t_project_id ) ) {
# TODO: What's best was to escape $t_project?
$t_message = "Project '$t_project_id' doesn't exist";
return $p_response->withStatus( HTTP_STATUS_NOT_FOUND, $t_message );
}

$t_filter_id = (int)$p_request->getParam( 'filter_id', 0 );
if( $t_filter_id !== 0 ) {
# TODO: we should have a better way to do this.
global $g_project_override;
$g_project_override = $t_project_id;

$t_issues = mc_filter_get_issues( '', '', $t_project_id, $t_filter_id, $t_page_number, $t_page_size );
} else {
$t_issues = mc_project_get_issues( '', '', $t_project_id, $t_page_number, $t_page_size );
}

$t_result = array( 'issues' => $t_issues );
}

return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
Expand Down

0 comments on commit 709fbde

Please sign in to comment.