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

(-)a/Koha/Item.pm (+71 lines)
Lines 35-40 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; Link Here
35
use Koha::Biblio::ItemGroups;
35
use Koha::Biblio::ItemGroups;
36
use Koha::Checkouts;
36
use Koha::Checkouts;
37
use Koha::CirculationRules;
37
use Koha::CirculationRules;
38
use Koha::ClassSources;
38
use Koha::CoverImages;
39
use Koha::CoverImages;
39
use Koha::Exceptions::Item::Transfer;
40
use Koha::Exceptions::Item::Transfer;
40
use Koha::Item::Attributes;
41
use Koha::Item::Attributes;
Lines 2058-2063 sub is_denied_renewal { Link Here
2058
    return 0;
2059
    return 0;
2059
}
2060
}
2060
2061
2062
=head3 api_strings_mapping
2063
2064
Retrieves for each column name the unblessed authorised value.
2065
2066
=cut
2067
2068
sub api_strings_mapping {
2069
    my ( $self, $params ) = @_;
2070
2071
    my $columns_info  = $self->_result->result_source->columns_info;
2072
    my $frameworkcode = $self->biblio->frameworkcode;
2073
    my $tagslib       = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
2074
    my $mss           = C4::Biblio::GetMarcSubfieldStructure( $frameworkcode, { unsafe => 1 } );
2075
2076
    my ( $itemtagfield, $itemtagsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
2077
2078
    my $public_read_list = $params->{public} ? $self->public_read_list : [];
2079
    my $to_api_mapping   = $self->to_api_mapping;
2080
2081
    # Hardcoded known 'authorised_value' values mapped to API codes
2082
    my $code_to_type = {
2083
        branches  => 'library',
2084
        cn_source => 'call_number_source',
2085
        itemtypes => 'item_type',
2086
    };
2087
2088
    # Handle not null and default values for integers and dates
2089
    my $strings = {};
2090
2091
    foreach my $col ( keys %{$columns_info} ) {
2092
2093
        # Skip columns not in public read list
2094
        next
2095
          unless !$params->{public}
2096
          || any { $col eq $_ } $public_read_list;
2097
2098
        # Skip columns that are not exposed on the API by to_api_mapping
2099
        # i.e. mapping exists but points to undef
2100
        next
2101
          if $col eq 'more_subfields_xml'    # not dealt with as a regular field
2102
          || ( exists $to_api_mapping->{$col} && !defined $to_api_mapping->{$col} );
2103
2104
        # By now, we are done with known columns, now check the framework for mappings
2105
        my $field = $self->_result->result_source->name . '.' . $col;
2106
2107
        # Check there's an entry in the MARC subfield structure for the field
2108
        if (   exists $mss->{$field}
2109
            && scalar @{ $mss->{$field} } > 0
2110
            && $mss->{$field}[0]->{authorised_value} )
2111
        {
2112
            my $subfield = $mss->{$field}[0];
2113
            my $code     = $subfield->{authorised_value};
2114
2115
            my $str  = C4::Biblio::GetAuthorisedValueDesc( $itemtagfield, $subfield->{tagsubfield}, $self->$col, '', $tagslib, undef, $params->{public} );
2116
            my $type = exists $code_to_type->{$code} ? $code_to_type->{$code} : 'av';
2117
2118
            # The _strings entry should match the API attribute name
2119
            my $mapped_attr = exists $to_api_mapping->{$col} ? $to_api_mapping->{$col} : $col;
2120
2121
            $strings->{$mapped_attr} = {
2122
                str  => $str,
2123
                type => $type,
2124
                ( $type eq 'av' ? ( category => $code ) : () ),
2125
            };
2126
        }
2127
    }
2128
2129
    return $strings;
2130
}
2131
2061
=head3 _type
2132
=head3 _type
2062
2133
2063
=cut
2134
=cut
(-)a/Koha/REST/V1/Items.pm (-2 / +3 lines)
Lines 68-81 sub get { Link Here
68
    my $c = shift->openapi->valid_input or return;
68
    my $c = shift->openapi->valid_input or return;
69
69
70
    try {
70
    try {
71
        my $item = Koha::Items->find($c->validation->param('item_id'));
71
        my $items_rs = Koha::Items->new;
72
        my $item = $c->objects->find($items_rs, $c->validation->param('item_id'));
72
        unless ( $item ) {
73
        unless ( $item ) {
73
            return $c->render(
74
            return $c->render(
74
                status => 404,
75
                status => 404,
75
                openapi => { error => 'Item not found'}
76
                openapi => { error => 'Item not found'}
76
            );
77
            );
77
        }
78
        }
78
        return $c->render( status => 200, openapi => $item->to_api );
79
        return $c->render( status => 200, openapi => $item );
79
    }
80
    }
80
    catch {
81
    catch {
81
        $c->unhandled_exception($_);
82
        $c->unhandled_exception($_);
(-)a/api/v1/swagger/definitions/item.yaml (+4 lines)
Lines 227-232 properties: Link Here
227
    type:
227
    type:
228
      - object
228
      - object
229
      - "null"
229
      - "null"
230
  _strings:
231
    type:
232
      - object
233
      - "null"
230
    description: A return claims object if one exists that's unresolved
234
    description: A return claims object if one exists that's unresolved
231
additionalProperties: false
235
additionalProperties: false
232
required:
236
required:
(-)a/api/v1/swagger/paths/items.yaml (-1 / +20 lines)
Lines 12-17 Link Here
12
        description: Search on the item's barcode
12
        description: Search on the item's barcode
13
        required: false
13
        required: false
14
        type: string
14
        type: string
15
      - name: x-koha-embed
16
        in: header
17
        required: false
18
        description: Embed list sent as a request header
19
        type: array
20
        items:
21
          type: string
22
          enum:
23
            - +strings
24
        collectionFormat: csv
15
      - $ref: "../swagger.yaml#/parameters/match"
25
      - $ref: "../swagger.yaml#/parameters/match"
16
      - $ref: "../swagger.yaml#/parameters/order_by"
26
      - $ref: "../swagger.yaml#/parameters/order_by"
17
      - $ref: "../swagger.yaml#/parameters/page"
27
      - $ref: "../swagger.yaml#/parameters/page"
Lines 62-67 Link Here
62
    summary: Get item
72
    summary: Get item
63
    parameters:
73
    parameters:
64
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
74
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
75
      - name: x-koha-embed
76
        in: header
77
        required: false
78
        description: Embed list sent as a request header
79
        type: array
80
        items:
81
          type: string
82
          enum:
83
            - +strings
84
        collectionFormat: csv
65
    consumes:
85
    consumes:
66
      - application/json
86
      - application/json
67
    produces:
87
    produces:
68
- 

Return to bug 33161