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

Hotfix/develop #7

Merged
merged 8 commits into from
Dec 26, 2023
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '0.1.0-alpha2'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.mock-server:mockserver-netty:5.11.2' // 사용 중인 MockServer 버전
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
package kr.bb.payment.controller.clientcontroller;

import bloomingblooms.response.SuccessResponse;
import java.time.LocalDateTime;
import kr.bb.payment.dto.request.KakaopayApproveRequestDto;
import kr.bb.payment.dto.request.KakaopayReadyRequestDto;
import kr.bb.payment.dto.response.KakaopayReadyResponseDto;
import kr.bb.payment.service.KakaopayService;
import kr.bb.payment.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/client")
@RequiredArgsConstructor
public class OrderClientController {

private final PaymentService paymentService;
private final KakaopayService kakaopayService;

@PostMapping("/ready")
public ResponseEntity<SuccessResponse<KakaopayReadyResponseDto>> payReady(
public SuccessResponse<KakaopayReadyResponseDto> payReady(
@RequestBody KakaopayReadyRequestDto readyRequestDto) {

KakaopayReadyResponseDto responseDto = kakaopayService.kakaoPayReady(readyRequestDto);

return ResponseEntity.ok()
.body(
SuccessResponse.<KakaopayReadyResponseDto>builder()
.code(String.valueOf(HttpStatus.OK.value()))
.message(HttpStatus.OK.name())
.data(responseDto)
.build());
return SuccessResponse.<KakaopayReadyResponseDto>builder()
.data(responseDto)
.message(HttpStatus.OK.name())
.build();
}

@PostMapping("/approve")
public ResponseEntity<SuccessResponse<Void>> payApprove(@RequestBody KakaopayApproveRequestDto approveRequestDto){
public SuccessResponse<LocalDateTime> payApprove(
@RequestBody KakaopayApproveRequestDto approveRequestDto) {

kakaopayService.kakaoPayApprove(approveRequestDto);
LocalDateTime paymentDateTime = kakaopayService.kakaoPayApprove(approveRequestDto);

return ResponseEntity.ok().body(SuccessResponse.<Void>builder()
.code(String.valueOf(HttpStatus.OK.value()))
.message(HttpStatus.OK.name())
.build());
return SuccessResponse.<LocalDateTime>builder()
.data(paymentDateTime)
.message(HttpStatus.OK.name())
.build();
}
}
19 changes: 10 additions & 9 deletions src/main/java/kr/bb/payment/entity/Subscription.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.bb.payment.entity;

import java.time.LocalDate;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -24,7 +25,7 @@ public class Subscription extends BaseEntity {
private Long subscriptionId;

@Column(name = "order_subscription_id", unique = true, nullable = false)
private Long orderSubscriptionId;
private String orderSubscriptionId;

@Column(name = "subscription_cid", nullable = false)
private String subscriptionCid;
Expand All @@ -35,18 +36,18 @@ public class Subscription extends BaseEntity {
@Column(name = "subscription_sid", unique = true, nullable = false)
private String subscriptionSid;

@Column(name = "subscription_quantity", unique = true, nullable = false)
@Column(name = "subscription_quantity", nullable = false)
private Long subscriptionQuantity;

@Column(name = "subscription_total_amount", unique = true, nullable = false)
@Column(name = "subscription_total_amount", nullable = false)
private Long subscriptionTotalAmount;

@Column(name = "payment_day", unique = true, nullable = false)
private String paymentDay;
@Column(name = "payment_date", nullable = false)
private LocalDate paymentDate;

@Column(name = "start_date", unique = true, nullable = false)
private Date startDate;
@Column(name = "start_date", nullable = false)
private LocalDate startDate;

@Column(name = "end_date", unique = true, nullable = true)
private Date endDate;
@Column(name = "end_date")
private LocalDate endDate;
}
2 changes: 2 additions & 0 deletions src/main/java/kr/bb/payment/entity/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/kr/bb/payment/feign/ProductServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
@FeignClient(name = "productServiceClient", url = "${endpoint.product-service")
public interface ProductServiceClient {

// 유효한지
@PostMapping("/api/products/prices")
SuccessResponse<Map<Long, Long>> getPricesByProductIds(
@RequestParam("productIds") List<Long> productIds);
}
10 changes: 5 additions & 5 deletions src/main/java/kr/bb/payment/service/KakaopayService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kr.bb.payment.service;

import java.time.LocalDateTime;
import kr.bb.payment.dto.request.KakaopayApproveRequestDto;
import kr.bb.payment.dto.request.KakaopayReadyRequestDto;
import kr.bb.payment.dto.response.KakaoPayApproveResponseDto;
import kr.bb.payment.dto.response.KakaopayReadyResponseDto;
import kr.bb.payment.entity.Payment;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -28,7 +28,7 @@ public class KakaopayService {
private String APIGATEWAY_SERVICE_URL;

public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto) {
String cid = requestDto.isSubscriptionPay() ? "TC0ONETIME" : "TCSUBSCRIP";
String cid = requestDto.isSubscriptionPay() ? "TCSUBSCRIP" : "TC0ONETIME";

MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();

Expand All @@ -46,7 +46,7 @@ public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto
+ "/api/orders/approve/"
+ requestDto.getOrderId()
+ "/"
+ requestDto.getUserId());
+ requestDto.getOrderType());
parameters.add("cancel_url", APIGATEWAY_SERVICE_URL + "/api/orders/cancel");
parameters.add("fail_url", APIGATEWAY_SERVICE_URL + "/api/orders/fail");

Expand All @@ -60,7 +60,7 @@ public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto
return responseDto;
}

public void kakaoPayApprove(KakaopayApproveRequestDto requestDto) {
public LocalDateTime kakaoPayApprove(KakaopayApproveRequestDto requestDto) {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();

parameters.add("cid", requestDto.getCid());
Expand All @@ -76,7 +76,7 @@ public void kakaoPayApprove(KakaopayApproveRequestDto requestDto) {

restTemplate.postForObject(url, requestEntity, KakaoPayApproveResponseDto.class);

paymentService.savePaymentInfo(requestDto);
return paymentService.savePaymentInfo(requestDto);
}

@NotNull
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/kr/bb/payment/service/PaymentService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.bb.payment.service;

import java.time.LocalDateTime;
import kr.bb.payment.dto.request.KakaopayApproveRequestDto;
import kr.bb.payment.dto.request.KakaopayReadyRequestDto;
import kr.bb.payment.dto.response.KakaoPayApproveResponseDto;
Expand All @@ -24,7 +25,7 @@ public class PaymentService {
* @return void
*/
@Transactional
public void savePaymentInfo(
public LocalDateTime savePaymentInfo(
KakaopayApproveRequestDto requestDto) {

OrderType type =
Expand All @@ -35,5 +36,6 @@ public void savePaymentInfo(
// Payment 객체를 DB에 저장
Payment payment = Payment.toEntity(requestDto, type);
paymentRepository.save(payment);
return payment.getCreatedAt();
}
}
20 changes: 20 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server:
port: 8100
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
application:
name: product-service
config:
activate:
on-profile: dev
import: optional:configserver:http://config-service:8888
management:
endpoints:
web:
exposure:
include:
- "refresh"
- "bus-refresh"
- "health"
40 changes: 19 additions & 21 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
server:
port: 8100
spring:
h2:
console:
enabled: true
path: /h2-console
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:payment-service;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
jpa:
hibernate:
ddl-auto: create
generate-ddl: true
defer-datasource-initialization: true
properties:
hibernate:
format_sql: true


kakao:
admin: e217481aeaeb6c14f8f10912b441f961
endpoint:
apigateway-service: http://localhost:3000
mvc:
pathmatch:
matching-strategy: ant_path_matcher
application:
name: product-service
config:
activate:
on-profile: local
import: optional:configserver:http://localhost:8888
management:
endpoints:
web:
exposure:
include:
- "refresh"
- "bus-refresh"
- "health"
20 changes: 20 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server:
port: 8100
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
application:
name: product-service
config:
activate:
on-profile: prod
import: optional:configserver:http://config-service:8888
management:
endpoints:
web:
exposure:
include:
- "refresh"
- "bus-refresh"
- "health"
16 changes: 0 additions & 16 deletions src/main/resources/application.yml

This file was deleted.

Loading