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

(-)a/Koha/Catalog/Concern.pm (+52 lines)
Line 0 Link Here
1
package Koha::Catalog::Concern;
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
21
use base qw(Koha::Object);
22
23
=head1 NAME
24
25
Koha::Catalog::Concern - Koha Catalog::Concern Object class
26
27
=head1 API
28
29
=head2 Internal methods
30
31
=cut
32
33
=head3 to_api_mapping
34
35
This method returns the mapping for representing a Koha::Catalog::Concern object
36
on the API.
37
38
=cut
39
40
sub to_api_mapping {
41
    return { id => 'concern_id', };
42
}
43
44
=head3 _type
45
46
=cut
47
48
sub _type {
49
    return 'CatalogConcern';
50
}
51
52
1;
(-)a/Koha/Catalog/Concerns.pm (+49 lines)
Line 0 Link Here
1
package Koha::Catalog::Concerns;
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
21
use base qw(Koha::Objects);
22
23
=head1 NAME
24
25
Koha::Tag - Koha Tag Object class
26
27
=head1 API
28
29
=head2 Internal methods
30
31
=cut
32
33
=head3 _type
34
35
=cut
36
37
sub _type {
38
    return 'CatalogConcern';
39
}
40
41
=head3 object_class
42
43
=cut
44
45
sub object_class {
46
    return 'Koha::Catalog::Concern';
47
}
48
49
1;
(-)a/Koha/REST/V1/Catalog/Concerns.pm (+141 lines)
Line 0 Link Here
1
package Koha::REST::V1::Catalog::Concerns;
2
3
# This file is part of Koha.
4
#
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.
9
#
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.
14
#
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>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Catalog::Concern;
23
use Koha::Catalog::Concerns;
24
25
use Try::Tiny qw( catch try );
26
27
=head1 API
28
29
=head2 Methods
30
31
=head3 list
32
33
=cut
34
35
sub list {
36
    my $c = shift->openapi->valid_input or return;
37
38
    return try {
39
        my $concerns_set = Koha::Catalog::Concerns->new;
40
        my $concerns = $c->objects->search( $concerns_set );
41
        return $c->render( status => 200, openapi => $concerns );
42
    }
43
    catch {
44
        $c->unhandled_exception($_);
45
    };
46
47
}
48
49
=head3 get
50
51
=cut
52
53
sub get {
54
    my $c = shift->openapi->valid_input or return;
55
56
    return try {
57
        my $concern = Koha::Catalog::Concerns->find( $c->validation->param('concern_id') );
58
        unless ($concern) {
59
            return $c->render( status  => 404,
60
                            openapi => { error => "Catalog::Concern not found" } );
61
        }
62
63
        return $c->render( status => 200, openapi => $concern->to_api );
64
    }
65
    catch {
66
        $c->unhandled_exception($_);
67
    }
68
}
69
70
=head3 add
71
72
=cut
73
74
sub add {
75
    my $c = shift->openapi->valid_input or return;
76
77
    return try {
78
        my $body    = $c->validation->param('body');
79
        my $concern = Koha::Catalog::Concern->new_from_api($body)->store;
80
        $concern->discard_changes;
81
        $c->res->headers->location( $c->req->url->to_string . '/' . $concern->id );
82
        return $c->render(
83
              status  => 201,
84
              openapi => $concern->to_api
85
        );
86
    }
87
    catch {
88
          $c->unhandled_exception($_);
89
    };
90
}
91
92
=head3 update
93
94
=cut
95
96
sub update {
97
    my $c = shift->openapi->valid_input or return;
98
99
    my $concern = Koha::Catalog::Concerns->find( $c->validation->param('concern_id') );
100
101
    if ( not defined $concern ) {
102
        return $c->render( status  => 404,
103
                           openapi => { error => "Object not found" } );
104
    }
105
106
    return try {
107
        $concern->set_from_api( $c->validation->param('body') );
108
        $concern->store();
109
        return $c->render( status => 200, openapi => $concern->to_api );
110
    }
111
    catch {
112
        $c->unhandled_exception($_);
113
    };
114
}
115
116
=head3 delete
117
118
=cut
119
120
sub delete {
121
    my $c = shift->openapi->valid_input or return;
122
123
    my $concern = Koha::Catalog::Concerns->find( $c->validation->param('concern_id') );
124
    if ( not defined $concern ) {
125
        return $c->render( status  => 404,
126
                           openapi => { error => "Object not found" } );
127
    }
128
129
    return try {
130
        $concern->delete;
131
        return $c->render(
132
            status  => 204,
133
            openapi => q{}
134
        );
135
    }
136
    catch {
137
        $c->unhandled_exception($_);
138
    };
139
}
140
141
1;
(-)a/api/v1/swagger/definitions/catalog_concern.yaml (+38 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  concern_id:
5
    type: integer
6
    description: Internal concern identifier
7
  added_date:
8
    type:
9
      - string
10
      - "null"
11
    format: date-time
12
    description: Date the concern was reported
13
  biblio_id:
14
    type: integer
15
    description: Internal identifier for the biblio the concern is related to
16
  message:
17
    type: string
18
    description: Concern details
19
  patron_id:
20
    type: integer
21
    description: Internal identifier for the patron the concern was submitted by
22
  resolved_by:
23
    type:
24
      - integer
25
      - "null"
26
    description: Internal identifier for the patron the concern was resolved by
27
  resolved_date:
28
    type:
29
      - string
30
      - "null"
31
    format: date-time
32
    description: Date the concern was resolved_date
33
  resolution_message:
34
    type:
35
        - string
36
        - "null"
37
    description: Resolution details
38
additionalProperties: false
(-)a/api/v1/swagger/paths/catalog_concerns.yaml (+200 lines)
Line 0 Link Here
1
---
2
/catalog/concerns:
3
  get:
4
    x-mojo-to: Catalog::Concerns#list
5
    operationId: listConcerns
6
    tags:
7
      - concerns
8
    summary: List concerns
9
    produces:
10
      - application/json
11
    parameters:
12
      - $ref: "../swagger.yaml#/parameters/match"
13
      - $ref: "../swagger.yaml#/parameters/order_by"
14
      - $ref: "../swagger.yaml#/parameters/page"
15
      - $ref: "../swagger.yaml#/parameters/per_page"
16
      - $ref: "../swagger.yaml#/parameters/q_param"
17
      - $ref: "../swagger.yaml#/parameters/q_body"
18
      - $ref: "../swagger.yaml#/parameters/q_header"
19
      - $ref: "../swagger.yaml#/parameters/request_id_header"
20
    responses:
21
      "200":
22
        description: A list of concerns
23
        schema:
24
          type: array
25
          items:
26
            $ref: "../swagger.yaml#/definitions/catalog_concern"
27
      "403":
28
        description: Access forbidden
29
        schema:
30
          $ref: "../swagger.yaml#/definitions/error"
31
      "500":
32
        description: |
33
          Internal server error. Possible `error_code` attribute values:
34
35
          * `internal_server_error`
36
        schema:
37
          $ref: "../swagger.yaml#/definitions/error"
38
      "503":
39
        description: Under maintenance
40
        schema:
41
          $ref: "../swagger.yaml#/definitions/error"
42
    x-koha-authorization:
43
      permissions:
44
        catalogue: "1"
45
  post:
46
    x-mojo-to: Catalog::Concerns#add
47
    operationId: addConcern
48
    tags:
49
      - concerns
50
    summary: Add catalog concern
51
    parameters:
52
      - name: body
53
        in: body
54
        description: A JSON object containing informations about the new hold
55
        required: true
56
        schema:
57
          $ref: "../swagger.yaml#/definitions/catalog_concern"
58
    produces:
59
      - application/json
60
    responses:
61
      "201":
62
        description: Concern added
63
        schema:
64
          $ref: "../swagger.yaml#/definitions/catalog_concern"
65
      "401":
66
        description: Authentication required
67
        schema:
68
          $ref: "../swagger.yaml#/definitions/error"
69
      "403":
70
        description: Access forbidden
71
        schema:
72
          $ref: "../swagger.yaml#/definitions/error"
73
      "500":
74
        description: |
75
          Internal server error. Possible `error_code` attribute values:
76
77
          * `internal_server_error`
78
        schema:
79
          $ref: "../swagger.yaml#/definitions/error"
80
      "503":
81
        description: Under maintenance
82
        schema:
83
          $ref: "../swagger.yaml#/definitions/error"
84
    x-koha-authorization:
85
      permissions:
86
        catalogue: "1"
87
"/catalog/concerns/{concern_id}":
88
  get:
89
    x-mojo-to: Catalog::Concerns#get
90
    operationId: getConcern
91
    tags:
92
      - concerns
93
    summary: Get catalog concern
94
    parameters:
95
      - $ref: "../swagger.yaml#/parameters/concern_id_pp"
96
    produces:
97
      - application/json
98
    responses:
99
      "200":
100
        description: A catalog concern
101
        schema:
102
          $ref: "../swagger.yaml#/definitions/catalog_concern"
103
      "404":
104
        description: Concern not found
105
        schema:
106
          $ref: "../swagger.yaml#/definitions/error"
107
      "500":
108
        description: |
109
          Internal server error. Possible `error_code` attribute values:
110
111
          * `internal_server_error`
112
        schema:
113
          $ref: "../swagger.yaml#/definitions/error"
114
      "503":
115
        description: Under maintenance
116
        schema:
117
          $ref: "../swagger.yaml#/definitions/error"
118
    x-koha-authorization:
119
      permissions:
120
        catalogue: "1"
121
  put:
122
    x-mojo-to: Catalog::Concerns#update
123
    operationId: updateConcern
124
    tags:
125
      - concerns
126
    summary: Update catalog concern
127
    parameters:
128
      - $ref: "../swagger.yaml#/parameters/concern_id_pp"
129
      - name: body
130
        in: body
131
        description: A catalog concern object
132
        required: true
133
        schema:
134
          $ref: "../swagger.yaml#/definitions/catalog_concern"
135
    produces:
136
      - application/json
137
    responses:
138
      "200":
139
        description: A catalog concern
140
        schema:
141
          $ref: "../swagger.yaml#/definitions/catalog_concern"
142
      "401":
143
        description: Authentication required
144
        schema:
145
          $ref: "../swagger.yaml#/definitions/error"
146
      "403":
147
        description: Access forbidden
148
        schema:
149
          $ref: "../swagger.yaml#/definitions/error"
150
      "404":
151
        description: Concern not found
152
        schema:
153
          $ref: "../swagger.yaml#/definitions/error"
154
      "500":
155
        description: Internal error
156
        schema:
157
          $ref: "../swagger.yaml#/definitions/error"
158
      "503":
159
        description: Under maintenance
160
        schema:
161
          $ref: "../swagger.yaml#/definitions/error"
162
    x-koha-authorization:
163
      permissions:
164
        editcatalogue: edit_catalogue
165
  delete:
166
    x-mojo-to: Catalog::Concerns#delete
167
    operationId: deleteConcern
168
    tags:
169
      - concerns
170
    summary: Delete catalog concern
171
    parameters:
172
      - $ref: "../swagger.yaml#/parameters/concern_id_pp"
173
    produces:
174
      - application/json
175
    responses:
176
      "204":
177
        description: Concern deleted
178
      "401":
179
        description: Authentication required
180
        schema:
181
          $ref: "../swagger.yaml#/definitions/error"
182
      "403":
183
        description: Access forbidden
184
        schema:
185
          $ref: "../swagger.yaml#/definitions/error"
186
      "404":
187
        description: Concern not found
188
        schema:
189
          $ref: "../swagger.yaml#/definitions/error"
190
      "500":
191
        description: Internal error
192
        schema:
193
          $ref: "../swagger.yaml#/definitions/error"
194
      "503":
195
        description: Under maintenance
196
        schema:
197
          $ref: "../swagger.yaml#/definitions/error"
198
    x-koha-authorization:
199
      permissions:
200
        editcatalogue: edit_catalogue
(-)a/api/v1/swagger/swagger.yaml (-1 / +12 lines)
Lines 14-19 definitions: Link Here
14
    $ref: ./definitions/bundle_link.yaml
14
    $ref: ./definitions/bundle_link.yaml
15
  cashup:
15
  cashup:
16
    $ref: ./definitions/cashup.yaml
16
    $ref: ./definitions/cashup.yaml
17
  catalog_concern:
18
    $ref: ./definitions/catalog_concern.yaml
17
  checkout:
19
  checkout:
18
    $ref: ./definitions/checkout.yaml
20
    $ref: ./definitions/checkout.yaml
19
  checkouts:
21
  checkouts:
Lines 123-128 paths: Link Here
123
    $ref: "./paths/cash_registers.yaml#/~1cash_registers~1{cash_register_id}~1cashups"
125
    $ref: "./paths/cash_registers.yaml#/~1cash_registers~1{cash_register_id}~1cashups"
124
  "/cashups/{cashup_id}":
126
  "/cashups/{cashup_id}":
125
    $ref: "./paths/cash_registers.yaml#/~1cashups~1{cashup_id}"
127
    $ref: "./paths/cash_registers.yaml#/~1cashups~1{cashup_id}"
128
  "/catalog/concerns":
129
    $ref: "./paths/catalog_concerns.yaml#/~1catalog~1concerns"
130
  "/catalog/concerns/{concern_id}":
131
    $ref: "./paths/catalog_concerns.yaml#/~1catalog~1concerns~1{concern_id}"
126
  /checkouts:
132
  /checkouts:
127
    $ref: ./paths/checkouts.yaml#/~1checkouts
133
    $ref: ./paths/checkouts.yaml#/~1checkouts
128
  "/checkouts/{checkout_id}":
134
  "/checkouts/{checkout_id}":
Lines 284-289 parameters: Link Here
284
    name: checkout_id
290
    name: checkout_id
285
    required: true
291
    required: true
286
    type: integer
292
    type: integer
293
  concern_id_pp:
294
    description: Internal concern identifier
295
    in: path
296
    name: concern_id
297
    required: true
298
    type: integer
287
  city_id_pp:
299
  city_id_pp:
288
    description: City internal identifier
300
    description: City internal identifier
289
    in: path
301
    in: path
290
- 

Return to bug 31028