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

[2 ~ 4 단계 방탈출 예약 결제 / 배포] 에버(손채영) 미션 제출합니다. #123

Merged
merged 15 commits into from
Jun 14, 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
- [x] 예약 생성 전 결제 외부 API 호출
- [x] 예약 실패 시 예외 처리 및 실패 사유 전달

### 2단계 구현 기능 목록
- [x] 내 예약 페이지 결제 정보 추가
- [x] paymentKey, 결제 금액 조회
- [x] 그 외 결제 정보 DB에 선택적으로 저장
32 changes: 32 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
plugins {
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'java'
}

group = 'nextstep'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
asciidoctorExt
}

repositories {
mavenCentral()
}
Expand All @@ -25,9 +30,36 @@ dependencies {
runtimeOnly 'com.h2database:h2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-restassured'
testImplementation 'io.rest-assured:rest-assured:5.3.1'
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
}

ext {
snippetsDir = file('build/generated-snippets')
}

test {
useJUnitPlatform()
outputs.dir snippetsDir
}

asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'
dependsOn test
}

asciidoctor.doFirst {
delete file('src/main/resources/static/docs')
}

tasks.register('copyDocument', Copy) {
dependsOn asciidoctor
from file("${asciidoctor.outputDir}")
into file("src/main/resources/static/docs")
}

build {
dependsOn copyDocument
}
82 changes: 82 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
ifndef::snippets[]
:snippets: ./build/generated-snippets
endif::[]


== 1️⃣ 회원
:domain: member
:class-name: member-controller-test

=== 조회
operation::{class-name}/show-{domain}[snippets='request-cookies,response-fields,http-request,http-response']

=== 저장
operation::{class-name}/save-{domain}[snippets='request-fields,http-request,http-response']

=== 삭제
operation::{class-name}/delete-{domain}[snippets='request-cookies,http-request,http-response']

== 2️⃣ 인증
:domain: auth
:class-name: login-controller-test

=== 로그인
operation::{class-name}/login[snippets='request-fields,http-request,http-response']

=== 로그아웃
operation::{class-name}/logout[snippets='request-cookies,http-request,http-response']

=== 로그인 여부 확인
operation::{class-name}/login-check[snippets='request-cookies,response-fields,http-request,http-response']

== 3️⃣ 예약 시간
:domain: reservation-time
:class-name: reservation-time-controller-test

=== 조회
operation::{class-name}/show-{domain}[snippets='request-cookies,response-fields,http-request,http-response']

=== 저장
operation::{class-name}/save-{domain}[snippets='request-cookies,request-fields,response-fields,http-request,http-response']

=== 삭제
operation::{class-name}/delete-{domain}[snippets='request-cookies,http-request,http-response']

== 4️⃣ 테마
:domain: theme
:class-name: theme-controller-test

=== 조회
operation::{class-name}/show-{domain}[snippets='request-cookies,response-fields,http-request,http-response']

=== 저장
operation::{class-name}/save-{domain}[snippets='request-cookies,request-fields,response-fields,http-request,http-response']

=== 삭제
operation::{class-name}/delete-{domain}[snippets='request-cookies,http-request,http-response']

=== 인기 조회
operation::{class-name}/show-popular-theme[snippets='response-fields,http-request,http-response']

== 5️⃣ 예약
:domain: reservation
:class-name: reservation-controller-test

=== 조회
operation::{class-name}/show-{domain}[snippets='request-cookies,response-fields,http-request,http-response']

=== 저장
operation::{class-name}/save-{domain}[snippets='request-cookies,request-fields,response-fields,http-request,http-response']

=== 삭제
operation::{class-name}/delete-{domain}[snippets='request-cookies,http-request,http-response']

=== 검색 (필터링)
operation::admin-reservation-controller-test/find-reservation-by-filter[snippets='request-cookies,response-fields,http-request,http-response']

== 6️⃣ 대기
:domain: waiting
:class-name: reservation-controller-test

=== 조회
operation::admin-reservation-controller-test/find-all-waiting[snippets='request-cookies,response-fields,http-request,http-response']
3 changes: 2 additions & 1 deletion src/main/java/roomescape/config/WebMvcConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/**")
.excludePathPatterns("/", "/error", "/login", "/signup",
"/members", "/themes/popular",
"/css/**", "/*.ico", "/js/**", "/image/**");
"/css/**", "/*.ico", "/js/**", "/image/**",
"/docs");

registry.addInterceptor(new CheckAdminInterceptor())
.order(2)
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/roomescape/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public LoginController(MemberService memberService, AuthService authService) {
this.authService = authService;
}

@GetMapping("/login")
public String page() {
return "login";
}

@PostMapping("/login")
public void login(@RequestBody LoginRequest loginRequest, HttpServletResponse response) {
MemberResponse memberResponse = memberService.findByEmailAndPassword(loginRequest.email(), loginRequest.password());
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/roomescape/controller/PageController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package roomescape.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class PageController {

@GetMapping
public String home() {
return "index";
}

@GetMapping("/login")
public String login() {
return "login";
}

@GetMapping("/signup")
public String signUp() {
return "signup";
}

@GetMapping("/reservation")
public String reservation() {
return "reservation";
}

@GetMapping("/reservation-mine")
public String reservationMine() {
return "reservation-mine";
}

@GetMapping("/reservation/payment")
public String reservationPayment() {
return "reservation-payment";
}
}
13 changes: 0 additions & 13 deletions src/main/java/roomescape/controller/UserPageController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ public class AdminPageController {

@GetMapping
public String home() {
return "/admin/index";
return "admin/index";
}

@GetMapping("/reservation")
public String reservation() {
return "/admin/reservation-new";
return "admin/reservation-new";
}

@GetMapping("/time")
public String time() {
return "/admin/time";
return "admin/time";
}

@GetMapping("/theme")
public String theme() {
return "/admin/theme";
return "admin/theme";
}

@GetMapping("/waiting")
public String waiting() {
return "/admin/waiting";
return "admin/waiting";
}
}
7 changes: 7 additions & 0 deletions src/main/java/roomescape/domain/payment/PaymentFailure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package roomescape.domain.payment;

public record PaymentFailure(
String code,
String message
) {
}
27 changes: 27 additions & 0 deletions src/main/java/roomescape/domain/payment/PaymentResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package roomescape.domain.payment;

import com.fasterxml.jackson.annotation.JsonFormat;
import roomescape.domain.reservation.PaymentInfo;

import java.time.LocalDateTime;

public record PaymentResponse(
String mId,
String paymentKey,
String orderId,
PaymentStatus status,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
LocalDateTime requestedAt,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
LocalDateTime approvedAt,
PaymentFailure failure,
Integer totalAmount
) {
public PaymentInfo toPaymentInfo() {
return new PaymentInfo(paymentKey, orderId, totalAmount);
}

public boolean isNotDone() {
return status.isNotDone();
}
}
17 changes: 17 additions & 0 deletions src/main/java/roomescape/domain/payment/PaymentStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package roomescape.domain.payment;

public enum PaymentStatus {
READY,
IN_PROGRESS,
WAITING_FOR_DEPOSIT,
DONE,
CANCELED,
PARTIAL_CANCELED,
ABORTED,
EXPIRED,
;

public boolean isNotDone() {
return this != DONE;
}
}
56 changes: 56 additions & 0 deletions src/main/java/roomescape/domain/reservation/PaymentInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package roomescape.domain.reservation;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

import java.util.Objects;

@Embeddable
public class PaymentInfo {

@Column(unique = true)
private String paymentKey;

@Column(unique = true)
private String orderId;
lxxjn0 marked this conversation as resolved.
Show resolved Hide resolved

private Integer amount;

public PaymentInfo(String paymentKey, String orderId, Integer amount) {
this.paymentKey = paymentKey;
this.orderId = orderId;
this.amount = amount;
}

protected PaymentInfo() {
}

public String getPaymentKey() {
return paymentKey;
}

public String getOrderId() {
return orderId;
}

public Integer getAmount() {
return amount;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PaymentInfo that = (PaymentInfo) o;
return Objects.equals(paymentKey, that.paymentKey);
}

@Override
public int hashCode() {
return Objects.hash(paymentKey, orderId);
}
}
Loading