View | Details | Raw Unified | Return to bug 38010
Collapse All | Expand All

(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-7 / +26 lines)
Lines 87-96 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};
95
    my $baskets       = delete $vendor->{baskets};
96
    my $contracts     = delete $vendor->{contracts};
94
97
95
    my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
98
    my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
96
99
Lines 124-138 Controller function that handles updating a Koha::Acquisition::Bookseller object Link Here
124
sub update {
127
sub update {
125
    my $c = shift->openapi->valid_input or return;
128
    my $c = shift->openapi->valid_input or return;
126
129
127
    my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
130
    my $vendor_id = $c->param('vendor_id');
131
    my $vendor = Koha::Acquisition::Booksellers->find( $vendor_id );
128
132
129
    return $c->render_resource_not_found("Vendor")
133
    return $c->render_resource_not_found("Vendor")
130
        unless $vendor;
134
        unless $vendor;
131
135
132
    return try {
136
    return try {
133
        $vendor->set_from_api( $c->req->json );
137
        my $vendor_update = $c->req->json;
138
        my $contacts      = delete $vendor_update->{contacts};
139
        my $interfaces    = delete $vendor_update->{interfaces};
140
        my $aliases       = delete $vendor_update->{aliases};
141
        my $subscriptions = delete $vendor_update->{subscriptions};
142
        my $baskets       = delete $vendor_update->{baskets};
143
        my $contracts     = delete $vendor_update->{contracts};
144
145
        $vendor->set_from_api($vendor_update);
134
        $vendor->store();
146
        $vendor->store();
135
147
148
        foreach my $contact (@$contacts) {
149
            $contact->{booksellerid} = $vendor_id;
150
            Koha::Acquisition::Bookseller::Contact->new($contact)->store;
151
        }
152
        $vendor->aliases($aliases)       if scalar($aliases) > 0;
153
        $vendor->interfaces($interfaces) if scalar($interfaces) > 0;
154
136
        return $c->render(
155
        return $c->render(
137
            status  => 200,
156
            status  => 200,
138
            openapi => $c->objects->to_api($vendor),
157
            openapi => $c->objects->to_api($vendor),
Lines 143-148 sub update { Link Here
143
162
144
}
163
}
145
164
165
146
=head3 delete
166
=head3 delete
147
167
148
Controller function that handles deleting a Koha::Acquisition::Bookseller object
168
Controller function that handles deleting a Koha::Acquisition::Bookseller object
149
- 

Return to bug 38010