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

Member Entity 명칭 수정 #44

Merged
merged 24 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f792c9
feat: 결제 연동 기능 테스트 #29
bongsh0112 Sep 17, 2023
e7060e8
feat: 결제 연동 구현에 맞춘 dbml 수정 #29
bongsh0112 Sep 18, 2023
b8b38f7
feat: 결제 연동 구현 thymeleaf 오류 수정 1트 #29
bongsh0112 Sep 18, 2023
9ec5251
feat: 결제 연동 구현 thymeleaf 오류 수정 완료 #29
bongsh0112 Sep 18, 2023
bfb115a
.keep 생성
bongsh0112 Sep 18, 2023
243ab48
fix: console.log to alert
bongsh0112 Sep 19, 2023
78b6e26
Merge branch 'dev' into feat/29-payment
bongsh0112 Sep 19, 2023
dc6d260
fix: dbml 수정 #29
bongsh0112 Sep 19, 2023
2f0a133
feat: 결제 API 기본 템플릿 작성#29
bongsh0112 Sep 19, 2023
e4982dd
feat: 결제 API 기본 템플릿 작성 #29
bongsh0112 Sep 20, 2023
2d2f050
feat: 결제 DBML 수정 #29
bongsh0112 Sep 20, 2023
75d34ee
edit: 결제 DBML 수정 + 결제 API 초안 갈아엎기 #29
bongsh0112 Sep 20, 2023
49ec009
edit: 결제 DBML 수정 + 결제 API 초안 갈아엎기 #29
bongsh0112 Sep 20, 2023
3c0b465
feat: 결제 감 잡아가는중... #29
bongsh0112 Sep 20, 2023
4ae5c92
feat: 결제 API DTO test #29
bongsh0112 Sep 20, 2023
d96d511
feat: 결제 API DTO test 3트 #29
bongsh0112 Sep 20, 2023
d86a9d7
feat: 결제 API DTO test - test user 사용 #29
bongsh0112 Sep 20, 2023
b8f7fc8
feat: 결제 API 작성 #29
bongsh0112 Sep 20, 2023
2617535
feat: 오탈자 수정 #29
bongsh0112 Sep 21, 2023
3576e2b
feat: 결제 API 완료 #29
bongsh0112 Sep 21, 2023
d41af29
edit: payment history 테이블명 수정 #29
bongsh0112 Sep 21, 2023
ca55963
edit: Member Entity 명칭 수정 #29
bongsh0112 Sep 21, 2023
8a0da4a
dev merge #29
bongsh0112 Sep 21, 2023
34061b6
edit: validator 수정 #29
bongsh0112 Sep 21, 2023
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
12 changes: 1 addition & 11 deletions Api/src/main/java/picasso/server/api/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,5 @@ public class HomeController {
public String index() {
return "index";
}

@GetMapping("/payment-test")
public String payment() {
return "exchange";
}

@ResponseBody
@PostMapping("/payment-test")
public void sample(@RequestBody Map<String, String> map) throws Exception {
map.forEach((key, value) -> log.info("key >>> {}, value >>> {}", key, value));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package picasso.server.api.exchange.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
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.ResponseBody;
import picasso.server.api.exchange.model.request.PostCreatePaymentRequest;
import picasso.server.api.exchange.service.PaymentService;
import picasso.server.api.user.service.UserService;
import picasso.server.domain.domains.member.entity.User;

import java.util.Optional;

@Slf4j
@RequestMapping("/exchange")
@RequiredArgsConstructor
@Controller
public class PaymentController {

private final PaymentService paymentService;
private final UserService userService;

@GetMapping("/payment")
public String paymentForm() {
return "exchange";
}

@ResponseBody
@PostMapping("/payment")
public void createPayment(@RequestBody PostCreatePaymentRequest body) {
log.info("{} {} {} {} {} {}", body.getPayResult(), body.getUserId(), body.getMerchantUid(), body.getProductName(), body.getPgProvider(), body.getPaidAmount());
paymentService.savePaymentHistory(body);
Optional<User> user = userService.findUserById(body.getUserId());
user.ifPresent(u -> u.updatePoint(body.getPaidAmount()));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package picasso.server.api.exchange.model.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PostCreatePaymentRequest {
private Boolean payResult;
private Long userId;
private String merchantUid;
private String productName;
private String pgProvider;
private Long paidAmount;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package picasso.server.api.exchange.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import picasso.server.api.exchange.model.request.PostCreatePaymentRequest;
import picasso.server.api.exchange.validator.PaymentValidator;
import picasso.server.domain.domains.items.PGName;
import picasso.server.domain.domains.items.PaymentHistory;
import picasso.server.domain.domains.repository.PaymentHistoryRepository;

@Service
@RequiredArgsConstructor
public class PaymentService {

private final PaymentHistoryRepository paymentHistoryRepository;
private final PaymentValidator paymentValidator;

public void savePaymentHistory(PostCreatePaymentRequest request) {
paymentValidator.isFailedPayment(request.getPayResult());
paymentValidator.isPaymentExists(request.getMerchantUid());

PaymentHistory payment = PaymentHistory.builder()
.pgName(request.getPgProvider().equals("kakaopay") ? PGName.KAKAO : PGName.TOSS)
.productName(request.getProductName())
.merchantUid(request.getMerchantUid())
.amount(request.getPaidAmount())
.userId(request.getUserId())
.build();

paymentHistoryRepository.save(payment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import picasso.server.domain.domains.items.PaymentHistory;
import picasso.server.domain.domains.repository.ExchangeRepository;
import picasso.server.domain.domains.repository.PaymentHistoryRepository;

@RequiredArgsConstructor
public class ExchangeUtils {

private final ExchangeRepository exchangeRepository;
private final PaymentHistoryRepository paymentHistoryRepository;

@Transactional
public void save(PaymentHistory paymentHistory) {
exchangeRepository.save(paymentHistory);
paymentHistoryRepository.save(paymentHistory);
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package picasso.server.api.exchange.validator;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import picasso.server.api.exchange.model.request.PostCreatePaymentRequest;
import picasso.server.common.annotation.Validator;
import picasso.server.common.exception.PaymentAlreadyExistsException;
import picasso.server.common.exception.PaymentFailedException;
import picasso.server.domain.domains.repository.PaymentHistoryRepository;

@Slf4j
@Validator
@RequiredArgsConstructor
public class PaymentValidator {

private final PaymentHistoryRepository paymentHistoryRepository;

public void isPaymentExists(String merchantUid) {
paymentHistoryRepository.findPaymentHistoryByMerchantUid(merchantUid).ifPresent(
paymentHistory -> {
throw PaymentAlreadyExistsException.EXCEPTION;}
);
}

public void isFailedPayment(Boolean payResult) {
if (!payResult) {
throw PaymentFailedException.EXCEPTION;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package picasso.server.api.member.controller;
package picasso.server.api.user.controller;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import picasso.server.api.member.service.UserService;
import org.springframework.web.bind.annotation.ResponseBody;
import picasso.server.api.user.service.UserService;
import picasso.server.domain.domains.member.entity.User;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/member")
@RequestMapping("/user")
public class AuthController {

{
Expand Down Expand Up @@ -64,4 +67,15 @@ public String logout(HttpSession session) throws Exception {
session.invalidate();
return "redirect:/";
}


// TODO: 테스트용 Controller 입니다. 추후 삭제 혹은 변경이 필요합니다.
@ResponseBody
@PostMapping("/session-info")
public Map<String, Long> paymentSessionInfoRtn(HttpSession session) {
User temp = (User)session.getAttribute("loginUser");
return new HashMap<String, Long>(){{
put("userId", 1L);
}};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package picasso.server.api.member.service;
package picasso.server.api.user.service;
//
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -38,11 +38,10 @@ public Optional<User> findUserByEmailAndPassword(String email, String password)
}

public Optional<User> findUserByNickname(String nickname) {
return userRepository.findByNickname(nickname);
return userRepository.findByNickName(nickname);
}

public void deleteUserById(Long id) {
userRepository.deleteById(id);
}

}
Loading