|
Lines 75-83
sub add {
Link Here
|
| 75 |
my $c = shift->openapi->valid_input or return; |
75 |
my $c = shift->openapi->valid_input or return; |
| 76 |
|
76 |
|
| 77 |
return try { |
77 |
return try { |
| 78 |
my $booking = Koha::Booking->new_from_api( $c->req->json ); |
78 |
my $body = $c->req->json; |
| 79 |
$booking->store; |
79 |
my $extended_attributes = delete $body->{extended_attributes} // []; |
| 80 |
$booking->discard_changes; |
80 |
|
|
|
81 |
my $booking = Koha::Booking->new_from_api($body)->store; |
| 82 |
|
| 83 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
| 84 |
$booking->extended_attributes( \@extended_attributes ); |
| 85 |
|
| 81 |
$c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); |
86 |
$c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); |
| 82 |
return $c->render( |
87 |
return $c->render( |
| 83 |
status => 201, |
88 |
status => 201, |
|
Lines 117-125
sub update {
Link Here
|
| 117 |
unless $booking; |
122 |
unless $booking; |
| 118 |
|
123 |
|
| 119 |
return try { |
124 |
return try { |
| 120 |
$booking->set_from_api( $c->req->json ); |
125 |
my $body = $c->req->json; |
| 121 |
$booking->store(); |
126 |
my $extended_attributes = delete $body->{extended_attributes} // []; |
| 122 |
$booking->discard_changes; |
127 |
|
|
|
128 |
$booking->set_from_api($body)->store; |
| 129 |
|
| 130 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
| 131 |
$booking->extended_attributes( \@extended_attributes ); |
| 132 |
|
| 123 |
return $c->render( status => 200, openapi => $c->objects->to_api($booking) ); |
133 |
return $c->render( status => 200, openapi => $c->objects->to_api($booking) ); |
| 124 |
} catch { |
134 |
} catch { |
| 125 |
$c->unhandled_exception($_); |
135 |
$c->unhandled_exception($_); |