Sfoglia il codice sorgente

mapping @id to id

master
Daniel 2 anni fa
parent
commit
4c5112cce7
12 ha cambiato i file con 159 aggiunte e 72 eliminazioni
  1. +60
    -45
      matsen-tool/openapi.yaml
  2. +13
    -0
      matsen-tool/src/app/_helpers/api.helper.ts
  3. +59
    -0
      matsen-tool/src/app/_helpers/property.interceptor.ts
  4. +2
    -0
      matsen-tool/src/app/app.module.ts
  5. +1
    -2
      matsen-tool/src/app/core/api/v1/model/contact.ts
  6. +1
    -2
      matsen-tool/src/app/core/api/v1/model/contactJsonhal.ts
  7. +1
    -2
      matsen-tool/src/app/core/api/v1/model/contactJsonld.ts
  8. +4
    -6
      matsen-tool/src/app/core/api/v1/model/partner.ts
  9. +4
    -6
      matsen-tool/src/app/core/api/v1/model/partnerJsonhal.ts
  10. +5
    -6
      matsen-tool/src/app/core/api/v1/model/partnerJsonld.ts
  11. +1
    -1
      matsen-tool/src/app/partners/partners-detail/partners-detail.component.ts
  12. +8
    -2
      matsen-tool/src/app/partners/partners.component.ts

+ 60
- 45
matsen-tool/openapi.yaml Vedi File

@@ -1119,11 +1119,12 @@ components:
- string
- 'null'
partner:
anyOf:
-
$ref: '#/components/schemas/Partner'
-
type: 'null'
'owl:maxCardinality': 1
type:
- string
- 'null'
format: iri-reference
example: 'https://example.com/'
birthday:
type:
- string
@@ -1179,11 +1180,12 @@ components:
- string
- 'null'
partner:
anyOf:
-
$ref: '#/components/schemas/Partner.jsonhal'
-
type: 'null'
'owl:maxCardinality': 1
type:
- string
- 'null'
format: iri-reference
example: 'https://example.com/'
birthday:
type:
- string
@@ -1253,11 +1255,12 @@ components:
- string
- 'null'
partner:
anyOf:
-
$ref: '#/components/schemas/Partner.jsonld'
-
type: 'null'
'owl:maxCardinality': 1
type:
- string
- 'null'
format: iri-reference
example: 'https://example.com/'
birthday:
type:
- string
@@ -1362,10 +1365,10 @@ components:
type: object
description: ''
deprecated: false
required:
- name
- type
properties:
id:
readOnly: true
type: integer
name:
type: string
type:
@@ -1398,13 +1401,6 @@ components:
type:
- string
- 'null'
createdAt:
type: string
format: date-time
contacts:
type: array
items:
$ref: '#/components/schemas/Contact'
logo:
'owl:maxCardinality': 1
type:
@@ -1412,10 +1408,24 @@ components:
- 'null'
format: iri-reference
example: 'https://example.com/'
createdAt:
type:
- string
- 'null'
format: date-time
contacts:
type: array
items:
type: string
format: iri-reference
example: 'https://example.com/'
Partner.jsonhal:
type: object
description: ''
deprecated: false
required:
- name
- type
properties:
_links:
type: object
@@ -1426,9 +1436,6 @@ components:
href:
type: string
format: iri-reference
id:
readOnly: true
type: integer
name:
type: string
type:
@@ -1461,13 +1468,6 @@ components:
type:
- string
- 'null'
createdAt:
type: string
format: date-time
contacts:
type: array
items:
$ref: '#/components/schemas/Contact.jsonhal'
logo:
'owl:maxCardinality': 1
type:
@@ -1475,10 +1475,24 @@ components:
- 'null'
format: iri-reference
example: 'https://example.com/'
createdAt:
type:
- string
- 'null'
format: date-time
contacts:
type: array
items:
type: string
format: iri-reference
example: 'https://example.com/'
Partner.jsonld:
type: object
description: ''
deprecated: false
required:
- name
- type
properties:
'@context':
readOnly: true
@@ -1503,9 +1517,6 @@ components:
'@type':
readOnly: true
type: string
id:
readOnly: true
type: integer
name:
type: string
type:
@@ -1538,13 +1549,6 @@ components:
type:
- string
- 'null'
createdAt:
type: string
format: date-time
contacts:
type: array
items:
$ref: '#/components/schemas/Contact.jsonld'
logo:
'owl:maxCardinality': 1
type:
@@ -1552,6 +1556,17 @@ components:
- 'null'
format: iri-reference
example: 'https://example.com/'
createdAt:
type:
- string
- 'null'
format: date-time
contacts:
type: array
items:
type: string
format: iri-reference
example: 'https://example.com/'
Post:
type: object
description: ''


+ 13
- 0
matsen-tool/src/app/_helpers/api.helper.ts Vedi File

@@ -0,0 +1,13 @@
export class ApiHelper {

public static extractId(iri: string | undefined) {
if (iri !== undefined) {
const iriRegex = /\/(\d+)$/;
const match = iri.match(iriRegex);
if (match && match[1]) {
return match[1];
}
}
return undefined;
}
}

+ 59
- 0
matsen-tool/src/app/_helpers/property.interceptor.ts Vedi File

@@ -0,0 +1,59 @@
// property.interceptor.ts

import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
HttpEvent, HttpResponse,
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable()
export class PropertyInterceptor implements HttpInterceptor {
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
map((event) => {
if (event instanceof HttpResponse && event.body) {
let modifiedBody;

if (event.body['hydra:member']) {
modifiedBody = {
...event.body,
'hydra:member': this.mapDataItems(
event.body['hydra:member']
),
};
} else {
// Wenn keine 'hydra:member' vorhanden ist, betrachte das gesamte Objekt
modifiedBody = this.mapDataItem(event.body);
}

return event.clone({
body: modifiedBody,
});
}

return event;
})
);
}

private mapDataItems(items: any[]): any[] {
return items.map((item) => this.mapDataItem(item));
}

private mapDataItem(item: any): any {
if (item && item['@id']) {
return {
...item,
id: item['@id'],
};
}
return item;
}
}

+ 2
- 0
matsen-tool/src/app/app.module.ts Vedi File

@@ -24,6 +24,7 @@ import { ProductsDetailComponent } from './products/products-detail/products-det
import { DocumentsComponent } from './documents/documents.component';
import { NewContactComponent } from './partners/new-contact/new-contact.component';
import { ModalComponent } from './_components/modal/modal.component';
import {PropertyInterceptor} from "@app/_helpers/property.interceptor";

export function apiConfigFactory(): Configuration {
const params: ConfigurationParameters = {
@@ -74,6 +75,7 @@ export function HttpLoaderFactory(http: HttpClient) {
providers: [
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: PropertyInterceptor, multi: true},

],
bootstrap: [AppComponent]


+ 1
- 2
matsen-tool/src/app/core/api/v1/model/contact.ts Vedi File

@@ -9,7 +9,6 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { Partner } from './partner';


/**
@@ -18,7 +17,7 @@ import { Partner } from './partner';
export interface Contact {
firstName: string | null;
lastName: string | null;
partner?: Partner | null;
partner?: string | null;
birthday?: string | null;
image?: string | null;
position?: string | null;


+ 1
- 2
matsen-tool/src/app/core/api/v1/model/contactJsonhal.ts Vedi File

@@ -10,7 +10,6 @@
* Do not edit the class manually.
*/
import { ContactJsonhalLinks } from './contactJsonhalLinks';
import { PartnerJsonhal } from './partnerJsonhal';


/**
@@ -20,7 +19,7 @@ export interface ContactJsonhal {
_links?: ContactJsonhalLinks;
firstName: string | null;
lastName: string | null;
partner?: PartnerJsonhal | null;
partner?: string | null;
birthday?: string | null;
image?: string | null;
position?: string | null;


+ 1
- 2
matsen-tool/src/app/core/api/v1/model/contactJsonld.ts Vedi File

@@ -9,7 +9,6 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { PartnerJsonld } from './partnerJsonld';


/**
@@ -21,7 +20,7 @@ export interface ContactJsonld {
readonly type?: string;
firstName: string | null;
lastName: string | null;
partner?: PartnerJsonld | null;
partner?: string | null;
birthday?: string | null;
image?: string | null;
position?: string | null;


+ 4
- 6
matsen-tool/src/app/core/api/v1/model/partner.ts Vedi File

@@ -9,25 +9,23 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { Contact } from './contact';


/**
*
*/
export interface Partner {
readonly id?: number;
name?: string;
type?: Partner.TypeEnum;
name: string;
type: Partner.TypeEnum;
street?: string | null;
streetNo?: string | null;
zip?: string | null;
city?: string | null;
country?: string | null;
website?: string | null;
createdAt?: string;
contacts?: Array<Contact>;
logo?: string | null;
createdAt?: string | null;
contacts?: Array<string>;
}
export namespace Partner {
export type TypeEnum = 'customer' | 'supplier' | 'service';


+ 4
- 6
matsen-tool/src/app/core/api/v1/model/partnerJsonhal.ts Vedi File

@@ -10,7 +10,6 @@
* Do not edit the class manually.
*/
import { ContactJsonhalLinks } from './contactJsonhalLinks';
import { ContactJsonhal } from './contactJsonhal';


/**
@@ -18,18 +17,17 @@ import { ContactJsonhal } from './contactJsonhal';
*/
export interface PartnerJsonhal {
_links?: ContactJsonhalLinks;
readonly id?: number;
name?: string;
type?: PartnerJsonhal.TypeEnum;
name: string;
type: PartnerJsonhal.TypeEnum;
street?: string | null;
streetNo?: string | null;
zip?: string | null;
city?: string | null;
country?: string | null;
website?: string | null;
createdAt?: string;
contacts?: Array<ContactJsonhal>;
logo?: string | null;
createdAt?: string | null;
contacts?: Array<string>;
}
export namespace PartnerJsonhal {
export type TypeEnum = 'customer' | 'supplier' | 'service';


+ 5
- 6
matsen-tool/src/app/core/api/v1/model/partnerJsonld.ts Vedi File

@@ -9,7 +9,6 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { ContactJsonld } from './contactJsonld';


/**
@@ -17,18 +16,18 @@ import { ContactJsonld } from './contactJsonld';
*/
export interface PartnerJsonld {
context?: string | null;
readonly id?: number;
name?: string;
type?: PartnerJsonld.TypeEnum;
readonly id?: string;
name: string;
type: PartnerJsonld.TypeEnum;
street?: string | null;
streetNo?: string | null;
zip?: string | null;
city?: string | null;
country?: string | null;
website?: string | null;
createdAt?: string;
contacts?: Array<ContactJsonld>;
logo?: string | null;
createdAt?: string | null;
contacts?: Array<string>;
}
export namespace PartnerJsonld {
export type TypeEnum = 'customer' | 'supplier' | 'service';


+ 1
- 1
matsen-tool/src/app/partners/partners-detail/partners-detail.component.ts Vedi File

@@ -36,7 +36,7 @@ export class PartnersDetailComponent implements OnInit {
) {
this.id = "";
this.partnerDetailSub = new Subscription();
this.partner = {};
this.partner = {} as PartnerJsonld;
this.partnerLogoSub = new Subscription();
this.partnerLogo = "";
this.partnerContactsSub = new Subscription();


+ 8
- 2
matsen-tool/src/app/partners/partners.component.ts Vedi File

@@ -6,6 +6,7 @@ import {Subscription} from "rxjs";
import {PartnerJsonld, PartnerService} from "@app/core/api/v1";
import {MatPaginator, MatPaginatorIntl, MatPaginatorModule, PageEvent} from "@angular/material/paginator";
import {OrderFilter} from "@app/_models/orderFilter";
import {ApiHelper} from "@app/_helpers/api.helper";

@Component({
selector: 'app-partners',
@@ -124,8 +125,13 @@ export class PartnersComponent implements OnInit, AfterViewInit {
this.getData();
}

navigateToDetails(partner: any) {
navigateToDetails(element: any) {
const partner: PartnerJsonld = element as PartnerJsonld;
// this.partnerService.setPartnerData(partner);
this.router.navigate(['/customers', partner.name]);
//console.log(partner['@id']);
console.log(ApiHelper.extractId(partner.id));
this.router.navigate(['/customers', ApiHelper.extractId(partner.id)]);
}

protected readonly PartnerJsonld = PartnerJsonld;
}

Caricamento…
Annulla
Salva