-
Notifications
You must be signed in to change notification settings - Fork 0
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
Entity 생성, h2 및 JPA 환경설정 #3
Open
SEONGHUN-95
wants to merge
2
commits into
main
Choose a base branch
from
feature/003-creating-entity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.gradle | ||
build | ||
.idea | ||
*.yml | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.onewayticket.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
|
||
/** | ||
* TossPaymentController에서 사용되는 restTemplate | ||
* | ||
*/ | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
import lombok.RequiredArgsConstructor; | ||
import org.onewayticket.dto.BookingDetailsDto; | ||
import org.onewayticket.dto.BookingRequestDto; | ||
import org.onewayticket.dto.BookingResponseDto; | ||
import org.onewayticket.security.AuthService; | ||
import org.onewayticket.service.BookingService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
|
@@ -15,78 +18,65 @@ | |
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeParseException; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/bookings") | ||
public class BookingController { | ||
|
||
private final BookingService bookingService; | ||
private final AuthService authService; | ||
|
||
// 예약 생성 | ||
@PostMapping | ||
public ResponseEntity<BookingDetailsDto> createBooking(@RequestBody BookingRequestDto bookingRequestInfo) { | ||
if (bookingRequestInfo.paymentId() == null || bookingRequestInfo.paymentId().isBlank() || !bookingRequestInfo.paymentId().equals("Confirmed")) { | ||
public ResponseEntity<BookingDetailsDto> createBooking(@RequestBody BookingRequestDto bookingRequestInfo, | ||
@PathVariable String flightId) { | ||
|
||
// 결제 정보 검증 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 검증은 어디서 할 것인가? |
||
if (bookingRequestInfo.paymentKey() == null || bookingRequestInfo.paymentKey().isBlank()) { | ||
return ResponseEntity.status(400).build(); | ||
} | ||
|
||
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")); | ||
bookingService.createBooking(bookingRequestInfo, flightId); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
|
||
} | ||
|
||
@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); | ||
} | ||
public ResponseEntity<BookingResponseDto> getBookingDetails( | ||
@RequestParam("referenceCode") String referenceCode, | ||
@RequestParam("bookingEmail") String bookingEmail) { | ||
|
||
// 미리 정의된 예약 정보 | ||
BookingDetailsDto bookingDetails = new BookingDetailsDto( | ||
"B1234", "John Doe", "[email protected]", "123456789", | ||
"FL123", "ICN", "NRT", LocalDate.of(2023, 12, 1), LocalDate.of(2023, 12, 1), | ||
name, LocalDate.parse(birthDate), 25, "Female", "AB123456", "Korean", "12A", "Economy", | ||
BigDecimal.valueOf(500), "Confirmed"); | ||
|
||
BookingDetailsDto bookingDetailsDto = bookingService.getBookingDetails(referenceCode); | ||
|
||
// bookingId가 일치하지 않을 경우 예외 처리 | ||
if (!bookingDetails.bookingId().equals(bookingId)) { | ||
if (!bookingDetailsDto.referenceCode().equals(referenceCode)) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | ||
} | ||
|
||
return ResponseEntity.ok(bookingDetails); | ||
} | ||
String token = authService.generateToken(referenceCode, bookingEmail); | ||
|
||
// record 인스턴스 생성 | ||
BookingResponseDto responseDto = new BookingResponseDto(token, bookingDetailsDto); | ||
|
||
// DTO 반환 | ||
return ResponseEntity.ok(responseDto); | ||
|
||
} | ||
|
||
// 예약 취소 | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<String> cancelBooking( | ||
@PathVariable String id, | ||
@RequestHeader(value = "Authorization", required = false) String authHeader) { | ||
@RequestHeader(value = "Authorization", required = true) String token) { | ||
|
||
// 토큰 검증 | ||
if (authHeader == null || !authHeader.equals("Bearer VALID_TOKEN")) { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // 메시지 없이 401 반환 | ||
try { | ||
bookingService.cancelBooking(id, token); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(400).build(); | ||
} | ||
|
||
// 200 OK와 함께 예약 ID 반환 | ||
return ResponseEntity.ok("Booking with ID " + id + " has been canceled successfully."); | ||
} | ||
|
||
|
||
// 오늘 이후 날짜이거나 입력 값이 맞는지 확인 | ||
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 반환 | ||
} | ||
} | ||
|
||
|
||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비밀번호를 제외한 정보들은 서비스 운영에 필요하지 않을까요?