Merge pull request #5191 from solgenomics/topic/quality_control
[sgn.git] / lib / CXGN / BrAPI / JSONResponse.pm
blobe109ffd99a4435b48e793e8ca5e64cbc62dde098
1 package CXGN::BrAPI::JSONResponse;
3 use Moose;
4 use Data::Dumper;
5 use CXGN::BrAPI::Pagination;
7 sub return_error {
8 my $self = shift;
9 my $status = shift;
10 my $message = shift;
11 my $http_code = shift;
12 push @$status, { 'ERROR' => $message };
13 my $formatted_status = _convert_status_obj($status);
14 my $pagination = CXGN::BrAPI::Pagination->pagination_response(0,1,0);
15 my $response = {
16 'status' => $formatted_status,
17 'pagination' => $pagination,
18 'result' => undef,
19 'datafiles' => [],
20 'http_code' => $http_code
22 return $response;
25 sub return_success {
26 my $self = shift;
27 my $result = shift;
28 my $pagination = shift;
29 my $data_files = shift;
30 my $status = shift;
31 my $message = shift;
32 push @$status, { 'INFO' => $message };
33 my $formatted_status = _convert_status_obj($status);
34 my $response = {
35 'status' => $formatted_status,
36 'pagination' => $pagination,
37 'result' => $result,
38 'datafiles' => $data_files
40 return $response;
43 sub _convert_status_obj {
44 my $status = shift;
45 my @formatted_status;
46 foreach (@$status){
47 while (my ($code, $message) = each %$_){
48 push @formatted_status, {
49 messageType => $code,
50 message => $message
54 return \@formatted_status;