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

(-)a/Koha/Item.pm (+70 lines)
Lines 2058-2063 sub is_denied_renewal { Link Here
2058
    return 0;
2058
    return 0;
2059
}
2059
}
2060
2060
2061
=head3 api_strings_mapping
2062
2063
Retrieves for each column name the unblessed authorised value.
2064
2065
=cut
2066
2067
sub api_strings_mapping {
2068
    my ( $self, $params ) = @_;
2069
2070
    my $columns_info  = $self->_result->result_source->columns_info;
2071
    my $frameworkcode = $self->biblio->frameworkcode;
2072
    my $tagslib       = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
2073
    my $mss           = C4::Biblio::GetMarcSubfieldStructure( $frameworkcode, { unsafe => 1 } );
2074
2075
    my ( $itemtagfield, $itemtagsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
2076
2077
    my $public_read_list = $params->{public} ? $self->public_read_list : [];
2078
    my $to_api_mapping   = $self->to_api_mapping;
2079
2080
    # Hardcoded known 'authorised_value' values mapped to API codes
2081
    my $code_to_type = {
2082
        branches  => 'library',
2083
        cn_source => 'call_number_source',
2084
        itemtypes => 'item_type',
2085
    };
2086
2087
    # Handle not null and default values for integers and dates
2088
    my $strings = {};
2089
2090
    foreach my $col ( keys %{$columns_info} ) {
2091
2092
        # Skip columns not in public read list
2093
        next
2094
          unless !$params->{public}
2095
          || any { $col eq $_ } $public_read_list;
2096
2097
        # Skip columns that are not exposed on the API by to_api_mapping
2098
        # i.e. mapping exists but points to undef
2099
        next
2100
          if $col eq 'more_subfields_xml'    # not dealt with as a regular field
2101
          || ( exists $to_api_mapping->{$col} && !defined $to_api_mapping->{$col} );
2102
2103
        # By now, we are done with known columns, now check the framework for mappings
2104
        my $field = $self->_result->result_source->name . '.' . $col;
2105
2106
        # Check there's an entry in the MARC subfield structure for the field
2107
        if (   exists $mss->{$field}
2108
            && scalar @{ $mss->{$field} } > 0
2109
            && $mss->{$field}[0]->{authorised_value} )
2110
        {
2111
            my $subfield = $mss->{$field}[0];
2112
            my $code     = $subfield->{authorised_value};
2113
2114
            my $str  = C4::Biblio::GetAuthorisedValueDesc( $itemtagfield, $subfield->{tagsubfield}, $self->$col, '', $tagslib, undef, $params->{public} );
2115
            my $type = exists $code_to_type->{$code} ? $code_to_type->{$code} : 'av';
2116
2117
            # The _strings entry should match the API attribute name
2118
            my $mapped_attr = exists $to_api_mapping->{$col} ? $to_api_mapping->{$col} : $col;
2119
2120
            $strings->{$mapped_attr} = {
2121
                str  => $str,
2122
                type => $type,
2123
                ( $type eq 'av' ? ( category => $code ) : () ),
2124
            };
2125
        }
2126
    }
2127
2128
    return $strings;
2129
}
2130
2061
=head3 _type
2131
=head3 _type
2062
2132
2063
=cut
2133
=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/acquisitions_orders.yaml (+1 lines)
Lines 63-68 Link Here
63
            - current_item_level_holds+count
63
            - current_item_level_holds+count
64
            - invoice
64
            - invoice
65
            - items
65
            - items
66
            - items+strings
66
            - subscription
67
            - subscription
67
        collectionFormat: csv
68
        collectionFormat: csv
68
    responses:
69
    responses:
(-)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