-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f20affb
commit 6961a09
Showing
10 changed files
with
374 additions
and
404 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
api/src/main/java/org/onewayticket/controller/AuthController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,75 +2,91 @@ | |
|
||
import lombok.RequiredArgsConstructor; | ||
import org.onewayticket.dto.BookingDetailsDto; | ||
import org.onewayticket.dto.BookingDto; | ||
import org.onewayticket.dto.BookingRequestDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.time.format.DateTimeParseException; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/bookings") | ||
public class BookingController { | ||
|
||
// 예약 생성 | ||
@PostMapping | ||
public ResponseEntity<String> createBooking(@RequestBody BookingRequestDto bookingRequestInfo) { | ||
if (bookingRequestInfo.paymentId() == null || bookingRequestInfo.paymentId().isBlank()) { | ||
return ResponseEntity.badRequest().body("Payment information is missing"); | ||
public ResponseEntity<BookingDetailsDto> createBooking(@RequestBody BookingRequestDto bookingRequestInfo) { | ||
if (bookingRequestInfo.paymentId() == null || bookingRequestInfo.paymentId().isBlank() || !bookingRequestInfo.paymentId().equals("Confirmed")) { | ||
return ResponseEntity.status(400).build(); | ||
} | ||
return ResponseEntity.ok("Booking created"); | ||
|
||
return ResponseEntity.ok(new BookingDetailsDto("A1234", bookingRequestInfo.bookingName(), bookingRequestInfo.bookingEmail(), bookingRequestInfo.bookingPhoneNumber(), | ||
bookingRequestInfo.flightId(), "ICN", "NRT", LocalDate.of(2023, 12, 1), LocalDate.of(2023, 12, 1), "Jane Doe", | ||
LocalDate.parse(bookingRequestInfo.birthDate()), 25, "Female", "AB123456", "Korean", "12A", "Economy", BigDecimal.valueOf(500), "Confirmed")); | ||
} | ||
|
||
// 예약 상세 조회 | ||
@GetMapping("/{id}") | ||
public ResponseEntity<BookingDetailsDto> getBookingDetails(@PathVariable String id) { | ||
@GetMapping | ||
public ResponseEntity<BookingDetailsDto> getBookingDetails( | ||
@RequestParam("bookingId") String bookingId, | ||
@RequestParam("name") String name, | ||
@RequestParam("birthDate") String birthDate) { | ||
|
||
// 날짜 유효성 검증 | ||
if (!isValidDate(birthDate)) { | ||
return ResponseEntity.badRequest().body(null); | ||
} | ||
|
||
// 미리 정의된 예약 정보 | ||
BookingDetailsDto bookingDetails = new BookingDetailsDto( | ||
id, "John Doe", "[email protected]", "123456789", | ||
"B1234", "John Doe", "[email protected]", "123456789", | ||
"FL123", "ICN", "NRT", LocalDate.of(2023, 12, 1), LocalDate.of(2023, 12, 1), | ||
"Jane Doe", 25, "Female", "AB123456", "Korean", "12A", "Economy", | ||
BigDecimal.valueOf(500), "Confirmed" | ||
); | ||
name, LocalDate.parse(birthDate), 25, "Female", "AB123456", "Korean", "12A", "Economy", | ||
BigDecimal.valueOf(500), "Confirmed"); | ||
|
||
// bookingId가 일치하지 않을 경우 예외 처리 | ||
if (!bookingDetails.bookingId().equals(bookingId)) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | ||
} | ||
|
||
return ResponseEntity.ok(bookingDetails); | ||
} | ||
|
||
|
||
// 예약 취소 | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<String> cancelBooking(@PathVariable String id, @RequestHeader("Authorization") String authHeader) { | ||
public ResponseEntity<String> cancelBooking( | ||
@PathVariable String id, | ||
@RequestHeader(value = "Authorization", required = false) String authHeader) { | ||
|
||
// 토큰 검증 | ||
if (!authHeader.equals("Bearer VALID_TOKEN")) { | ||
return ResponseEntity.status(403).body("Unauthorized user"); | ||
if (authHeader == null || !authHeader.equals("Bearer VALID_TOKEN")) { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // 메시지 없이 401 반환 | ||
} | ||
|
||
return ResponseEntity.ok("Booking canceled"); | ||
// 200 OK와 함께 예약 ID 반환 | ||
return ResponseEntity.ok("Booking with ID " + id + " has been canceled successfully."); | ||
} | ||
|
||
|
||
@GetMapping("/my") | ||
public ResponseEntity<List<BookingDto>> getMyBookings( | ||
@RequestParam("bookingId") String bookingId, | ||
@RequestParam("name") String name, | ||
@RequestParam("birthDate") String birthDate | ||
) { | ||
// 더미 데이터 | ||
List<BookingDto> bookings = List.of( | ||
new BookingDto("BK001", "John Doe", "[email protected]", "123456789"), | ||
new BookingDto("BK002", "Jane Smith", "[email protected]", "987654321") | ||
); | ||
|
||
// 사용자 정보로 필터링 | ||
List<BookingDto> filteredBookings = bookings.stream() | ||
.filter(booking -> booking.bookingId().equals(bookingId) && booking.reservationName().equalsIgnoreCase(name)) | ||
.toList(); | ||
|
||
// 조건에 따라 응답 처리 | ||
if (filteredBookings.isEmpty()) { | ||
return ResponseEntity.status(404).build(); // 404 반환 | ||
// 오늘 이후 날짜이거나 입력 값이 맞는지 확인 | ||
private boolean isValidDate(String date) { | ||
try { | ||
LocalDate parsedDate = LocalDate.parse(date); // 기본 포맷 yyyy-MM-dd | ||
return !parsedDate.isAfter(LocalDate.now()); // 오늘 이후 날짜인지 확인 | ||
} catch (DateTimeParseException e) { | ||
return false; // 형식이 잘못된 경우 false 반환 | ||
} | ||
|
||
return ResponseEntity.ok(filteredBookings); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
api/src/main/java/org/onewayticket/controller/PaymentController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.