Lines 27-46
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; |
34 |
foreach my $key (keys %$params) { |
34 |
foreach my $key (keys %$params) { |
35 |
delete $params->{$key} unless grep { $key eq $_ } @valid_params; |
35 |
delete $params->{$key} unless grep { $key eq $_ } @valid_params; |
36 |
} |
36 |
} |
37 |
my $holds = Koha::Holds->search($params)->unblessed; |
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 = C4::Reserves::GetReserve($reserve_id); |
109 |
my $hold = Koha::Holds->find($reserve_id); |
110 |
|
110 |
|
111 |
return $c->$cb($reserve, 201); |
111 |
return $c->render( status => 201, openapi => $hold ); |
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 138-161
sub edit {
Link Here
|
138 |
suspend_until => $suspend_until, |
139 |
suspend_until => $suspend_until, |
139 |
}; |
140 |
}; |
140 |
C4::Reserves::ModReserve($params); |
141 |
C4::Reserves::ModReserve($params); |
141 |
$reserve = C4::Reserves::GetReserve($reserve_id); |
142 |
$reserve = Koha::Holds->find($reserve_id); |
142 |
|
143 |
|
143 |
return $c->$cb($reserve, 200); |
144 |
return $c->render( status => 200, openapi => $reserve ); |
144 |
} |
145 |
} |
145 |
|
146 |
|
146 |
sub delete { |
147 |
sub delete { |
147 |
my ($c, $args, $cb) = @_; |
148 |
my $c = shift->openapi->valid_input or return; |
148 |
|
149 |
|
149 |
my $reserve_id = $args->{reserve_id}; |
150 |
my $reserve_id = $c->validation->param('reserve_id'); |
150 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
151 |
my $reserve = C4::Reserves::GetReserve($reserve_id); |
151 |
|
152 |
|
152 |
unless ($reserve) { |
153 |
unless ($reserve) { |
153 |
return $c->$cb({error => "Reserve not found"}, 404); |
154 |
return $c->render( status => 404, openapi => {error => "Reserve not found"} ); |
154 |
} |
155 |
} |
155 |
|
156 |
|
156 |
C4::Reserves::CancelReserve({ reserve_id => $reserve_id }); |
157 |
C4::Reserves::CancelReserve({ reserve_id => $reserve_id }); |
157 |
|
158 |
|
158 |
return $c->$cb({}, 200); |
159 |
return $c->render( status => 200, openapi => {} ); |
159 |
} |
160 |
} |
160 |
|
161 |
|
161 |
1; |
162 |
1; |