|
Lines 76-81
sub add {
Link Here
|
| 76 |
|
76 |
|
| 77 |
return try { |
77 |
return try { |
| 78 |
my $body = $c->req->json; |
78 |
my $body = $c->req->json; |
|
|
79 |
my $extended_attributes = delete $body->{extended_attributes} // []; |
| 79 |
|
80 |
|
| 80 |
# Validate that exactly one of item_id or itemtype_id is provided |
81 |
# Validate that exactly one of item_id or itemtype_id is provided |
| 81 |
my $has_item_id = defined $body->{item_id}; |
82 |
my $has_item_id = defined $body->{item_id}; |
|
Lines 106-112
sub add {
Link Here
|
| 106 |
} |
107 |
} |
| 107 |
|
108 |
|
| 108 |
$booking->store; |
109 |
$booking->store; |
|
|
110 |
|
| 111 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
| 112 |
$booking->extended_attributes( \@extended_attributes ); |
| 113 |
|
| 109 |
$booking->discard_changes; |
114 |
$booking->discard_changes; |
|
|
115 |
|
| 110 |
$c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); |
116 |
$c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); |
| 111 |
return $c->render( |
117 |
return $c->render( |
| 112 |
status => 201, |
118 |
status => 201, |
|
Lines 147-152
sub update {
Link Here
|
| 147 |
|
153 |
|
| 148 |
return try { |
154 |
return try { |
| 149 |
my $body = $c->req->json; |
155 |
my $body = $c->req->json; |
|
|
156 |
my $extended_attributes = delete $body->{extended_attributes} // []; |
| 150 |
|
157 |
|
| 151 |
# Extract and remove itemtype_id from body (it's not a database column) |
158 |
# Extract and remove itemtype_id from body (it's not a database column) |
| 152 |
my $itemtype_id = delete $body->{itemtype_id}; |
159 |
my $itemtype_id = delete $body->{itemtype_id}; |
|
Lines 159-165
sub update {
Link Here
|
| 159 |
} |
166 |
} |
| 160 |
|
167 |
|
| 161 |
$booking->store(); |
168 |
$booking->store(); |
|
|
169 |
|
| 170 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
| 171 |
$booking->extended_attributes( \@extended_attributes ); |
| 172 |
|
| 162 |
$booking->discard_changes; |
173 |
$booking->discard_changes; |
|
|
174 |
|
| 163 |
return $c->render( status => 200, openapi => $c->objects->to_api($booking) ); |
175 |
return $c->render( status => 200, openapi => $c->objects->to_api($booking) ); |
| 164 |
} catch { |
176 |
} catch { |
| 165 |
$c->unhandled_exception($_); |
177 |
$c->unhandled_exception($_); |