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