|
Lines 85-94
Controller function that handles adding a new Koha::Acquisition::Bookseller obje
Link Here
|
| 85 |
sub add { |
85 |
sub add { |
| 86 |
my $c = shift->openapi->valid_input or return; |
86 |
my $c = shift->openapi->valid_input or return; |
| 87 |
|
87 |
|
| 88 |
my $vendor = $c->req->json; |
88 |
my $vendor = $c->req->json; |
| 89 |
my $contacts = delete $vendor->{contacts}; |
89 |
my $contacts = delete $vendor->{contacts}; |
| 90 |
my $interfaces = delete $vendor->{interfaces}; |
90 |
my $interfaces = delete $vendor->{interfaces}; |
| 91 |
my $aliases = delete $vendor->{aliases}; |
91 |
my $aliases = delete $vendor->{aliases}; |
|
|
92 |
my $subscriptions = delete $vendor->{subscriptions}; |
| 93 |
my $baskets = delete $vendor->{baskets}; |
| 94 |
my $contracts = delete $vendor->{contracts}; |
| 92 |
|
95 |
|
| 93 |
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); |
96 |
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); |
| 94 |
|
97 |
|
|
Lines 121-135
Controller function that handles updating a Koha::Acquisition::Bookseller object
Link Here
|
| 121 |
sub update { |
124 |
sub update { |
| 122 |
my $c = shift->openapi->valid_input or return; |
125 |
my $c = shift->openapi->valid_input or return; |
| 123 |
|
126 |
|
| 124 |
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') ); |
127 |
my $vendor_id = $c->param('vendor_id'); |
|
|
128 |
my $vendor = Koha::Acquisition::Booksellers->find($vendor_id); |
| 125 |
|
129 |
|
| 126 |
return $c->render_resource_not_found("Vendor") |
130 |
return $c->render_resource_not_found("Vendor") |
| 127 |
unless $vendor; |
131 |
unless $vendor; |
| 128 |
|
132 |
|
| 129 |
return try { |
133 |
return try { |
| 130 |
$vendor->set_from_api( $c->req->json ); |
134 |
my $vendor_update = $c->req->json; |
|
|
135 |
my $contacts = delete $vendor_update->{contacts}; |
| 136 |
my $interfaces = delete $vendor_update->{interfaces}; |
| 137 |
my $aliases = delete $vendor_update->{aliases}; |
| 138 |
my $subscriptions = delete $vendor_update->{subscriptions}; |
| 139 |
my $baskets = delete $vendor_update->{baskets}; |
| 140 |
my $contracts = delete $vendor_update->{contracts}; |
| 141 |
|
| 142 |
$vendor->set_from_api($vendor_update); |
| 131 |
$vendor->store(); |
143 |
$vendor->store(); |
| 132 |
|
144 |
|
|
|
145 |
foreach my $contact (@$contacts) { |
| 146 |
$contact->{booksellerid} = $vendor_id; |
| 147 |
Koha::Acquisition::Bookseller::Contact->new($contact)->store; |
| 148 |
} |
| 149 |
$vendor->aliases($aliases) if scalar($aliases) > 0; |
| 150 |
$vendor->interfaces($interfaces) if scalar($interfaces) > 0; |
| 151 |
|
| 133 |
return $c->render( |
152 |
return $c->render( |
| 134 |
status => 200, |
153 |
status => 200, |
| 135 |
openapi => $c->objects->to_api($vendor), |
154 |
openapi => $c->objects->to_api($vendor), |
| 136 |
- |
|
|