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

(-)a/Koha/Availability.pm (+16 lines)
Lines 213-216 sub unavailable { Link Here
213
    }
213
    }
214
}
214
}
215
215
216
217
sub _swaggerize_exception {
218
    my ($self, $exceptions) = @_;
219
220
    my $ret = {};
221
    foreach my $ex (keys %{$exceptions}) {
222
        my $name = $ex;
223
        $name =~ s/Koha::Exceptions:://;
224
        $ret->{$name} = {};
225
        foreach my $field ($exceptions->{$ex}->Fields) {
226
            $ret->{$name}->{$field} = $exceptions->{$ex}->$field;
227
        }
228
    }
229
    return $ret;
230
}
231
216
1;
232
1;
(-)a/Koha/Biblio/Availability.pm (+46 lines)
Lines 19-24 package Koha::Biblio::Availability; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Scalar::Util qw(looks_like_number);
21
use Scalar::Util qw(looks_like_number);
22
use Mojo::JSON;
22
23
23
use base qw(Koha::Availability);
24
use base qw(Koha::Availability);
24
25
Lines 129-132 sub new { Link Here
129
    return $self;
130
    return $self;
130
}
131
}
131
132
133
=head3 swaggerize
134
135
Returns a HASHref that contains biblio availability information as well as
136
availability information for each item of this biblio.
137
138
Numifies numbers for Swagger to be numbers instead of strings.
139
140
=cut
141
142
sub swaggerize {
143
    my ($self) = @_;
144
145
    my $item_availabilities = [];
146
    foreach my $item_availability (@{$self->item_availabilities}) {
147
        push $item_availabilities, $item_availability->swaggerize;
148
    }
149
    foreach my $item_availability (@{$self->item_unavailabilities}) {
150
        push $item_availabilities, $item_availability->swaggerize;
151
    }
152
    my $confirmations = $self->SUPER::_swaggerize_exception($self->confirmations);
153
    my $notes = $self->SUPER::_swaggerize_exception($self->notes);
154
    my $unavailabilities = $self->SUPER::_swaggerize_exception($self->unavailabilities);
155
    my $availability = {
156
        available => $self->available
157
                         ? Mojo::JSON->true
158
                         : Mojo::JSON->false,
159
    };
160
    if (keys %{$confirmations} > 0) {
161
        $availability->{'confirmations'} = $confirmations;
162
    }
163
    if (keys %{$notes} > 0) {
164
        $availability->{'notes'} = $notes;
165
    }
166
    if (keys %{$unavailabilities} > 0) {
167
        $availability->{'unavailabilities'} = $unavailabilities;
168
    }
169
170
    my $hash = {
171
        biblionumber => 0+$self->biblio->biblionumber,
172
        availability => $availability,
173
        item_availabilities => $item_availabilities,
174
    };
175
    return $hash;
176
}
177
132
1;
178
1;
(-)a/Koha/Item/Availability.pm (+45 lines)
Lines 123-126 sub new { Link Here
123
    return $self;
123
    return $self;
124
}
124
}
125
125
126
=head3 swaggerize
127
128
Returns a HASHref that contains item availability information.
129
130
Numifies numbers for Swagger to be numbers instead of strings.
131
132
=cut
133
134
sub swaggerize {
135
    my ($self) = @_;
136
137
    my $confirmations = $self->SUPER::_swaggerize_exception($self->confirmations);
138
    my $notes = $self->SUPER::_swaggerize_exception($self->notes);
139
    my $unavailabilities = $self->SUPER::_swaggerize_exception($self->unavailabilities);
140
    my $item = $self->item;
141
    my $availability = {
142
        available => $self->available
143
                         ? Mojo::JSON->true
144
                         : Mojo::JSON->false,
145
    };
146
    if (keys %{$confirmations} > 0) {
147
        $availability->{'confirmations'} = $confirmations;
148
    }
149
    if (keys %{$notes} > 0) {
150
        $availability->{'notes'} = $notes;
151
    }
152
    if (keys %{$unavailabilities} > 0) {
153
        $availability->{'unavailabilities'} = $unavailabilities;
154
    }
155
156
    return {
157
        itemnumber => 0+$item->itemnumber,
158
        biblionumber => 0+$item->biblionumber,
159
        biblioitemnumber => 0+$item->biblioitemnumber,
160
        availability => $availability,
161
        barcode => $item->barcode,
162
        enumchron => $item->enumchron,
163
        holdingbranch => $item->holdingbranch,
164
        homebranch => $item->homebranch,
165
        itemcallnumber => $item->itemcallnumber,
166
        itemnotes => $item->itemnotes,
167
        location => $item->location,
168
    };
169
}
170
126
1;
171
1;
(-)a/api/v1/swagger/paths/availability.json (-2 / +8 lines)
Lines 6-12 Link Here
6
      "parameters": [
6
      "parameters": [
7
        { "$ref": "../parameters.json#/biblionumbersQueryParam" },
7
        { "$ref": "../parameters.json#/biblionumbersQueryParam" },
8
        { "$ref": "../parameters.json#/borrowernumberQueryParam" },
8
        { "$ref": "../parameters.json#/borrowernumberQueryParam" },
9
        { "$ref": "../parameters.json#/branchcodeQueryParam"}
9
        { "$ref": "../parameters.json#/branchcodeQueryParam"},
10
        {
11
          "name": "limit_items",
12
          "in": "query",
13
          "description": "Check only first n available items.",
14
          "required": false,
15
          "type": "integer"
16
        }
10
      ],
17
      ],
11
      "consumes": ["application/json"],
18
      "consumes": ["application/json"],
12
      "produces": ["application/json"],
19
      "produces": ["application/json"],
13
- 

Return to bug 16826