Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Tea-Bliss/BE_Tea_Bliss into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mun9659 committed Jun 24, 2024
2 parents e7c92e5 + 6cd3193 commit d1d21d7
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import org.springframework.web.bind.annotation.*;

import store.teabliss.member.entity.MemberDetails;
import store.teabliss.payment.dto.PaymentRequestDto;
import store.teabliss.payment.dto.PaymentResponseDto;
import store.teabliss.payment.service.PaymentService;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -48,6 +51,17 @@ public ResponseEntity<?> payment(@RequestParam ("paymentId") String paymentId,@A
return ResponseEntity.ok(portone);


}

@GetMapping("/")
@Operation(summary = "결제 내역 조회", description = "결제 내역 조회입니다.")
public ResponseEntity<?> getpayment(@AuthenticationPrincipal MemberDetails memberDetails){

List<PaymentRequestDto> result=paymentService.getpayment(memberDetails.getMemberId());


return ResponseEntity.ok(result);



}
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/store/teabliss/payment/dto/PaymentRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package store.teabliss.payment.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import store.teabliss.payment.entity.DBProduct;
import store.teabliss.review.entity.Review;

import java.util.List;


@Builder
@Getter
@ToString
public class PaymentRequestDto {

private Long paymentid;


private List<Object> productList;


private String paidAt;



public static PaymentRequestDto of(Long paymentid,List<Object> productList,String paidAt) {
return PaymentRequestDto.builder().paymentid(paymentid)
.productList(productList)
.paidAt(paidAt)
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/java/store/teabliss/payment/entity/DBPayment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DBPayment {

private String orderName;

private LocalDateTime paidAt;
private String paidAt;



Expand Down
5 changes: 5 additions & 0 deletions src/main/java/store/teabliss/payment/entity/DBProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@


import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Builder
@Getter
@Setter

public class DBProduct {

private Long payId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.ibatis.annotations.Mapper;
import store.teabliss.payment.entity.*;

import java.util.List;

@Mapper
public interface PaymentMapper {

Expand All @@ -14,5 +16,9 @@ public interface PaymentMapper {
void savecustomer(DBCustomer dbCustomer);
void savecard(DBCard dbCard);

List<DBPayment> searchpayid(Long id);
List<DBProduct> searchprodcut(Long paymentId);



}
58 changes: 56 additions & 2 deletions src/main/java/store/teabliss/payment/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import store.teabliss.basket.mapper.BasketMapper;
import store.teabliss.payment.dto.PaymentRequestDto;
import store.teabliss.payment.dto.PaymentResponseDto;
import store.teabliss.payment.entity.*;
import store.teabliss.payment.mapper.PaymentMapper;
import store.teabliss.review.entity.Review;
import store.teabliss.review.mapper.ReviewMapper;
import store.teabliss.tea.mapper.TeaMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
Expand All @@ -27,6 +32,7 @@ public class PaymentService {
private final TeaMapper teaMapper;
private final BasketMapper basketMapper;
private final PaymentMapper paymentMapper;
private final ReviewMapper reviewMapper;

//amount 설정
PayAmount payAmount=new PayAmount();
Expand All @@ -38,12 +44,16 @@ public class PaymentService {
//webclient 설정
WebClient client=WebClient.create("https://api.portone.io/payments");

@Value("${portone.beartoken}")
private String token;

public PaymentResponseDto portone(String paymentId){


// api 요청
Mono<PaymentResponseDto> result=client.get()
.uri("/{paymentId}",paymentId)
.header("Authorization", "PortOne SMS7u8BYzRSw2qJzBaHnkUowNREOWJgkCBW13xRBFNixOOdZC5mKubNuADhwW0qMWLXZrUPM3H4Hb7je")
.header("Authorization", token)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(PaymentResponseDto.class);
Expand Down Expand Up @@ -94,7 +104,7 @@ public boolean payment(PaymentResponseDto paymentResponseDto,Long memId){

//inventory 변경
teaMapper.updateinventory(name, quantity);
//basket 변경
//판매수량 변경
teaMapper.updatesale(name, quantity);

String result=basketMapper.search(name,memId);
Expand Down Expand Up @@ -161,5 +171,49 @@ public boolean payment(PaymentResponseDto paymentResponseDto,Long memId){



}


public List<PaymentRequestDto> getpayment(Long id){

//일단 payment의 고유 아이디 구해서
List<DBPayment> payment=paymentMapper.searchpayid(id);

List<PaymentRequestDto> paymentRequestDtos =new ArrayList<>();

for (DBPayment pay:payment) {
//그중에서 모든 구매 prodcut 구하고
Long paymentId= pay.getId();
List<DBProduct> products = paymentMapper.searchprodcut(pay.getId());
List<Object> finalproducts=new ArrayList<>();

for (DBProduct product : products){
Map<String,Object> response=new HashMap<>();

String name= product.getName();
Long findId=teaMapper.findByidandname(name);

boolean reviewok=reviewMapper.findByteaidandmember(findId,id);

response.put("review",reviewok);
response.put("product",product);

finalproducts.add(response);

}

//paid_at 도 구한다.

String paid_at = pay.getPaidAt();
paymentRequestDtos.add(PaymentRequestDto.of(paymentId,finalproducts,paid_at));


}

return paymentRequestDtos;




}
}
2 changes: 2 additions & 0 deletions src/main/java/store/teabliss/review/mapper/ReviewMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface ReviewMapper {

void updateReview(Review review);

boolean findByteaidandmember(Long tea_id,Long mem_id);

}
2 changes: 2 additions & 0 deletions src/main/java/store/teabliss/tea/mapper/TeaMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public interface TeaMapper {

void deleteFlavor(Long tea_id);

Long findByidandname(String name);



}
4 changes: 3 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ jwt:
# client_secret: ${GOOGLE_CLIENT_SECRET}
# scope: # 기본 값 openid,profile,email => profile, email 로 설정 변경
# - profile
# - email
# - emailportone:
portone:
beartoken: ${PORTONE_BEARTOKEN}
11 changes: 11 additions & 0 deletions src/main/resources/mapper/PaymentMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
VALUES (#{payId},#{name})
</insert>

<select id="searchpayid">
SELECT *
FROM PAYMENT
WHERE mem_id=#{id}
</select>

<select id="searchprodcut">
SELECT *
FROM PAYPRODUCT
WHERE pay_Id=#{payment_id}
</select>



Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mapper/ReviewMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,12 @@
AND tea_id = #{teaId}
</update>

<select id="findByteaidandmember" resultType="boolean">
SELECT IF(COUNT(*) = 1, 1, 0)
FROM REVIEW
WHERE mem_id = #{mem_id} AND tea_id=#{tea_id}

</select>

</mapper>

9 changes: 7 additions & 2 deletions src/main/resources/mapper/TeaMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
<select id="findByIngredient">
SELECT ingredient_id
FROM TEAINGREDIENT
WHERE tea_id =#{id} AND delete_yn=0
WHERE tea_id =#{id}

</select>

<select id="findByFlavor">
SELECT flavor_id
FROM TEAFLAVOR
WHERE tea_id =#{id} AND delete_yn=0
WHERE tea_id =#{id}

</select>

Expand Down Expand Up @@ -225,6 +225,11 @@
DELETE FROM TEAFLAVOR
WHERE tea_id=#{tea_id}
</delete>
<select id="findByidandname">
SELECT id
FROM TEA
WHERE name=#{name}
</select>


</mapper>

0 comments on commit d1d21d7

Please sign in to comment.