Commit 28c7eb49 authored by Andrei Zhikulin's avatar Andrei Zhikulin
Browse files

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	server/src/main/java/server/dto/FlightDto.java
#	server/src/main/java/server/dto/PassengerDto.java
#	server/src/main/java/server/model/PassengerEntity.java
parents c71ec945 59093305
......@@ -35,6 +35,12 @@ public class PassengerController {
@GetMapping(value="/getAllPassengers")
public List<PassengerEntity> getAllPassengers(){
// service.getAllPassengers().forEach(passengerEntity -> System.out.println("FLIGHTS: " + passengerEntity.getFlights()));
return service.getAllPassengers();
}
......
......@@ -34,6 +34,7 @@ public class FlightEntity {
private TerminalEntity terminalByTerminalid;
private List<TicketEntity> ticketsById;
@Id
@Column(name = "id")
public int getId() {
......@@ -159,6 +160,21 @@ public class FlightEntity {
this.airlineByAirlineid = airlineByAirlineid;
}
private Set<PassengerEntity> passengers;
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
@JoinTable(name = "ticket", joinColumns = @JoinColumn(name = "flightid"),
inverseJoinColumns = @JoinColumn(name = "passengerid"))
public Set<PassengerEntity> getPassengers() {
return passengers;
}
public void setPassengers(Set<PassengerEntity> passengers) {
this.passengers = passengers;
}
@JsonIgnore
@ManyToOne(cascade = {CascadeType.PERSIST})
@JoinColumn(name = "terminalid", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
......
package server.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.Target;
import javax.persistence.*;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@Entity
@Table(name = "passenger", schema = "airbook", catalog = "ear2018zs_22")
......@@ -98,11 +94,11 @@ public class PassengerEntity {
Objects.equals(password, that.password);
}
// @Override
// public int hashCode() {
// return Objects.hash(id, email, name, surname, password, phonenumber);
// }
@Override
public int hashCode() {
return Objects.hash(id, email, name, surname, password, phonenumber);
}
@OneToMany(cascade = {CascadeType.ALL}, orphanRemoval = true, mappedBy = "passengerByPassengerid")
public List<TicketEntity> getTicketsById() {
......@@ -129,4 +125,17 @@ public class PassengerEntity {
public void setFlights(List<FlightEntity> flights) {
this.flights = flights;
}
}
\ No newline at end of file
@Override
public String toString() {
return "PassengerEntity{" +
"id=" + id +
", email='" + email + '\'' +
", name='" + name + '\'' +
", surname='" + surname + '\'' +
", password='" + password + '\'' +
", phonenumber=" + phonenumber +
", ticketsById=" + ticketsById +
", flights=" + flights +
'}';
}
}
......@@ -8,4 +8,6 @@ import server.model.PassengerEntity;
public interface PassengerRepository extends JpaRepository<PassengerEntity, Integer> {
PassengerEntity findOneByName(String name);
}
......@@ -6,8 +6,10 @@ import org.springframework.stereotype.Service;
import server.dto.FlightDto;
import server.model.FlightEntity;
import server.repositories.FlightRepository;
import server.repositories.PassengerRepository;
import server.service.Interfaces.FlightServiceInterface;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
......@@ -15,11 +17,14 @@ import java.util.Optional;
public class FlightService implements FlightServiceInterface {
@Autowired
private FlightRepository repository;
private FlightRepository flightRepository;
@Autowired
private PassengerRepository passengerRepository;
@Autowired
public FlightService(FlightRepository repository) {
this.repository = repository;
this.flightRepository = repository;
}
public FlightService() {
......@@ -27,37 +32,39 @@ public class FlightService implements FlightServiceInterface {
@Override
public FlightEntity create(FlightDto flightDto) {
return repository.saveAndFlush(flightDto.toEntity());
return flightRepository.saveAndFlush(flightDto.toEntity());
}
@Override
public List<FlightEntity> getAllFlight() {
return repository.findAll();
// List<FlightEntity> flightEntities = new ArrayList<>();
// flightEntities = flightRepository.findAll();
return flightRepository.findAll();
}
@Override
public Optional<FlightEntity> getFlightByID(int id) {
return repository.findById(id);
return flightRepository.findById(id);
}
@Override
public void update(FlightDto flightDto) {
repository.saveAndFlush(flightDto.toEntity());
flightRepository.saveAndFlush(flightDto.toEntity());
}
public void updatePlane(Integer id, Integer newPlane){
FlightEntity passenger = repository.findById(id).orElseThrow(() -> new ResourceNotFoundException(id.toString()));
FlightEntity passenger = flightRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(id.toString()));
passenger.setPlaneid(newPlane);
repository.saveAndFlush(passenger);
flightRepository.saveAndFlush(passenger);
}
@Override
public void delete(FlightEntity flight) {
repository.saveAndFlush(flight);
flightRepository.saveAndFlush(flight);
}
@Override
public void deleteById(int id) {
repository.deleteById(id);
flightRepository.deleteById(id);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment