Есть model Tourist в которой есть связь с model Flight:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String firstName;
private String lastName;
private String sex;
private String country;
private String notes;
@ManyToMany
@JoinTable(
name = "tourist_flight",
joinColumns = @JoinColumn(name = "tourist_id"),
inverseJoinColumns = @JoinColumn(name = "flight_id"))
private Set<Flight> flights;
model Flight:
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private LocalDateTime timeOfDeparture;
private LocalDateTime arrivalTime;
private int numberOfSeats;
@ManyToMany
private Set<Tourist> tourists;
private double ticketPrice;
в Controller получаю этот объект по id
@GetMapping("/edit/{id}")
public Tourist editTourist(@PathVariable long id){
return this.touristService.editTourist(id);
}
Метод editTourist(long id):
public Tourist editTourist(long id) {
return this.touristRepository.findById(id).orElse(null);
}
Angular app:
model Tourist:
export interface Tourist {
id: number;
firstName: string;
lastName: string;
sex: string;
country: string;
notes: string;
flights: Flight[];
}
model Flight:
export interface Flight {
id: number;
timeOfDeparture: Date;
arrivalTime: Date;
numberOfSeats: number;
tourists: Tourist[];
ticketPrice: number;
}
В tourist.service.ts получаю объект Tourist:
getTouristById(id: number): Observable<Tourist>{
return this.http.get<Tourist>(this.GET_TOURIST_BY_ID_URL + id);
}
В tourist.component.ts
constructor(private touristService: TouristService, router: Router, activeRoute: ActivatedRoute) {
this.id = activeRoute.snapshot.params.id;
}
ngOnInit(): void {
this.edit(this.id);
}
public edit( id: number) {
this.touristService.getTouristById(id).subscribe(
res => {
console.log(res);
},
error => {console.log('An error'); }
);
}
Как можно увидеть есть 1 элемент, но неизвестно какой, как его можно получить?
Вывод в консоль на сервере: