From 2de7fd850b479b4f42e1e3c68d5db4e7cb3ab89d Mon Sep 17 00:00:00 2001 From: gytjd Date: Mon, 25 Nov 2024 17:38:14 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20Member=20=EB=8B=A8=EC=9D=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MemberController.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java index 8d8a769..ca38260 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java +++ b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java @@ -53,34 +53,42 @@ public ListResult getAllMembers() { return responseService.getListResult(memberResponseDtoList); } - // 특정 회원 조회 @GetMapping("/{email}/{companyName}") - public SingleResult getMemberKey( + public SingleResult getMemberAndKeyByEmailAndCompany( @PathVariable String email, @PathVariable String companyName) { - Member findMember = memberService.getMemberByEmail(email); - if (findMember == null) { - return (SingleResult) responseService.getFailResult("Member not found"); + // 서비스에서 멤버 조회 + Member member = memberService.getMemberByEmail(email); + + if (member == null) { + throw new IllegalArgumentException("Member not found"); } - Optional matchingKey = findMember.getAiwaKeys().stream() + // AiwaKey 조회 + Optional optionalKey = member.getAiwaKeys().stream() .filter(key -> companyName.equalsIgnoreCase(key.getCompanyName())) .findFirst(); - if (matchingKey.isPresent()) { - AiwaKey aiwaKey = matchingKey.get(); - MemberCredentialDto memberCredentialDto = new MemberCredentialDto( - findMember.getEmail(), - aiwaKey.getAccessKey(), - aiwaKey.getSecretKey() - ); - return responseService.getSingleResult(memberCredentialDto); + if (optionalKey.isPresent()) { + AiwaKey aiwaKey = optionalKey.get(); + + // MemberResponseDto 생성 + MemberResponseDto memberResponseDto = MemberResponseDto.toDto(member); + + // AiwaKeyResponseDto 추가 (해당 회사 키만 추가) + List filteredKeys = List.of(AiwaKeyResponseDto.toDto(aiwaKey)); + memberResponseDto.setAiwaKeys(filteredKeys); + + return responseService.getSingleResult(memberResponseDto); } else { - return (SingleResult) responseService.getFailResult("No key found for company: " + companyName); + throw new IllegalArgumentException("Key for company '" + companyName + "' not found"); } } + + + // AWS 및 GCP 키 추가/업데이트 @PostMapping("/add-aws-gcp-key") public SingleResult addAwsAndGcpKey(