|
|
|
@ -82,112 +82,6 @@ sub OPTIONS :Allow {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub PATCH :Allow {
|
|
|
|
|
my ($self, $c, $id) = @_;
|
|
|
|
|
my $guard = $c->model('DB')->txn_scope_guard;
|
|
|
|
|
{
|
|
|
|
|
my $preference = $self->require_preference($c);
|
|
|
|
|
last unless $preference;
|
|
|
|
|
|
|
|
|
|
my $json = $self->get_valid_patch_data(
|
|
|
|
|
c => $c,
|
|
|
|
|
id => $id,
|
|
|
|
|
media_type => 'application/json-patch+json',
|
|
|
|
|
);
|
|
|
|
|
last unless $json;
|
|
|
|
|
|
|
|
|
|
my $item = $self->item_by_id($c, $id);
|
|
|
|
|
last unless $self->resource_exists($c, invoicetemplate => $item);
|
|
|
|
|
my $old_resource = { $item->get_inflated_columns };
|
|
|
|
|
my $resource = $self->apply_patch($c, $old_resource, $json);
|
|
|
|
|
last unless $resource;
|
|
|
|
|
|
|
|
|
|
my $form = $self->get_form($c);
|
|
|
|
|
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
|
|
|
|
|
last unless $item;
|
|
|
|
|
|
|
|
|
|
$guard->commit;
|
|
|
|
|
|
|
|
|
|
if ('minimal' eq $preference) {
|
|
|
|
|
$c->response->status(HTTP_NO_CONTENT);
|
|
|
|
|
$c->response->header(Preference_Applied => 'return=minimal');
|
|
|
|
|
$c->response->body(q());
|
|
|
|
|
} else {
|
|
|
|
|
my $hal = $self->hal_from_item($c, $item, $form);
|
|
|
|
|
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
|
|
|
|
|
$hal->http_headers,
|
|
|
|
|
), $hal->as_json);
|
|
|
|
|
$c->response->headers($response->headers);
|
|
|
|
|
$c->response->header(Preference_Applied => 'return=representation');
|
|
|
|
|
$c->response->body($response->content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub PUT :Allow {
|
|
|
|
|
my ($self, $c, $id) = @_;
|
|
|
|
|
my $guard = $c->model('DB')->txn_scope_guard;
|
|
|
|
|
{
|
|
|
|
|
my $preference = $self->require_preference($c);
|
|
|
|
|
last unless $preference;
|
|
|
|
|
|
|
|
|
|
my $item = $self->item_by_id($c, $id);
|
|
|
|
|
last unless $self->resource_exists($c, invoicetemplate => $item);
|
|
|
|
|
my $resource = $self->get_valid_put_data(
|
|
|
|
|
c => $c,
|
|
|
|
|
id => $id,
|
|
|
|
|
media_type => 'application/json',
|
|
|
|
|
);
|
|
|
|
|
last unless $resource;
|
|
|
|
|
my $old_resource = { $item->get_inflated_columns };
|
|
|
|
|
|
|
|
|
|
my $form = $self->get_form($c);
|
|
|
|
|
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
|
|
|
|
|
last unless $item;
|
|
|
|
|
|
|
|
|
|
$guard->commit;
|
|
|
|
|
|
|
|
|
|
if ('minimal' eq $preference) {
|
|
|
|
|
$c->response->status(HTTP_NO_CONTENT);
|
|
|
|
|
$c->response->header(Preference_Applied => 'return=minimal');
|
|
|
|
|
$c->response->body(q());
|
|
|
|
|
} else {
|
|
|
|
|
my $hal = $self->hal_from_item($c, $item, $form);
|
|
|
|
|
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
|
|
|
|
|
$hal->http_headers,
|
|
|
|
|
), $hal->as_json);
|
|
|
|
|
$c->response->headers($response->headers);
|
|
|
|
|
$c->response->header(Preference_Applied => 'return=representation');
|
|
|
|
|
$c->response->body($response->content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub DELETE :Allow {
|
|
|
|
|
my ($self, $c, $id) = @_;
|
|
|
|
|
|
|
|
|
|
my $guard = $c->model('DB')->txn_scope_guard;
|
|
|
|
|
{
|
|
|
|
|
my $item = $self->item_by_id($c, $id);
|
|
|
|
|
last unless $self->resource_exists($c, invoicetemplate => $item);
|
|
|
|
|
$c->model('DB')->resultset('contracts')->search({
|
|
|
|
|
'invoice_template_id' => $item->id,
|
|
|
|
|
})->update({
|
|
|
|
|
'invoice_template_id' => undef,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$item->delete;
|
|
|
|
|
|
|
|
|
|
$guard->commit;
|
|
|
|
|
|
|
|
|
|
$c->response->status(HTTP_NO_CONTENT);
|
|
|
|
|
$c->response->body(q());
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub end : Private {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|