Commit 9d44adbb authored by Keith Jolley's avatar Keith Jolley
Browse files

No need to return error code in payload. Already available in header.

Only show paging when more than 1 page.
parent 0704f96f
...@@ -50,7 +50,7 @@ get '/db/:db/isolates' => sub { ...@@ -50,7 +50,7 @@ get '/db/:db/isolates' => sub {
if ( $page != $pages ) { if ( $page != $pages ) {
push @$paging, { last => request->uri_base . "/db/$db/isolates?page=$pages&page_size=$self->{'page_size'}" }; push @$paging, { last => request->uri_base . "/db/$db/isolates?page=$pages&page_size=$self->{'page_size'}" };
} }
push @$values, { paging => $paging }; push @$values, { paging => $paging } if $pages > 1;
my @links; my @links;
push @links, request->uri_for("/db/$db/isolates/$_")->as_string foreach @$ids; push @links, request->uri_for("/db/$db/isolates/$_")->as_string foreach @$ids;
push @$values, { isolates => \@links }; push @$values, { isolates => \@links };
...@@ -62,14 +62,14 @@ get '/db/:db/isolates/:id' => sub { ...@@ -62,14 +62,14 @@ get '/db/:db/isolates/:id' => sub {
my ( $db, $id ) = ( params->{'db'}, params->{'id'} ); my ( $db, $id ) = ( params->{'db'}, params->{'id'} );
if ( !BIGSdb::Utils::is_int($id) ) { if ( !BIGSdb::Utils::is_int($id) ) {
status(400); status(400);
return { status => 400, error => 'Id must be an integer.' }; return { error => 'Id must be an integer.' };
} }
my $values = []; my $values = [];
my $field_values = my $field_values =
$self->{'datastore'}->run_query( "SELECT * FROM $self->{'system'}->{'view'} WHERE id=?", $id, { fetch => 'row_hashref' } ); $self->{'datastore'}->run_query( "SELECT * FROM $self->{'system'}->{'view'} WHERE id=?", $id, { fetch => 'row_hashref' } );
if ( !defined $field_values->{'id'} ) { if ( !defined $field_values->{'id'} ) {
status(404); status(404);
return { status => 404, error => "Isolate $id does not exist." }; return { error => "Isolate $id does not exist." };
} }
my $field_list = $self->{'xmlHandler'}->get_field_list; my $field_list = $self->{'xmlHandler'}->get_field_list;
foreach my $field (@$field_list) { foreach my $field (@$field_list) {
...@@ -93,7 +93,7 @@ get '/db/:db/fields' => sub { ...@@ -93,7 +93,7 @@ get '/db/:db/fields' => sub {
my $self = setting('self'); my $self = setting('self');
if ( $self->{'system'}->{'dbtype'} ne 'isolates' ) { if ( $self->{'system'}->{'dbtype'} ne 'isolates' ) {
status(400); status(400);
return { status => 400, error => "Fields can only be defined in isolate databases." }; return { error => "Fields can only be defined in isolate databases." };
} }
my $fields = $self->{'xmlHandler'}->get_field_list; my $fields = $self->{'xmlHandler'}->get_field_list;
my $values = []; my $values = [];
......
...@@ -48,7 +48,7 @@ get '/db/:db' => sub { ...@@ -48,7 +48,7 @@ get '/db/:db' => sub {
my $db = params->{'db'}; my $db = params->{'db'};
if ( !$self->{'system'}->{'db'} ) { if ( !$self->{'system'}->{'db'} ) {
status(404); status(404);
return { status => 404, error => "Database '$db' does not exist" }; return { error => "Database '$db' does not exist" };
} }
if ( $self->{'system'}->{'dbtype'} eq 'isolates' ) { if ( $self->{'system'}->{'dbtype'} eq 'isolates' ) {
my $count = $self->{'datastore'}->run_query("SELECT COUNT(*) FROM $self->{'system'}->{'view'}"); my $count = $self->{'datastore'}->run_query("SELECT COUNT(*) FROM $self->{'system'}->{'view'}");
......
...@@ -31,12 +31,12 @@ get '/db/:db/users/:user' => sub { ...@@ -31,12 +31,12 @@ get '/db/:db/users/:user' => sub {
my $user_id = param('user'); my $user_id = param('user');
if ( !BIGSdb::Utils::is_int($user_id) ) { if ( !BIGSdb::Utils::is_int($user_id) ) {
status(400); status(400);
return { status => 400, error => 'User id must be an integer.' }; return { error => 'User id must be an integer.' };
} }
my $user = $self->{'datastore'}->run_query( "SELECT * FROM users WHERE id=?", $user_id, { fetch => 'row_hashref' } ); my $user = $self->{'datastore'}->run_query( "SELECT * FROM users WHERE id=?", $user_id, { fetch => 'row_hashref' } );
if ( !defined $user->{'id'} ) { if ( !defined $user->{'id'} ) {
status(404); status(404);
return { status => 404, error => "User $user_id does not exist." }; return { error => "User $user_id does not exist." };
} }
my $values = []; my $values = [];
foreach my $field (qw(id first_name surname affiliation email)) { foreach my $field (qw(id first_name surname affiliation email)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment