Lines 87-99
Controller function that handles adding a new Koha::Acquisition::Bookseller obje
Link Here
|
87 |
sub add { |
87 |
sub add { |
88 |
my $c = shift->openapi->valid_input or return; |
88 |
my $c = shift->openapi->valid_input or return; |
89 |
|
89 |
|
90 |
my $vendor = $c->req->json; |
90 |
my $vendor = $c->req->json; |
91 |
my $contacts = delete $vendor->{contacts}; |
91 |
my $contacts = delete $vendor->{contacts}; |
92 |
my $interfaces = delete $vendor->{interfaces}; |
92 |
my $interfaces = delete $vendor->{interfaces}; |
93 |
my $aliases = delete $vendor->{aliases}; |
93 |
my $aliases = delete $vendor->{aliases}; |
94 |
my $subscriptions = delete $vendor->{subscriptions}; |
94 |
my $subscriptions = delete $vendor->{subscriptions}; |
95 |
my $baskets = delete $vendor->{baskets}; |
95 |
my $baskets = delete $vendor->{baskets}; |
96 |
my $contracts = delete $vendor->{contracts}; |
96 |
my $contracts = delete $vendor->{contracts}; |
|
|
97 |
my $extended_attributes = delete $vendor->{extended_attributes}; |
97 |
|
98 |
|
98 |
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); |
99 |
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); |
99 |
|
100 |
|
Lines 101-108
sub add {
Link Here
|
101 |
$vendor_to_store->store; |
102 |
$vendor_to_store->store; |
102 |
|
103 |
|
103 |
$vendor_to_store->contacts($contacts) if scalar($contacts) > 0; |
104 |
$vendor_to_store->contacts($contacts) if scalar($contacts) > 0; |
104 |
$vendor_to_store->aliases($aliases) if scalar($aliases) > 0; |
105 |
$vendor_to_store->aliases($aliases) if scalar(@$aliases) > 0; |
105 |
$vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0; |
106 |
$vendor_to_store->interfaces($interfaces) if scalar(@$interfaces) > 0; |
|
|
107 |
|
108 |
if(scalar(@$extended_attributes) > 0) { |
109 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
110 |
$vendor_to_store->extended_attributes( \@extended_attributes ); |
111 |
} |
106 |
|
112 |
|
107 |
$c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); |
113 |
$c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); |
108 |
return $c->render( |
114 |
return $c->render( |
Lines 131-150
sub update {
Link Here
|
131 |
unless $vendor; |
137 |
unless $vendor; |
132 |
|
138 |
|
133 |
return try { |
139 |
return try { |
134 |
my $vendor_update = $c->req->json; |
140 |
my $vendor_update = $c->req->json; |
135 |
my $contacts = delete $vendor_update->{contacts}; |
141 |
my $contacts = delete $vendor_update->{contacts}; |
136 |
my $interfaces = delete $vendor_update->{interfaces}; |
142 |
my $interfaces = delete $vendor_update->{interfaces}; |
137 |
my $aliases = delete $vendor_update->{aliases}; |
143 |
my $aliases = delete $vendor_update->{aliases}; |
138 |
my $subscriptions = delete $vendor_update->{subscriptions}; |
144 |
my $subscriptions = delete $vendor_update->{subscriptions}; |
139 |
my $baskets = delete $vendor_update->{baskets}; |
145 |
my $baskets = delete $vendor_update->{baskets}; |
140 |
my $contracts = delete $vendor_update->{contracts}; |
146 |
my $contracts = delete $vendor_update->{contracts}; |
|
|
147 |
my $extended_attributes = delete $vendor_update->{extended_attributes}; |
141 |
|
148 |
|
142 |
$vendor->set_from_api($vendor_update); |
149 |
$vendor->set_from_api($vendor_update); |
143 |
$vendor->store(); |
150 |
$vendor->store(); |
144 |
|
151 |
|
145 |
$vendor->contacts($contacts) if scalar($contacts) > 0; |
152 |
$vendor->contacts($contacts) if scalar($contacts) > 0; |
146 |
$vendor->aliases($aliases) if scalar($aliases) > 0; |
153 |
$vendor->aliases($aliases) if scalar(@$aliases) > 0; |
147 |
$vendor->interfaces($interfaces) if scalar($interfaces) > 0; |
154 |
$vendor->interfaces($interfaces) if scalar(@$interfaces) > 0; |
|
|
155 |
|
156 |
if ( scalar(@$extended_attributes) > 0 ) { |
157 |
my @extended_attributes = |
158 |
map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
159 |
$vendor->extended_attributes( \@extended_attributes ); |
160 |
} |
148 |
|
161 |
|
149 |
return $c->render( |
162 |
return $c->render( |
150 |
status => 200, |
163 |
status => 200, |