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

weekly_10 병합 #86

Merged
merged 45 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bbfd92d
feat: 응답헤더로 cookie set (httponly, secure 적용)
westzeroright Nov 2, 2024
e3d6300
Merge pull request #71 from kakao-tech-campus-2nd-step3/refactor/70/l…
westzeroright Nov 4, 2024
76b817b
remove: 중복 파일 제거
nove1080 Nov 4, 2024
77acc76
feat: Point 사용 요청/응답 dto 생성
nove1080 Nov 4, 2024
8224af8
feat: 포인트 차감 API 더미 코드 개발
nove1080 Nov 4, 2024
6f398ab
remove: 사용하지 않는 파일 삭제
nove1080 Nov 5, 2024
61de9d1
feat: data.sql 더미 데이터 추가
nove1080 Nov 5, 2024
a07e72a
feat: 결제 상태 이름으로 조회 메서드 추가
nove1080 Nov 5, 2024
665abd5
feat: 결제 내역 DTO 생성
nove1080 Nov 5, 2024
08eda8d
feat: 결제 내역 조회 기능 구현
nove1080 Nov 5, 2024
f922e67
feat: 결제 내역 조회 API 개발
nove1080 Nov 5, 2024
9b45b76
test: 테스트 코드 유지보수
nove1080 Nov 5, 2024
4400773
fix: 쓰지 않는 패키지 삭제
rbm0524 Nov 6, 2024
4427bc1
refactor: code와 ENUM값 변환 수정
rbm0524 Nov 6, 2024
4c06a03
refactor: code 추가, 변환 로직 추가
rbm0524 Nov 6, 2024
ed8303f
refactor: 예외 추가, 변환 로직 추가
rbm0524 Nov 6, 2024
0ebeeed
refactor: Spot 전체 조회 로직 수정에 다른 메서드 삭제
rbm0524 Nov 6, 2024
28dea61
refactor: converter 어노테이션 추가
rbm0524 Nov 6, 2024
be92b91
fix: 사용하지 않는 메서드 삭제
rbm0524 Nov 6, 2024
534e04b
refactor: String으로 타입 변환
rbm0524 Nov 6, 2024
b89e120
refactor: Builder 어노테이션 추가
rbm0524 Nov 6, 2024
a2eb986
refactor: String으로 타입 변환
rbm0524 Nov 6, 2024
a4a2ac5
refactor: setter 추가
rbm0524 Nov 6, 2024
b941cec
refactor: Exception refactor
rbm0524 Nov 6, 2024
af5eb74
refactor: Mapping 방식 수정
rbm0524 Nov 6, 2024
5ec5e0c
refactor: 예외 처리 로직 추가, 채워지지 않는 필드에 대한 로직 추가
rbm0524 Nov 6, 2024
818c78d
refactor: String으로 타입 변환
rbm0524 Nov 6, 2024
8ccad08
feat: Exception 추가
rbm0524 Nov 6, 2024
87eadd1
feat: 테스트 코드 작성
rbm0524 Nov 6, 2024
9755d2a
fix: 중복으로 인한 에러 수정
rbm0524 Nov 7, 2024
b955efe
fix: category를 제외한 다른 필드들도 매핑되도록 수정
rbm0524 Nov 7, 2024
f945b67
refactor: 테스트 추가 작성
rbm0524 Nov 7, 2024
3d1735a
refactor: dialect 추가
rbm0524 Nov 7, 2024
09bb55f
feat: Category.class를 AbstractCodedEnumConverter에 전달하는 클래스 작성
rbm0524 Nov 7, 2024
9ca780c
fix: Autowired 제거
rbm0524 Nov 7, 2024
e2aec99
refactor: 클래스를 상속해서 Category에 대한 Converter가 동작하도록 수정
rbm0524 Nov 7, 2024
505eb95
fix: CategoryConverter를 사용하는 것으로 수정
rbm0524 Nov 7, 2024
47fe1a0
fix: Converter를 통해 코드를 저장하도록 수정 + refactor
rbm0524 Nov 8, 2024
46cdfca
fix: SpotMapper에서 category가 매핑이 되지 않는 부분 수정
rbm0524 Nov 8, 2024
929af21
fix: response는 String이므로 비교 대상 수정
rbm0524 Nov 8, 2024
13794a9
style: 코드 스타일 수정
rbm0524 Nov 8, 2024
136032f
refactor: 사용하지 않는 import문 제거
rbm0524 Nov 8, 2024
31725c5
refactor: 페이지 리다이렉트 외부 url이 가능하도록 함
westzeroright Nov 8, 2024
ee23776
feat: 로그아웃 구현, 쿠키 삭제
westzeroright Nov 8, 2024
f886d21
refactor: 리다이렉트url을 value로 주입받음
westzeroright Nov 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
import com.ordertogether.team14_be.member.application.dto.MemberInfoRequest;
import com.ordertogether.team14_be.member.application.service.MemberService;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Controller
@RequestMapping("/api/v1/auth")
public class AuthController {

Expand All @@ -42,18 +43,39 @@ public AuthController(
}

@GetMapping("/login")
public ResponseEntity<ApiResponse<String>> getToken(@RequestHeader String authorizationCode) {
public ResponseEntity<ApiResponse<String>> getToken(
@RequestHeader("Authorization") String authorizationHeader,
HttpServletResponse httpServletResponse) {
String authorizationCode = authorizationHeader.replace("Bearer ", "");
System.out.println("인가코드:" + authorizationCode);
String userKakaoEmail = kakaoAuthService.getKakaoUserEmail(authorizationCode);
System.out.println("이메일:" + userKakaoEmail);
Optional<Member> existMember = memberService.findMemberByEmail(userKakaoEmail);
if (existMember.isPresent()) {
return ResponseEntity.ok(
ApiResponse.with(HttpStatus.OK, "로그인 성공", authService.getServiceToken(userKakaoEmail)));
String serviceToken = authService.getServiceToken(userKakaoEmail);

ResponseCookie cookie =
ResponseCookie.from("serviceToken", serviceToken)
.httpOnly(true)
.secure(true)
.path("/")
.sameSite("Strict")
.build();

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.SET_COOKIE, cookie.toString());

return ResponseEntity.ok()
.headers(headers)
.body(ApiResponse.with(HttpStatus.OK, "로그인 성공", serviceToken));
} else {
return ResponseEntity.status(HttpStatus.FOUND)
.location(
URI.create(redirectPage + URLEncoder.encode(userKakaoEmail, StandardCharsets.UTF_8)))
.build();
String redirectUrl = redirectPage + userKakaoEmail;
try {
httpServletResponse.sendRedirect(redirectUrl);
} catch (IOException e) {
System.out.println(e.getMessage());
}
return ResponseEntity.ok().body(ApiResponse.with(HttpStatus.OK, "리다이렉트", redirectUrl));
}
}

Expand All @@ -63,13 +85,35 @@ public ResponseEntity<ApiResponse<String>> signUpMember(
String serviceToken =
authService.register(
email, memberInfoRequest.deliveryName(), memberInfoRequest.phoneNumber());
return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "로그인 성공", serviceToken));

ResponseCookie cookie =
ResponseCookie.from("serviceToken", serviceToken)
.httpOnly(true)
.secure(true)
.path("/")
.sameSite("Strict")
.build();

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.SET_COOKIE, cookie.toString());

return ResponseEntity.ok()
.headers(headers)
.body(ApiResponse.with(HttpStatus.OK, "회원가입 성공", serviceToken));
}

@PostMapping("/signup")
public ResponseEntity<ApiResponse<String>> signUpMember(
@RequestParam String email, @RequestBody MemberInfoRequest memberInfoRequest) {
return authService.register(
email, memberInfoRequest.deliveryName(), memberInfoRequest.phoneNumber());
@PostMapping("/logout")
public void logout(HttpServletResponse response) {
ResponseCookie deleteCookie =
ResponseCookie.from("serviceToken", "")
.maxAge(0)
.httpOnly(true)
.secure(true)
.path("/")
.sameSite("Strict")
.build();

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.SET_COOKIE, deleteCookie.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ordertogether.team14_be.member.application.service;

import com.ordertogether.team14_be.auth.JwtUtil;
import com.ordertogether.team14_be.member.application.dto.MemberInfoResponse;
import com.ordertogether.team14_be.member.application.exception.NotFoundMember;
import com.ordertogether.team14_be.member.persistence.MemberRepository;
Expand Down Expand Up @@ -36,25 +37,6 @@ public MemberInfoResponse findMemberInfo(Long memberId) {
.build();
}

@Transactional(readOnly = true)
public Long getMemberId(String email) {
return memberRepository
.findByEmail(email)
.map(Member::getId)
.orElseThrow(() -> new NoSuchElementException("Member with email " + email + " not found"));
}

@Transactional(readOnly = true)
public MemberInfoResponse findMemberInfo(Long memberId) {
Member member = findMember(memberId);

return MemberInfoResponse.builder()
.deliveryName(member.getDeliveryName())
.phoneNumber(member.getPhoneNumber())
.point(member.getPoint())
.build();
}

@Transactional
public MemberInfoResponse modifyMember(Long memberId, String deliveryName, String phoneNumber) {
Member member = findMember(memberId);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ordertogether.team14_be.payment.domain;

import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -21,4 +22,12 @@ public boolean isSuccess() {
public boolean isFail() {
return this == FAIL;
}

public static PaymentStatus fromString(String statusName) {
return Arrays.stream(PaymentStatus.values())
.filter(paymentStatus -> paymentStatus.name().equalsIgnoreCase(statusName))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException("%s 는 올바른 결제 상태가 아닙니다.".formatted(statusName)));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.ordertogether.team14_be.payment.persistence.jpa.repository;

import com.ordertogether.team14_be.payment.domain.PaymentOrder;
import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity;
import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity;
import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentOrderMapper;
import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper;
import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository;
import com.ordertogether.team14_be.payment.web.dto.PaymentHistory;
import java.math.BigDecimal;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -74,6 +76,11 @@ public BigDecimal getPaymentTotalAmount(String orderId) {
() -> new NoSuchElementException("주문 번호: %s 에 해당하는 주문이 존재하지 않습니다.".formatted(orderId)));
}

@Override
public List<PaymentHistory> getChargeHistory(Long memberId, PaymentStatus paymentStatus) {
return simpleJpaPaymentOrderRepository.getChargeHistory(memberId, paymentStatus);
}

private ProductEntity getProductEntity(PaymentOrder paymentOrder) {
return simpleJpaProductRepository
.findById(paymentOrder.getProductId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ordertogether.team14_be.payment.persistence.jpa.repository;

import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity;
import com.ordertogether.team14_be.payment.web.dto.PaymentHistory;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
Expand All @@ -15,4 +17,12 @@ public interface SimpleJpaPaymentOrderRepository extends JpaRepository<PaymentOr
Optional<BigDecimal> getPaymentTotalAmount(String orderId);

List<PaymentOrderEntity> findByOrderId(String orderId);

@Query(
"SELECT new com.ordertogether.team14_be.payment.web.dto.PaymentHistory(poe.amount, poe.createdAt) FROM PaymentOrderEntity poe"
+ " WHERE poe.orderId IN "
+ " (SELECT bpee.orderId "
+ " FROM PaymentEventEntity bpee "
+ " WHERE bpee.buyerId = :memberId AND bpee.paymentStatus = :paymentStatus) ")
List<PaymentHistory> getChargeHistory(Long memberId, PaymentStatus paymentStatus);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ordertogether.team14_be.payment.persistence.repository;

import com.ordertogether.team14_be.payment.domain.PaymentOrder;
import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import com.ordertogether.team14_be.payment.web.dto.PaymentHistory;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
Expand All @@ -22,4 +24,6 @@ public interface PaymentOrderRepository {
* @return 총 결제 금액
*/
BigDecimal getPaymentTotalAmount(String orderId);

List<PaymentHistory> getChargeHistory(Long memberId, PaymentStatus paymentStatus);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ordertogether.team14_be.payment.service;

import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository;
import com.ordertogether.team14_be.payment.web.dto.PaymentHistory;
import com.ordertogether.team14_be.payment.web.response.PaymentHistoryResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PaymentHistoryService {

private final PaymentOrderRepository paymentOrderRepository;

public PaymentHistoryResponse getChargeHistory(Long memberId, PaymentStatus paymentStatus) {
List<PaymentHistory> histories =
paymentOrderRepository.getChargeHistory(memberId, paymentStatus);
return PaymentHistoryResponse.builder().histories(histories).build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.ordertogether.team14_be.payment.web.controller;

import com.ordertogether.team14_be.common.web.response.ApiResponse;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import com.ordertogether.team14_be.member.presentation.LoginMember;
import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import com.ordertogether.team14_be.payment.service.PaymentConfirmService;
import com.ordertogether.team14_be.payment.service.PaymentHistoryService;
import com.ordertogether.team14_be.payment.service.PaymentPreparationService;
import com.ordertogether.team14_be.payment.web.request.PaymentConfirmRequest;
import com.ordertogether.team14_be.payment.web.request.PaymentHistoryRequest;
import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest;
import com.ordertogether.team14_be.payment.web.response.PaymentConfirmationResponse;
import com.ordertogether.team14_be.payment.web.response.PaymentHistoryResponse;
import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;
Expand All @@ -22,12 +29,12 @@ public class PaymentController {

private final PaymentPreparationService paymentPreparationService;
private final PaymentConfirmService paymentConfirmService;
private final PaymentHistoryService paymentHistoryService;

@PostMapping
public ResponseEntity<ApiResponse<PaymentPrepareResponse>> preparePayment(
@RequestBody PaymentPrepareRequest request) {
// todo: 1L -> UserDetail.getUserId()
request.addBuyerId(1L);
@RequestBody PaymentPrepareRequest request, @LoginMember Member member) {
request.addBuyerId(member.getId());
PaymentPrepareResponse data = paymentPreparationService.prepare(request);

return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제 정보를 저장하였습니다.", data));
Expand All @@ -43,4 +50,15 @@ public ResponseEntity<ApiResponse<PaymentConfirmationResponse>> confirmPayment(
}
return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제가 완료되었습니다.", data));
}

@GetMapping("/history")
public ResponseEntity<ApiResponse<PaymentHistoryResponse>> getHistory(
@RequestBody PaymentHistoryRequest request, @LoginMember Member member) {
return ResponseEntity.ok(
ApiResponse.with(
HttpStatus.OK,
"포인트 사용 내역을 조회하였습니다.",
paymentHistoryService.getChargeHistory(
member.getId(), PaymentStatus.fromString(request.paymentStatus()))));
}
}
Loading