|
Lines 81-86
sub add {
Link Here
|
| 81 |
openapi => $c->objects->to_api($source) |
81 |
openapi => $c->objects->to_api($source) |
| 82 |
); |
82 |
); |
| 83 |
} catch { |
83 |
} catch { |
|
|
84 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
| 85 |
return $c->render( |
| 86 |
status => 409, |
| 87 |
openapi => { error => 'Duplicate name.' } |
| 88 |
); |
| 89 |
} elsif ( blessed $_ and $_->isa('Koha::Exceptions::BadParameter') ) { |
| 90 |
return $c->render( |
| 91 |
status => 409, |
| 92 |
openapi => { error => 'Name not allowed.' } |
| 93 |
); |
| 94 |
} |
| 84 |
$c->unhandled_exception($_); |
95 |
$c->unhandled_exception($_); |
| 85 |
}; |
96 |
}; |
| 86 |
} |
97 |
} |
|
Lines 97-107
sub update {
Link Here
|
| 97 |
return $c->render_resource_not_found("Record source") |
108 |
return $c->render_resource_not_found("Record source") |
| 98 |
unless $source; |
109 |
unless $source; |
| 99 |
|
110 |
|
|
|
111 |
if ( $source->is_system ) { |
| 112 |
return $c->render( |
| 113 |
status => 409, |
| 114 |
openapi => { error => 'Cannot edit system defined value.' } |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 100 |
return try { |
118 |
return try { |
| 101 |
$source->set_from_api( $c->req->json )->store; |
119 |
$source->set_from_api( $c->req->json )->store; |
| 102 |
$source->discard_changes; |
120 |
$source->discard_changes; |
| 103 |
return $c->render( status => 200, openapi => $c->objects->to_api($source) ); |
121 |
return $c->render( status => 200, openapi => $c->objects->to_api($source) ); |
| 104 |
} catch { |
122 |
} catch { |
|
|
123 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
| 124 |
return $c->render( |
| 125 |
status => 409, |
| 126 |
openapi => { error => 'Duplicate name.' } |
| 127 |
); |
| 128 |
} elsif ( blessed $_ and $_->isa('Koha::Exceptions::BadParameter') ) { |
| 129 |
return $c->render( |
| 130 |
status => 409, |
| 131 |
openapi => { error => 'Name not allowed.' } |
| 132 |
); |
| 133 |
} |
| 105 |
$c->unhandled_exception($_); |
134 |
$c->unhandled_exception($_); |
| 106 |
}; |
135 |
}; |
| 107 |
} |
136 |
} |
|
Lines 131-136
sub delete {
Link Here
|
| 131 |
} |
160 |
} |
| 132 |
); |
161 |
); |
| 133 |
} |
162 |
} |
|
|
163 |
elsif ( blessed $_ and $_->isa('Koha::Exceptions::CannotDeleteDefault') ) { |
| 164 |
return $c->render( |
| 165 |
status => 409, |
| 166 |
openapi => { |
| 167 |
error => 'Cannot delete system defined record source', |
| 168 |
error_code => 'cannot_delete_is_system', |
| 169 |
} |
| 170 |
); |
| 171 |
} |
| 134 |
$c->unhandled_exception($_); |
172 |
$c->unhandled_exception($_); |
| 135 |
}; |
173 |
}; |
| 136 |
} |
174 |
} |