Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] added changes to docker and code design #3

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MYSQLDB_DATABASE=air_companies_management
MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=default
MYSQLDB_ROOT_PASSWORD=root
MYSQLDB_LOCAL_PORT=3308
MYSQLDB_DOCKER_PORT=3306
SPRING_LOCAL_PORT=8088
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
- MYSQL_ROOT_HOST="%"
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
healthcheck:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import org.company.aircompaniesmanager.dto.air.company.AirCompanyUpdateRequestDto;
import org.company.aircompaniesmanager.service.air.company.AirCompanyService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -63,8 +65,8 @@ private AirCompanyResponseDto updateById(
@DeleteMapping("/{id}")
@Operation(summary = "Delete air company",
description = "Removes air company")
private String deleteById(@PathVariable Long id) {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
private void deleteById(@PathVariable Long id) {
airCompanyService.deleteById(id);
return String.format("Company with id: '%s' deleted successfully.", id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.company.aircompaniesmanager.service.airplane.AirplaneService;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -48,13 +48,13 @@ public AirplaneResponseDto save(@RequestBody AirplaneRequestDto requestDto) {
return airplaneService.save(requestDto);
}

@PutMapping("/{id}")
@PatchMapping("/{airplaneId}/move")
@Operation(summary = "Reassign to another company",
description = "Updates airplane company")
public AirplaneResponseDto updateCompany(
@PathVariable Long id,
@PathVariable Long airplaneId,
@RequestBody AirplaneUpdateRequestDto requestDto
) {
return airplaneService.updateCompany(id, requestDto);
return airplaneService.updateCompany(airplaneId, requestDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ List<FlightResponseDto> findAllOverdue(Pageable pageable) {
return flightService.findAllOverdue(pageable);
}

@GetMapping("/{status}/company")
@GetMapping("/by-company-and-status")
@Operation(
summary = "Find flight by status and company",
description = "Retrieves detailed information "
+ "about flights by specified company with specified status"
)
List<FlightResponseDto> findAllByCompanyNameAndStatus(
@RequestParam String name,
@PathVariable String status,
@RequestParam String status,
Pageable pageable
) {
return flightService.findAllByCompanyName(name, status, pageable);
return flightService.findAllByCompanyAndStatus(name, status, pageable);
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ public class AirCompany {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, unique = true, length = 72)
private String name;

@Column(nullable = false, length = 56)
private String companyType;

@Column(nullable = false)
private LocalDate foundationDate;

@Column(name = "is_deleted", nullable = false, columnDefinition = "boolean default false")
private boolean isDeleted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ public class Airplane {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 12)
private String factorySerialNumber;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@JoinColumn(name = "air_company_id")
@ManyToOne(fetch = FetchType.LAZY)
private AirCompany airCompany;

private int numberOfFlights;
private double flightDistance;
private double fuelCapacity;

@Column(nullable = false, length = 56)
private String type;

private LocalDate creationDate;

@Column(name = "is_deleted", nullable = false, columnDefinition = "boolean default false")
private boolean isDeleted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,40 @@ public class Flight {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Status status;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@JoinColumn(name = "air_company_id", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
private AirCompany airCompany;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@JoinColumn(name = "airplane_id", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
private Airplane airplane;

@Column(nullable = false)
private String departureCountry;

@Column(nullable = false)
private String destinationCountry;

@Column(nullable = false)
private double distance;

@Column(nullable = false)
private double estimatedTime;

private LocalDateTime startTime;
private LocalDateTime endTime;
private LocalDateTime delayStartTime;
private LocalDateTime creationDate;

@Column(name = "is_deleted", nullable = false, columnDefinition = "boolean default false")
private boolean isDeleted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
@Repository
public interface AirCompanyRepository extends JpaRepository<AirCompany, Long> {
Optional<AirCompany> findByName(String name);

void deleteByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface FlightRepository extends JpaRepository<Flight, Long> {

@Query(
value = "SELECT * FROM `air_companies_management`.`flights` "
+ "WHERE TIMESTAMPDIFF(minute, start_time, end_time) >= estimated_time",
+ "WHERE TIMESTAMPDIFF(minute, start_time, end_time) >= estimated_time "
+ "AND status = 'COMPLETED'",
nativeQuery = true
)
List<Flight> findAllOverdue(Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface FlightService {
List<FlightResponseDto> findAll(Pageable pageable);

List<FlightResponseDto> findAllByCompanyName(
List<FlightResponseDto> findAllByCompanyAndStatus(
String companyName,
String statusString,
Pageable pageable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<FlightResponseDto> findAll(Pageable pageable) {
}

@Override
public List<FlightResponseDto> findAllByCompanyName(
public List<FlightResponseDto> findAllByCompanyAndStatus(
String name,
String statusString,
Pageable pageable
Expand Down
Loading