Skip to content

Commit

Permalink
[Fix/#110] 가족초대 응답값 반환, 1원인증 알림 body 타입변경 (#112)
Browse files Browse the repository at this point in the history
* [Fix] #110 - 1원 송금정보 알림 body 타입 변경

* [Add] #110 - User, AcceptStatus로 Approval조회 메서드 추가

* [Fix] #110 - 승인되지 않은 가족 초대 요청만 반환하도록 수정
  • Loading branch information
given-dragon authored Aug 31, 2024
1 parent 1c1a6e3 commit b19b097
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approval")
@RequiredArgsConstructor
Expand All @@ -16,7 +18,7 @@ public class ApprovalController {
private final ApprovalService approvalService;

@GetMapping
public ResponseEntity<ApprovalInfoResponse> searchApproval() {
public ResponseEntity<List<ApprovalInfoResponse>> searchApproval() {
return ResponseEntity.ok(approvalService.getApproval());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,4 +13,6 @@ public interface ApprovalRepository extends JpaRepository<Approval, Long> {
Optional<Approval> findByUser(User user);

List<Approval> findAllByUser(User user);

List<Approval> findAllByUserAndAccepted(User user, AcceptStatus acceptStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -52,18 +53,22 @@ public Long createApproval(Family family, User user, String relationship) {
return approval.getId();
}

public ApprovalInfoResponse getApproval() {
public List<ApprovalInfoResponse> 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<Approval> approvalList = approvalRepository.findAllByUserAndAccepted(user, AcceptStatus.PROGRESS);

List<ApprovalInfoResponse> approvalInfoResponseList = approvalList.stream().map(approval -> {
Family family = approval.getFamily();
return new ApprovalInfoResponse(
approval.getId(),
family.getId(),
family.getName(),
family.getDescription()
);
}).toList();

return approvalInfoResponseList;
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String, String> 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) {
Expand Down

0 comments on commit b19b097

Please sign in to comment.