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 104-111
sub add {
Link Here
|
104 |
$contact->{booksellerid} = $vendor_to_store->id; |
105 |
$contact->{booksellerid} = $vendor_to_store->id; |
105 |
Koha::Acquisition::Bookseller::Contact->new($contact)->store; |
106 |
Koha::Acquisition::Bookseller::Contact->new($contact)->store; |
106 |
} |
107 |
} |
107 |
$vendor_to_store->aliases($aliases) if scalar($aliases) > 0; |
108 |
$vendor_to_store->aliases($aliases) if scalar(@$aliases) > 0; |
108 |
$vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0; |
109 |
$vendor_to_store->interfaces($interfaces) if scalar(@$interfaces) > 0; |
|
|
110 |
|
111 |
if(scalar(@$extended_attributes) > 0) { |
112 |
my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
113 |
$vendor_to_store->extended_attributes( \@extended_attributes ); |
114 |
} |
109 |
|
115 |
|
110 |
$c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); |
116 |
$c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); |
111 |
return $c->render( |
117 |
return $c->render( |
Lines 134-146
sub update {
Link Here
|
134 |
unless $vendor; |
140 |
unless $vendor; |
135 |
|
141 |
|
136 |
return try { |
142 |
return try { |
137 |
my $vendor_update = $c->req->json; |
143 |
my $vendor_update = $c->req->json; |
138 |
my $contacts = delete $vendor_update->{contacts}; |
144 |
my $contacts = delete $vendor_update->{contacts}; |
139 |
my $interfaces = delete $vendor_update->{interfaces}; |
145 |
my $interfaces = delete $vendor_update->{interfaces}; |
140 |
my $aliases = delete $vendor_update->{aliases}; |
146 |
my $aliases = delete $vendor_update->{aliases}; |
141 |
my $subscriptions = delete $vendor_update->{subscriptions}; |
147 |
my $subscriptions = delete $vendor_update->{subscriptions}; |
142 |
my $baskets = delete $vendor_update->{baskets}; |
148 |
my $baskets = delete $vendor_update->{baskets}; |
143 |
my $contracts = delete $vendor_update->{contracts}; |
149 |
my $contracts = delete $vendor_update->{contracts}; |
|
|
150 |
my $extended_attributes = delete $vendor_update->{extended_attributes}; |
144 |
|
151 |
|
145 |
$vendor->set_from_api($vendor_update); |
152 |
$vendor->set_from_api($vendor_update); |
146 |
$vendor->store(); |
153 |
$vendor->store(); |
Lines 149-156
sub update {
Link Here
|
149 |
$contact->{booksellerid} = $vendor_id; |
156 |
$contact->{booksellerid} = $vendor_id; |
150 |
Koha::Acquisition::Bookseller::Contact->new($contact)->store; |
157 |
Koha::Acquisition::Bookseller::Contact->new($contact)->store; |
151 |
} |
158 |
} |
152 |
$vendor->aliases($aliases) if scalar($aliases) > 0; |
159 |
$vendor->aliases($aliases) if scalar(@$aliases) > 0; |
153 |
$vendor->interfaces($interfaces) if scalar($interfaces) > 0; |
160 |
$vendor->interfaces($interfaces) if scalar(@$interfaces) > 0; |
|
|
161 |
|
162 |
if ( scalar(@$extended_attributes) > 0 ) { |
163 |
my @extended_attributes = |
164 |
map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; |
165 |
$vendor->extended_attributes( \@extended_attributes ); |
166 |
} |
154 |
|
167 |
|
155 |
return $c->render( |
168 |
return $c->render( |
156 |
status => 200, |
169 |
status => 200, |