-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
75 deletions.
There are no files selected for viewing
151 changes: 86 additions & 65 deletions
151
src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,119 @@ | ||
package AIWA.MCPBackend_Member.Controller; | ||
|
||
import AIWA.MCPBackend_Member.Dto.AddAwsAndGcpKeyRequestDto; | ||
import AIWA.MCPBackend_Member.Dto.MemberDeleteRequestDto; | ||
import AIWA.MCPBackend_Member.Dto.MemberRequestDto; | ||
import AIWA.MCPBackend_Member.Dto.*; | ||
import AIWA.MCPBackend_Member.Entity.AiwaKey; | ||
import AIWA.MCPBackend_Member.Entity.Member; | ||
import AIWA.MCPBackend_Member.Service.member.MemberService; | ||
import AIWA.MCPBackend_Member.Service.response.ResponseService; | ||
import AIWA.MCPBackend_Member.response.CommonResult; | ||
import AIWA.MCPBackend_Member.response.ListResult; | ||
import AIWA.MCPBackend_Member.response.SingleResult; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequestMapping("/member/api/members") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/member/api/members") | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
private final ResponseService responseService; | ||
|
||
// 회원 등록 | ||
@PostMapping("/register") | ||
public ResponseEntity<String> registerMember(@RequestBody MemberRequestDto memberRequestDto) { | ||
try { | ||
memberService.registerMember(memberRequestDto); | ||
return ResponseEntity.ok("Member registered successfully"); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
public SingleResult<MemberResponseDto> registerMember(@RequestBody MemberRequestDto memberRequestDto) { | ||
// 회원 등록 | ||
Member savedMember = memberService.registerMember(memberRequestDto); | ||
MemberResponseDto memberResponseDto = MemberResponseDto.toDto(savedMember); | ||
return responseService.getSingleResult(memberResponseDto); | ||
} | ||
|
||
// 회원 삭제 | ||
@DeleteMapping("/delete") | ||
public ResponseEntity<String> deleteMember(@RequestBody MemberDeleteRequestDto deleteMemberRequestDto) { | ||
try { | ||
memberService.deleteMember(deleteMemberRequestDto); | ||
return ResponseEntity.ok("Member deleted successfully"); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
public CommonResult deleteMember(@RequestBody MemberDeleteRequestDto deleteMemberRequestDto) { | ||
// 회원 삭제 | ||
memberService.deleteMember(deleteMemberRequestDto); | ||
return responseService.getSuccessResult(); | ||
} | ||
|
||
// AWS 및 GCP 키 추가/수정 | ||
@PostMapping("/add-keys") | ||
public ResponseEntity<String> addOrUpdateAwsAndGcpKey(@RequestBody AddAwsAndGcpKeyRequestDto addAwsAndGcpKeyRequestDto) { | ||
try { | ||
String result = memberService.addOrUpdateAwsAndGcpKey( | ||
addAwsAndGcpKeyRequestDto.getEmail(), | ||
addAwsAndGcpKeyRequestDto.getCompanyName(), | ||
addAwsAndGcpKeyRequestDto.getAccessKey(), | ||
addAwsAndGcpKeyRequestDto.getSecretKey(), | ||
addAwsAndGcpKeyRequestDto.getGcpKeyContent() | ||
); | ||
return ResponseEntity.ok(result); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
// 모든 회원 조회 | ||
@GetMapping("/all") | ||
public ListResult<MemberResponseDto> getAllMembers() { | ||
// 모든 회원 조회 | ||
List<Member> members = memberService.getAllMembers(); | ||
List<MemberResponseDto> memberResponseDtoList = members.stream() | ||
.map(MemberResponseDto::toDto) | ||
.collect(Collectors.toList()); | ||
return responseService.getListResult(memberResponseDtoList); | ||
} | ||
|
||
// 회원 정보 조회 | ||
@GetMapping("/{email}") | ||
public ResponseEntity<Object> getMemberByEmail(@PathVariable String email) { | ||
try { | ||
return ResponseEntity.ok(memberService.getMemberByEmail(email)); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
// 특정 회원 조회 | ||
@GetMapping("/{email}/{companyName}") | ||
public SingleResult<MemberCredentialDto> getMemberKey( | ||
@PathVariable String email, | ||
@PathVariable String companyName) { | ||
|
||
Member findMember = memberService.getMemberByEmail(email); | ||
if (findMember == null) { | ||
return (SingleResult<MemberCredentialDto>) responseService.getFailResult("Member not found"); | ||
} | ||
} | ||
|
||
// 모든 회원 조회 | ||
@GetMapping("/all") | ||
public ResponseEntity<Object> getAllMembers() { | ||
try { | ||
return ResponseEntity.ok(memberService.getAllMembers()); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
Optional<AiwaKey> matchingKey = findMember.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); | ||
} else { | ||
return (SingleResult<MemberCredentialDto>) responseService.getFailResult("No key found for company: " + companyName); | ||
} | ||
} | ||
|
||
// AWS 및 GCP 키 추가/업데이트 | ||
@PostMapping("/add-aws-gcp-key") | ||
public SingleResult<String> addAwsAndGcpKey( | ||
@RequestParam String email, | ||
@RequestParam String companyName, | ||
@RequestParam String accessKey, | ||
@RequestParam String secretKey, | ||
@RequestParam String projectId, | ||
@RequestParam(required = false) MultipartFile gcpKeyFile) throws IOException { | ||
|
||
// GCP 자격 증명 파일을 포함하여 AWS 및 GCP 키 처리 | ||
String result = memberService.addOrUpdateAwsAndGcpKey( | ||
email, | ||
companyName, | ||
accessKey, | ||
secretKey, | ||
projectId, | ||
gcpKeyFile | ||
); | ||
return responseService.getSingleResult(result); | ||
} | ||
|
||
// AWS 키 삭제 | ||
@DeleteMapping("/remove/aws/{memberId}") | ||
public ResponseEntity<String> removeAwsKey(@PathVariable Long memberId) { | ||
try { | ||
memberService.removeAwsKey(memberId); | ||
return ResponseEntity.ok("AWS key removed successfully"); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
@DeleteMapping("/delete-aws-key") | ||
public CommonResult deleteAwsKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) { | ||
memberService.removeAwsKey(deleteKeyRequestDto.getMemberId()); | ||
return responseService.getSuccessResult(); | ||
} | ||
|
||
// GCP 키 삭제 | ||
@DeleteMapping("/remove/gcp/{memberId}") | ||
public ResponseEntity<String> removeGcpKey(@PathVariable Long memberId) { | ||
try { | ||
memberService.removeGcpKey(memberId); | ||
return ResponseEntity.ok("GCP key removed successfully"); | ||
} catch (RuntimeException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
@DeleteMapping("/delete-gcp-key") | ||
public CommonResult deleteGcpKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) { | ||
memberService.removeGcpKey(deleteKeyRequestDto.getMemberId()); | ||
return responseService.getSuccessResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters