Skip to content

Commit

Permalink
[#15220885] Updates to Koha::Squatting::Branch and Reserves
Browse files Browse the repository at this point in the history
This adds HTTP::Exception style handling to Branches,
removes deprecated JSONP callback handling and complete
support for retrieving a single branch.
  • Loading branch information
ctfliblime committed Jul 22, 2011
1 parent 9bd5db5 commit df769e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
39 changes: 22 additions & 17 deletions Koha/Squatting/Branch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,42 @@ use Carp;

sub BranchShow {
my ($self, $branchcode) = @_;
$self->v->{'callback'} = $self->input->{'callback'};

try {
$self->v->{branch}
= Koha::Model::Branch->new(branchcode => $branchcode)->load;
$self->render('_rdb_obj', _SetContentType($self));
}
catch {
carp $_;
$self->status = 404;
return $self->render('404');
if (/^No such Koha::/) {
HTTP::Exception::404->throw;
}
else {
carp $_;
HTTP::Exception::500->throw;
}
};
}

sub BranchSetShow {
my ($self) = @_;
my $results

try {
my $results
= Koha::Model::BranchSet->new(limits => $self->input);
$self->v->{branchset} = ($results) ? $results->branches : undef;
$self->v->{inflate} = $self->input->{inflate} // 0;
$self->v->{callback} = $self->input->{'callback'};
$self->render('_rdb_objset', _SetContentType($self));
$self->v->{branchset} = ($results) ? $results->branches : undef;
$self->v->{inflate} = $self->input->{inflate} // 0;
$self->render('_rdb_objset', _SetContentType($self));
}
catch {
carp $_;
HTTP::Exception::500->throw;
};
}

our @C = (
C( BranchShow => ['/branches/(\w+)'],
get => \&BranchShow,
),
C( BranchSetShow => ['/branches/'],
get => \&BranchSetShow,
Expand All @@ -83,10 +94,7 @@ use Carp;

sub RenderRdbAsJson {
my ($self, $v) = @_;
my $func = $v->{'callback'};
my $str = as_json($v->{branch});
if ($func) { "$func($str)" }
else { $str }
return as_json($v->{branch});
}

sub RenderRdbSetAsJson {
Expand All @@ -103,10 +111,7 @@ use Carp;
else {
@branchset = ($v->{branchset});
}
my $str = to_json(\@branchset);
my $func = $v->{'callback'};
if ($func) { "$func($str)" }
else { $str }
return to_json(\@branchset);
}

our @V = (
Expand Down
1 change: 0 additions & 1 deletion Koha/Squatting/Reserve.pm
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ use Carp;
$r->borrower->surname,
$r->borrower->firstname);
$t->{borrowercard} = $r->borrower->cardnumber;
# $t->{branchname} = $r->branchcode; #for now... no FK in db
$t->{branchname} = $r->branch->branchname;
$t->{itembarcode} = ($r->item) ? $r->item->barcode : undef;
$t->{uri} = R('ReserveSingle', $t->{reservenumber});
Expand Down

0 comments on commit df769e9

Please sign in to comment.