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 (+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>
(-)a/api/v1/swagger/definitions.json (+6 lines)
Lines 88-92 Link Here
88
  },
88
  },
89
  "smtp_server": {
89
  "smtp_server": {
90
    "$ref": "definitions/smtp_server.json"
90
    "$ref": "definitions/smtp_server.json"
91
  },
92
  "fund": {
93
    "$ref": "definitions/fund.json"
94
  },
95
  "suggestion": {
96
    "$ref": "definitions/suggestion.json"
91
  }
97
  }
92
}
98
}
(-)a/api/v1/swagger/definitions/suggestion.json (+154 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "suggestion_id": {
5
      "type": "string",
6
      "description": "unique identifier assigned automatically by Koha"
7
    },
8
    "suggested_by": {
9
      "type": ["string", "null"],
10
      "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table"
11
    },
12
    "suggestion_date": {
13
      "type": ["string", "null"],
14
      "format": "date",
15
      "description": "the suggestion was submitted"
16
    },
17
    "managed_by": {
18
      "type": ["string", "null"],
19
      "description": "patron_id for the librarian managing the suggestion, foreign key linking to the borrowers table"
20
    },
21
    "managed_date": {
22
      "type": ["string", "null"],
23
      "format": "date",
24
      "description": "date the suggestion was updated"
25
    },
26
    "accepted_by": {
27
      "type": ["string", "null"],
28
      "description": "patron_id for the librarian who accepted the suggestion, foreign key linking to the borrowers table"
29
    },
30
    "accepted_date": {
31
      "type": ["string", "null"],
32
      "format": "date",
33
      "description": "date the suggestion was marked as accepted"
34
    },
35
    "rejected_by": {
36
      "type": ["string", "null"],
37
      "description": "patron_id for the librarian who rejected the suggestion, foreign key linking to the borrowers table"
38
    },
39
    "rejected_date": {
40
      "type": ["string", "null"],
41
      "format": "date",
42
      "description": "date the suggestion was marked as rejected"
43
    },
44
    "last_modification_by": {
45
      "type": ["string", "null"],
46
      "description": "patron the suggestion was last modified by"
47
    },
48
    "last_modification_date": {
49
      "type": ["string", "null"],
50
      "format": "date",
51
      "description": "date the suggestion was last modified"
52
    },
53
    "status": {
54
      "type": "string",
55
      "description": "Suggestion status",
56
      "enum": [
57
        "ASKED",
58
        "CHECKED",
59
        "ACCEPTED",
60
        "REJECTED"
61
      ]
62
    },
63
    "note": {
64
      "type": ["string", "null"],
65
      "description": "note entered on the suggestion"
66
    },
67
    "author": {
68
      "type": ["string", "null"],
69
      "description": "author of the suggested item"
70
    },
71
    "title": {
72
      "type": ["string", "null"],
73
      "description": "title of the suggested item"
74
    },
75
    "copyright_date": {
76
      "type": ["string", "null"],
77
      "format": "date",
78
      "description": "copyright date of the suggested item"
79
    },
80
    "publisher_code": {
81
      "type": ["string", "null"],
82
      "description": "publisher of the suggested item"
83
    },
84
    "date_created": {
85
      "type": ["string", "null"],
86
      "description": "timestamp of date created"
87
    },
88
    "volume_desc": {
89
      "type": ["string", "null"],
90
      "description": "volume description"
91
    },
92
    "publication_year": {
93
      "type": ["string", "null"],
94
      "description": "year of publication"
95
    },
96
    "publication_place": {
97
      "type": ["string", "null"],
98
      "description": "publication place of the suggested item"
99
    },
100
    "isbn": {
101
      "type": ["string", "null"],
102
      "description": "isbn of the suggested item"
103
    },
104
    "biblio_id": {
105
      "type": ["string", "null"],
106
      "description": "foreign key linking the suggestion to the biblio table after the suggestion has been ordered"
107
    },
108
    "reason": {
109
      "type": ["string", "null"],
110
      "description": "reason for accepting or rejecting the suggestion"
111
    },
112
    "patron_reason": {
113
      "type": ["string", "null"],
114
      "description": "reason for making the suggestion"
115
    },
116
    "budget_id": {
117
      "type": ["string", "null"],
118
      "description": "foreign key linking the suggested budget to the aqbudgets table"
119
    },
120
    "library_id": {
121
      "type": ["string", "null"],
122
      "description": "foreign key linking the suggested branch to the branches table"
123
    },
124
    "collection_title": {
125
      "type": ["string", "null"],
126
      "description": "collection name for the suggested item"
127
    },
128
    "item_type": {
129
      "type": ["string", "null"],
130
      "description": "suggested item type"
131
    },
132
    "quantity": {
133
      "type": ["string", "null"],
134
      "description": "suggested quantity to be purchased"
135
    },
136
    "currency": {
137
      "type": ["string", "null"],
138
      "description": "suggested currency for the suggested price"
139
    },
140
    "item_price": {
141
      "type": ["number", "null"],
142
      "description": "suggested price"
143
    },
144
    "total_price": {
145
      "type": ["string", "null"],
146
      "description": "suggested total cost (price*quantity updated for currency)"
147
    },
148
    "archived": {
149
      "type": ["boolean", "null"],
150
      "description": "archived (processed) suggestion"
151
    }
152
  },
153
  "additionalProperties": false
154
}
(-)a/api/v1/swagger/parameters.json (+3 lines)
Lines 119-123 Link Here
119
  },
119
  },
120
  "fundidPathParam": {
120
  "fundidPathParam": {
121
    "$ref": "parameters/fund.json#/fundidPathParam"
121
    "$ref": "parameters/fund.json#/fundidPathParam"
122
  },
123
  "suggestion_id_pp": {
124
    "$ref": "parameters/suggestion.json#/suggestion_id_pp"
122
  }
125
  }
123
}
126
}
(-)a/api/v1/swagger/parameters/suggestion.json (+9 lines)
Line 0 Link Here
1
{
2
  "suggestion_id_pp": {
3
    "name": "suggestion_id",
4
    "in": "path",
5
    "description": "Internal suggestion identifier",
6
    "required": true,
7
    "type": "integer"
8
  }
9
}
(-)a/api/v1/swagger/paths.json (+6 lines)
Lines 181-185 Link Here
181
  },
181
  },
182
  "/return_claims/{claim_id}": {
182
  "/return_claims/{claim_id}": {
183
    "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}"
183
    "$ref": "paths/return_claims.json#/~1return_claims~1{claim_id}"
184
  },
185
  "/suggestions": {
186
    "$ref": "paths/suggestions.json#/~1suggestions"
187
  },
188
  "/suggestions/{suggestion_id}": {
189
    "$ref": "paths/suggestions.json#/~1suggestions~1{suggestion_id}"
184
  }
190
  }
185
}
191
}
(-)a/api/v1/swagger/paths/suggestions.json (-1 / +284 lines)
Line 0 Link Here
0
- 
1
{
2
  "/suggestions": {
3
    "get": {
4
      "x-mojo-to": "Suggestions#list",
5
      "operationId" : "list",
6
      "tags": ["patrons", "suggestions"],
7
      "parameters": [
8
        {
9
          "$ref": "../parameters.json#/match"
10
        },
11
        {
12
          "$ref": "../parameters.json#/order_by"
13
        },
14
        {
15
          "$ref": "../parameters.json#/page"
16
        },
17
        {
18
          "$ref": "../parameters.json#/per_page"
19
        },
20
        {
21
          "$ref": "../parameters.json#/q_param"
22
        },
23
        {
24
          "$ref": "../parameters.json#/q_body"
25
        },
26
        {
27
          "$ref": "../parameters.json#/q_header"
28
        }
29
      ],
30
      "produces": [
31
          "application/json"
32
      ],
33
      "responses": {
34
        "200": {
35
          "description": "A list of suggestions",
36
          "schema": {
37
            "type": "array",
38
            "items": {
39
              "$ref": "../definitions.json#/suggestion"
40
            }
41
          }
42
        },
43
        "403": {
44
          "description": "Access forbidden",
45
          "schema": {
46
            "$ref": "../definitions.json#/error"
47
          }
48
        },
49
        "500": {
50
          "description": "Internal error",
51
          "schema": {
52
            "$ref": "../definitions.json#/error"
53
          }
54
        },
55
        "503": {
56
          "description": "Under maintenance",
57
          "schema": {
58
            "$ref": "../definitions.json#/error"
59
          }
60
        }
61
      },
62
      "x-koha-authorization": {
63
        "permissions": {
64
          "acquisition": "1"
65
        }
66
      }
67
    },
68
    "post": {
69
      "x-mojo-to": "Suggestions#add",
70
      "operationId": "add",
71
      "tags": ["patrons", "suggestions"],
72
      "parameters": [{
73
        "name": "body",
74
        "in": "body",
75
        "description": "A JSON object containing informations about the new suggestion",
76
        "required": true,
77
        "schema": {
78
          "$ref": "../definitions.json#/suggestion"
79
        }
80
      }],
81
      "produces": [
82
        "application/json"
83
      ],
84
      "responses": {
85
        "201": {
86
          "description": "Suggestion added",
87
          "schema": {
88
            "$ref": "../definitions.json#/suggestion"
89
          }
90
        },
91
        "400": {
92
          "description": "Bad request",
93
          "schema": {
94
            "$ref": "../definitions.json#/error"
95
          }
96
        },
97
        "403": {
98
          "description": "Access forbidden",
99
          "schema": {
100
            "$ref": "../definitions.json#/error"
101
          }
102
        },
103
        "500": {
104
          "description": "Internal error",
105
          "schema": {
106
            "$ref": "../definitions.json#/error"
107
          }
108
        },
109
        "503": {
110
          "description": "Under maintenance",
111
          "schema": {
112
            "$ref": "../definitions.json#/error"
113
          }
114
        }
115
      },
116
      "x-koha-authorization": {
117
        "permissions": {
118
          "acquisition": "1"
119
        }
120
      }
121
    }
122
  },
123
  "/suggestions/{suggestion_id}": {
124
    "get": {
125
      "x-mojo-to": "Suggestions#get",
126
      "operationId": "getSuggestions",
127
      "tags": ["patrons", "suggestions"],
128
      "parameters": [{
129
          "$ref": "../parameters.json#/suggestion_id_pp"
130
        }
131
      ],
132
      "produces": [
133
          "application/json"
134
      ],
135
      "responses": {
136
        "200": {
137
          "description": "A suggestion",
138
          "schema": {
139
            "$ref": "../definitions.json#/suggestion"
140
          }
141
        },
142
        "403": {
143
          "description": "Access forbidden",
144
          "schema": {
145
            "$ref": "../definitions.json#/error"
146
          }
147
        },
148
        "404": {
149
          "description": "Suggestion not found",
150
          "schema": {
151
            "$ref": "../definitions.json#/error"
152
          }
153
        },
154
        "500": {
155
          "description": "Internal error",
156
          "schema": {
157
            "$ref": "../definitions.json#/error"
158
          }
159
        },
160
        "503": {
161
          "description": "Under maintenance",
162
          "schema": {
163
            "$ref": "../definitions.json#/error"
164
          }
165
        }
166
      },
167
      "x-koha-authorization": {
168
        "permissions": {
169
          "acquisition": "1"
170
        }
171
      }
172
    },
173
    "put": {
174
      "x-mojo-to": "Suggestions#update",
175
      "operationId": "update",
176
      "tags": ["patrons", "suggestions"],
177
      "parameters": [{
178
        "$ref": "../parameters.json#/suggestion_id_pp"
179
      }, {
180
        "name": "body",
181
        "in": "body",
182
        "description": "A JSON object containing informations about the new hold",
183
        "required": true,
184
        "schema": {
185
          "$ref": "../definitions.json#/suggestion"
186
        }
187
      }],
188
      "produces": [
189
        "application/json"
190
      ],
191
      "responses": {
192
        "200": {
193
          "description": "A suggestion",
194
          "schema": {
195
            "$ref": "../definitions.json#/suggestion"
196
          }
197
        },
198
        "400": {
199
          "description": "Bad request",
200
          "schema": {
201
            "$ref": "../definitions.json#/error"
202
          }
203
        },
204
        "403": {
205
          "description": "Access forbidden",
206
          "schema": {
207
            "$ref": "../definitions.json#/error"
208
          }
209
        },
210
        "404": {
211
          "description": "Suggestion not found",
212
          "schema": {
213
            "$ref": "../definitions.json#/error"
214
          }
215
        },
216
        "500": {
217
          "description": "Internal error",
218
          "schema": {
219
            "$ref": "../definitions.json#/error"
220
          }
221
        },
222
        "503": {
223
          "description": "Under maintenance",
224
          "schema": {
225
            "$ref": "../definitions.json#/error"
226
          }
227
        }
228
      },
229
      "x-koha-authorization": {
230
        "permissions": {
231
          "acquisition": "1"
232
        }
233
      }
234
    },
235
    "delete": {
236
      "x-mojo-to": "Suggestions#delete",
237
      "operationId": "delete",
238
      "tags": ["patrons", "suggestions"],
239
      "parameters": [{
240
        "$ref": "../parameters.json#/suggestion_id_pp"
241
      }],
242
      "produces": [
243
        "application/json"
244
      ],
245
      "responses": {
246
        "200": {
247
          "description": "Suggestion deleted",
248
          "schema": {
249
            "type": "string"
250
          }
251
        },
252
        "403": {
253
          "description": "Access forbidden",
254
          "schema": {
255
            "$ref": "../definitions.json#/error"
256
          }
257
        },
258
        "404": {
259
          "description": "Suggestion not found",
260
          "schema": {
261
            "$ref": "../definitions.json#/error"
262
          }
263
        },
264
        "500": {
265
          "description": "Internal error",
266
          "schema": {
267
            "$ref": "../definitions.json#/error"
268
          }
269
        },
270
        "503": {
271
          "description": "Under maintenance",
272
          "schema": {
273
            "$ref": "../definitions.json#/error"
274
          }
275
        }
276
      },
277
      "x-koha-authorization": {
278
        "permissions": {
279
          "acquisition": "1"
280
        }
281
      }
282
    }
283
  }
284
}

Return to bug 17314