1 package Koha::REST::V1::ImportRecordMatches;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
22 use Koha::Import::Record::Matches;
34 Method that handles unselecting all chosen matches for an import record
36 DELETE /api/v1/import/{import_batch_id}/records/{import_record_id}/matches/chosen
41 my $c = shift->openapi->valid_input or return;
43 my $import_record_id = $c->validation->param('import_record_id');
44 my $matches = Koha::Import::Record::Matches->search({
45 import_record_id => $import_record_id,
50 openapi => { error => "No matches not found" }
54 $matches->update({ chosen => 0 });
55 return $c->render( status => 204, openapi => $matches );
58 $c->unhandled_exception($_);
64 Method that handles modifying if a Koha::Import::Record::Match object has been chosen for overlay
66 PUT /api/v1/import/{import_batch_id}/records/{import_record_id}/matches/chosen
68 Body should contain the condidate_match_id to chose
73 my $c = shift->openapi->valid_input or return;
75 my $import_record_id = $c->validation->param('import_record_id');
76 my $body = $c->validation->param('body');
77 my $candidate_match_id = $body->{'candidate_match_id'};
79 my $match = Koha::Import::Record::Matches->find({
80 import_record_id => $import_record_id,
81 candidate_match_id => $candidate_match_id
87 openapi => { error => "Match not found" }
92 my $matches = Koha::Import::Record::Matches->search({
93 import_record_id => $import_record_id,
96 $matches->update({ chosen => 0}) if $matches;
97 $match->set_from_api({ chosen => JSON::true });
99 return $c->render( status => 200, openapi => $match );
102 $c->unhandled_exception($_);