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

(-)a/Koha/REST/V1/Suggestions.pm (+179 lines)
Line 0 Link Here
1
package Koha::REST::V1::Suggestions;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with Koha; if not, see <http:°www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Mojo::Base 'Mojolicious::Controller';
20
21
use Koha::Suggestions;
22
23
use Try::Tiny;
24
25
=head1 NAME
26
27
Koha::REST::V1::Suggestion
28
29
=head1 API
30
31
=head2 Methods
32
33
=head3 list
34
35
Controller method that handles listing Koha::Suggestion objects
36
37
=cut
38
39
sub list {
40
    my $c = shift->openapi->valid_input or return;
41
42
    return try {
43
44
        my $suggestions = $c->objects->search( Koha::Suggestions->new );
45
46
        return $c->render(
47
            status  => 200,
48
            openapi => $suggestions
49
        );
50
    }
51
    catch {
52
        $c->unhandled_exception($_);
53
    };
54
}
55
56
=head3 get
57
58
Controller method that handles retrieving a single Koha::Suggestion object
59
60
=cut
61
62
sub get {
63
    my $c = shift->openapi->valid_input or return;
64
65
    return try {
66
        my $suggestion_id = $c->validation->param('suggestion_id');
67
        my $suggestion = $c->objects->find( Koha::Suggestions->new, $suggestion_id );
68
69
        unless ($suggestion) {
70
            return $c->render(
71
                status  => 404,
72
                openapi => { error => "Suggestion not found." }
73
            );
74
        }
75
76
        return $c->render(
77
            status  => 200,
78
            openapi => $suggestion
79
        );
80
    }
81
    catch {
82
        $c->unhandled_exception($_);
83
    };
84
}
85
86
=head3 add
87
88
Controller method that handles adding a new Koha::Suggestion object
89
90
=cut
91
92
sub add {
93
    my $c = shift->openapi->valid_input or return;
94
95
    my $body = $c->validation->param('body');
96
97
    # FIXME: This should be handled in Koha::Suggestion->store
98
    $body->{'status'} = 'ASKED'
99
        unless defined $body->{'status'};
100
101
    return try {
102
        my $suggestion = Koha::Suggestion->new_from_api( $body )->store;
103
        $c->res->headers->location( $c->req->url->to_string . '/' . $suggestion->suggestionid );
104
105
        return $c->render(
106
            status  => 201,
107
            openapi => $suggestion->to_api
108
        );
109
    }
110
    catch {
111
        $c->unhandled_exception($_);
112
    };
113
}
114
115
=head3 update
116
117
Controller method that handles modifying Koha::Suggestion object
118
119
=cut
120
121
sub update {
122
    my $c = shift->openapi->valid_input or return;
123
124
    my $suggestion_id = $c->validation->param('suggestion_id');
125
    my $suggestion = Koha::Suggestions->find( $suggestion_id );
126
127
    return $c->render(
128
        status  => 404,
129
        openapi => { error => 'Suggestion not found.' }
130
    ) unless $suggestion;
131
132
    return try {
133
134
        my $body = $c->validation->param('body');
135
136
        $suggestion->set_from_api( $body )->store;
137
        $suggestion->discard_changes;
138
139
        return $c->render(
140
            status  => 200,
141
            openapi => $suggestion->to_api
142
        );
143
    }
144
    catch {
145
        $c->unhandled_exception($_);
146
    };
147
148
}
149
150
=head3 delete
151
152
Controller method that handles removing a Koha::Suggestion object
153
154
=cut
155
156
sub delete {
157
    my $c = shift->openapi->valid_input or return;
158
159
    my $suggestion_id = $c->validation->param('suggestion_id');
160
    my $suggestion = Koha::Suggestions->find( $suggestion_id );
161
162
    return $c->render(
163
        status  => 404,
164
        openapi => { error => 'Suggestion not found.' }
165
    ) unless $suggestion;
166
167
    return try {
168
        $suggestion->delete;
169
        return $c->render(
170
            status  => 200,
171
            openapi => q{}
172
        );
173
    }
174
    catch {
175
        $c->unhandled_exception($_);
176
    };
177
}
178
179
1;
(-)a/Koha/Suggestion.pm (-1 / +46 lines)
Lines 139-144 sub _type { Link Here
139
    return 'Suggestion';
139
    return 'Suggestion';
140
}
140
}
141
141
142
=head3 to_api_mapping
143
144
This method returns the mapping for representing a Koha::Patron object
145
on the API.
146
147
=cut
148
149
sub to_api_mapping {
150
    return {
151
        suggestionid         => 'suggestion_id',
152
        suggestedby          => 'suggested_by',
153
        suggesteddate        => 'suggestion_date',
154
        managedby            => 'managed_by',
155
        manageddate          => 'managed_date',
156
        acceptedby           => 'accepted_by',
157
        accepteddate         => 'accepted_date',
158
        rejectedby           => 'rejected_by',
159
        rejecteddate         => 'rejected_date',
160
        lastmodificationdate => 'last_modification_date',
161
        lastmodificationby   => 'last_modification_by',
162
        STATUS               => 'status',
163
        note                 => 'note',
164
        author               => 'author',
165
        title                => 'title',
166
        copyrightdate        => 'copyright_date',
167
        publishercode        => 'publisher_code',
168
        date                 => 'date_created',
169
        volumedesc           => 'volume_desc',
170
        publicationyear      => 'publication_year',
171
        place                => 'publication_place',
172
        isbn                 => 'isbn',
173
        biblionumber         => 'biblio_id',
174
        reason               => 'reason',
175
        patronreason         => 'patron_reason',
176
        budgetid             => 'budget_id',
177
        branchcode           => 'library_id',
178
        collectiontitle      => 'collection_title',
179
        itemtype             => 'item_type',
180
        quantity             => 'quantity',
181
        currency             => 'currency',
182
        price                => 'item_price',
183
        total                => 'total_price',
184
        archived             => 'archived',
185
    };
186
}
187
142
=head1 AUTHOR
188
=head1 AUTHOR
143
189
144
Kyle M Hall <kyle@bywatersolutions.com>
190
Kyle M Hall <kyle@bywatersolutions.com>
145
- 

Return to bug 17314