From b19b09796a249491b37ba437a4110fe52a5ba604 Mon Sep 17 00:00:00 2001 From: Yi JoonYong Date: Sat, 31 Aug 2024 13:49:25 +0900 Subject: [PATCH] =?UTF-8?q?[Fix/#110]=20=EA=B0=80=EC=A1=B1=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EB=B0=98=ED=99=98,?= =?UTF-8?q?=201=EC=9B=90=EC=9D=B8=EC=A6=9D=20=EC=95=8C=EB=A6=BC=20body=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EB=B3=80=EA=B2=BD=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Fix] #110 - 1원 송금정보 알림 body 타입 변경 * [Add] #110 - User, AcceptStatus로 Approval조회 메서드 추가 * [Fix] #110 - 승인되지 않은 가족 초대 요청만 반환하도록 수정 --- .../controller/ApprovalController.java | 4 ++- .../repository/ApprovalRepository.java | 3 +++ .../approval/service/ApprovalService.java | 27 +++++++++++-------- .../domain/user/service/UserService.java | 23 +++++++++++++--- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/controller/ApprovalController.java b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/controller/ApprovalController.java index 1dc3256..f1d8d9c 100644 --- a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/controller/ApprovalController.java +++ b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/controller/ApprovalController.java @@ -8,6 +8,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("/approval") @RequiredArgsConstructor @@ -16,7 +18,7 @@ public class ApprovalController { private final ApprovalService approvalService; @GetMapping - public ResponseEntity searchApproval() { + public ResponseEntity> searchApproval() { return ResponseEntity.ok(approvalService.getApproval()); } diff --git a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/repository/ApprovalRepository.java b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/repository/ApprovalRepository.java index bb7a663..585b5d4 100644 --- a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/repository/ApprovalRepository.java +++ b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/repository/ApprovalRepository.java @@ -1,5 +1,6 @@ package com.shinhan_hackathon.the_family_guardian.domain.approval.repository; +import com.shinhan_hackathon.the_family_guardian.domain.approval.entity.AcceptStatus; import com.shinhan_hackathon.the_family_guardian.domain.approval.entity.Approval; import com.shinhan_hackathon.the_family_guardian.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; @@ -12,4 +13,6 @@ public interface ApprovalRepository extends JpaRepository { Optional findByUser(User user); List findAllByUser(User user); + + List findAllByUserAndAccepted(User user, AcceptStatus acceptStatus); } diff --git a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/service/ApprovalService.java b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/service/ApprovalService.java index 4f989c7..fb4e599 100644 --- a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/service/ApprovalService.java +++ b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/approval/service/ApprovalService.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.Optional; @Service @@ -52,18 +53,22 @@ public Long createApproval(Family family, User user, String relationship) { return approval.getId(); } - public ApprovalInfoResponse getApproval() { + public List getApproval() { User user = authUtil.getUserPrincipal().user(); - Approval approval = approvalRepository.findByUser(user) - .orElseThrow(() -> new RuntimeException("초대가 없습니다.")); - Family family = approval.getFamily(); - - return new ApprovalInfoResponse( - approval.getId(), - family.getId(), - family.getName(), - family.getDescription() - ); + + List approvalList = approvalRepository.findAllByUserAndAccepted(user, AcceptStatus.PROGRESS); + + List approvalInfoResponseList = approvalList.stream().map(approval -> { + Family family = approval.getFamily(); + return new ApprovalInfoResponse( + approval.getId(), + family.getId(), + family.getName(), + family.getDescription() + ); + }).toList(); + + return approvalInfoResponseList; } @Transactional diff --git a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/user/service/UserService.java b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/user/service/UserService.java index e8052b8..3f28262 100644 --- a/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/user/service/UserService.java +++ b/src/main/java/com/shinhan_hackathon/the_family_guardian/domain/user/service/UserService.java @@ -5,9 +5,12 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.HashMap; import java.util.List; import java.util.UUID; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -61,8 +64,9 @@ public class UserService { private final ApprovalService approvalService; private final ApprovalRepository approvalRepository; private final FcmSender fcmSender; + private final ObjectMapper jacksonObjectMapper; - @Transactional + @Transactional public LoginResponse createUser(SignupRequest signupRequest) { validateSignupRequest(signupRequest); @@ -112,9 +116,20 @@ public AccountAuthResponse openAccountAuth(String accountNo, String deviceToken) String accountAuthCode = getAccountAuthCode(accountNo, openAccountAuthResponse); log.info("[NOTIFICATION] account auth code: {}", accountAuthCode); - fcmSender.sendMessage(deviceToken, "인증", accountAuthCode+","+"신한 "+accountNo+",1"); - - return new AccountAuthResponse(openAccountAuthResponse.rec().accountNo(), csrfToken); + HashMap map = new HashMap<>(); + map.put("auth_code", accountAuthCode); + map.put("bank", "신한"); + map.put("account_no", accountNo); + map.put("transaction_balance", "1"); + try { + String bodyStr = jacksonObjectMapper.writeValueAsString(map); + fcmSender.sendMessage(deviceToken, "인증", bodyStr); + + return new AccountAuthResponse(openAccountAuthResponse.rec().accountNo(), csrfToken); + } catch (JsonProcessingException e) { + log.info("1원송금 fcm body 변환 실패"); + throw new RuntimeException(e); + } } private String getAccountAuthCode(String accountNo, OpenAccountAuthResponse openAccountAuthResponse) {