Lines 27-33
use Koha::Holds;
Link Here
|
27 |
use Koha::DateUtils; |
27 |
use Koha::DateUtils; |
28 |
|
28 |
|
29 |
sub list { |
29 |
sub list { |
30 |
my ($c, $args, $cb) = @_; |
30 |
my $c = shift->openapi->valid_input or return; |
31 |
|
31 |
|
32 |
my $params = $c->req->query_params->to_hash; |
32 |
my $params = $c->req->query_params->to_hash; |
33 |
my @valid_params = Koha::Holds->_resultset->result_source->columns; |
33 |
my @valid_params = Koha::Holds->_resultset->result_source->columns; |
Lines 36-46
sub list {
Link Here
|
36 |
} |
36 |
} |
37 |
my $holds = Koha::Holds->search($params); |
37 |
my $holds = Koha::Holds->search($params); |
38 |
|
38 |
|
39 |
return $c->$cb($holds, 200); |
39 |
return $c->render(status => 200, openapi => $holds); |
40 |
} |
40 |
} |
41 |
|
41 |
|
42 |
sub add { |
42 |
sub add { |
43 |
my ($c, $args, $cb) = @_; |
43 |
my $c = shift->openapi->valid_input or return; |
44 |
|
44 |
|
45 |
my $body = $c->req->json; |
45 |
my $body = $c->req->json; |
46 |
|
46 |
|
Lines 51-76
sub add {
Link Here
|
51 |
my $expirationdate = $body->{expirationdate}; |
51 |
my $expirationdate = $body->{expirationdate}; |
52 |
my $borrower = Koha::Patrons->find($borrowernumber); |
52 |
my $borrower = Koha::Patrons->find($borrowernumber); |
53 |
unless ($borrower) { |
53 |
unless ($borrower) { |
54 |
return $c->$cb({error => "Borrower not found"}, 404); |
54 |
return $c->render( status => 404, |
|
|
55 |
openapi => {error => "Borrower not found"} ); |
55 |
} |
56 |
} |
56 |
|
57 |
|
57 |
unless ($biblionumber or $itemnumber) { |
58 |
unless ($biblionumber or $itemnumber) { |
58 |
return $c->$cb({ |
59 |
return $c->render( status => 400, openapi => { |
59 |
error => "At least one of biblionumber, itemnumber should be given" |
60 |
error => "At least one of biblionumber, itemnumber should be given" |
60 |
}, 400); |
61 |
} ); |
61 |
} |
62 |
} |
62 |
unless ($branchcode) { |
63 |
unless ($branchcode) { |
63 |
return $c->$cb({ |
64 |
return $c->render( status => 400, |
64 |
error => "Branchcode is required" |
65 |
openapi => { error => "Branchcode is required" } ); |
65 |
}, 400); |
|
|
66 |
} |
66 |
} |
67 |
|
67 |
|
68 |
if ($itemnumber) { |
68 |
if ($itemnumber) { |
69 |
my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); |
69 |
my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); |
70 |
if ($biblionumber and $biblionumber != $item_biblionumber) { |
70 |
if ($biblionumber and $biblionumber != $item_biblionumber) { |
71 |
return $c->$cb({ |
71 |
return $c->render( status => 400, openapi => { |
72 |
error => "Item $itemnumber doesn't belong to biblio $biblionumber" |
72 |
error => "Item $itemnumber doesn't belong to biblio $biblionumber" |
73 |
}, 400); |
73 |
} ); |
74 |
} |
74 |
} |
75 |
$biblionumber ||= $item_biblionumber; |
75 |
$biblionumber ||= $item_biblionumber; |
76 |
} |
76 |
} |
Lines 83-91
sub add {
Link Here
|
83 |
: CanBookBeReserved( $borrowernumber, $biblionumber ); |
83 |
: CanBookBeReserved( $borrowernumber, $biblionumber ); |
84 |
|
84 |
|
85 |
unless ($can_reserve eq 'OK') { |
85 |
unless ($can_reserve eq 'OK') { |
86 |
return $c->$cb({ |
86 |
return $c->render( status => 403, openapi => { |
87 |
error => "Reserve cannot be placed. Reason: $can_reserve" |
87 |
error => "Reserve cannot be placed. Reason: $can_reserve" |
88 |
}, 403); |
88 |
} ); |
89 |
} |
89 |
} |
90 |
|
90 |
|
91 |
my $priority = C4::Reserves::CalculatePriority($biblionumber); |
91 |
my $priority = C4::Reserves::CalculatePriority($biblionumber); |
Lines 101-124
sub add {
Link Here
|
101 |
$biblio->{title}, $itemnumber); |
101 |
$biblio->{title}, $itemnumber); |
102 |
|
102 |
|
103 |
unless ($reserve_id) { |
103 |
unless ($reserve_id) { |
104 |
return $c->$cb({ |
104 |
return $c->render( status => 500, openapi => { |
105 |
error => "Error while placing reserve. See Koha logs for details." |
105 |
error => "Error while placing reserve. See Koha logs for details." |
106 |
}, 500); |
106 |
} ); |
107 |
} |
107 |
} |
108 |
|
108 |
|
109 |
my $reserve = Koha::Holds->find($reserve_id); |
109 |
my $reserve = Koha::Holds->find($reserve_id); |
110 |
|
110 |
|
111 |
return $c->$cb($reserve, 201); |
111 |
return $c->render( status => 201, openapi => $reserve ); |
112 |
} |
112 |
} |
113 |
|
113 |
|
114 |
sub edit { |
114 |
sub edit { |
115 |
my ($c, $args, $cb) = @_; |
115 |
my $c = shift->openapi->valid_input or return; |
116 |
|
116 |
|
117 |
my $reserve_id = $args->{reserve_id}; |
117 |
my $reserve_id = $c->validation->param('reserve_id'); |
118 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
118 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
119 |
|
119 |
|
120 |
unless ($reserve) { |
120 |
unless ($reserve) { |
121 |
return $c->$cb({error => "Reserve not found"}, 404); |
121 |
return $c->render( status => 404, |
|
|
122 |
openapi => {error => "Reserve not found"} ); |
122 |
} |
123 |
} |
123 |
|
124 |
|
124 |
my $body = $c->req->json; |
125 |
my $body = $c->req->json; |
Lines 141-162
sub edit {
Link Here
|
141 |
C4::Reserves::ModReserve($params); |
142 |
C4::Reserves::ModReserve($params); |
142 |
$reserve = Koha::Holds->find($reserve_id); |
143 |
$reserve = Koha::Holds->find($reserve_id); |
143 |
|
144 |
|
144 |
return $c->$cb($reserve, 200); |
145 |
return $c->render( status => 200, openapi => $reserve ); |
145 |
} |
146 |
} |
146 |
|
147 |
|
147 |
sub delete { |
148 |
sub delete { |
148 |
my ($c, $args, $cb) = @_; |
149 |
my $c = shift->openapi->valid_input or return; |
149 |
|
150 |
|
150 |
my $reserve_id = $args->{reserve_id}; |
151 |
my $reserve_id = $c->validation->param('reserve_id'); |
151 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
152 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
152 |
|
153 |
|
153 |
unless ($reserve) { |
154 |
unless ($reserve) { |
154 |
return $c->$cb({error => "Reserve not found"}, 404); |
155 |
return $c->render( status => 404, openapi => {error => "Reserve not found"} ); |
155 |
} |
156 |
} |
156 |
|
157 |
|
157 |
C4::Reserves::CancelReserve({ reserve_id => $reserve_id }); |
158 |
C4::Reserves::CancelReserve({ reserve_id => $reserve_id }); |
158 |
|
159 |
|
159 |
return $c->$cb({}, 200); |
160 |
return $c->render( status => 200, openapi => {} ); |
160 |
} |
161 |
} |
161 |
|
162 |
|
162 |
1; |
163 |
1; |