Skip to content

Commit

Permalink
Merge pull request #17 from AWS-Cloud-School-6/16-feat-member-keyclass
Browse files Browse the repository at this point in the history
16 feat member keyclass
  • Loading branch information
gytjd authored Nov 13, 2024
2 parents f5fb47b + 83fdf8f commit c387ae3
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package AIWA.MCPBackend_Member.Controller;


import AIWA.MCPBackend_Member.Dto.*;
import AIWA.MCPBackend_Member.Entity.Member;
import AIWA.MCPBackend_Member.Service.member.MemberService;
Expand All @@ -18,12 +17,14 @@
@RequiredArgsConstructor
@RequestMapping("/member/api/members")
public class MemberController {

private final MemberService memberService;
private final ResponseService responseService;

// 회원 등록
@PostMapping("/register")
public SingleResult<MemberResponseDto> registerMember(@RequestBody MemberRequestDto memberRequestDto) {
// 회원 등록
Member savedMember = memberService.registerMember(memberRequestDto);
MemberResponseDto memberResponseDto = MemberResponseDto.toDto(savedMember);
return responseService.getSingleResult(memberResponseDto);
Expand All @@ -32,49 +33,62 @@ public SingleResult<MemberResponseDto> registerMember(@RequestBody MemberRequest
// 회원 삭제
@DeleteMapping("/delete")
public CommonResult deleteMember(@RequestBody MemberDeleteRequestDto deleteMemberRequestDto) {
// 회원 삭제 서비스 호출
// 회원 삭제
memberService.deleteMember(deleteMemberRequestDto);

// 성공 응답 반환 (ResponseService를 통해)
return responseService.getSuccessResult();
}

// 모든 회원 조회
@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") // PathVariable로 이메일을 전달
public SingleResult<MemberCredentialDTO> getMember(@RequestParam String email) {
Member findMember = memberService.getMemberByEmail(email); // Optional을 반환하지 않는다고 가정
// System.out.println(email);
// System.out.println(findMember.getAccess_key());
// System.out.println(findMember.getSecret_key());

if (findMember != null) {
// Member 정보를 MemberCredentialDTO로 변환
MemberCredentialDTO memberCredentialDTO = new MemberCredentialDTO(
findMember.getEmail(),
findMember.getAccess_key(),
findMember.getSecret_key()
);
System.out.println(memberCredentialDTO);
return responseService.getSingleResult(memberCredentialDTO);
} else {
return (SingleResult<MemberCredentialDTO>) responseService.getFailResult();
@GetMapping("/email")
public SingleResult<MemberResponseDto> getMemberByEmail(@RequestParam String email) {
// 특정 회원 조회
Member member = memberService.getMemberByEmail(email);
if (member == null) {
throw new RuntimeException("Member not found with Email: " + email); // 예외 처리
}
MemberResponseDto memberResponseDto = MemberResponseDto.toDto(member);
return responseService.getSingleResult(memberResponseDto);
}

@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);



// AWS 키 추가/업데이트
@PostMapping("/add-aws-gcp-key")
public SingleResult<String> addAwsAndGcpKey(@RequestBody AddAwsAndGcpKeyRequestDto requestDto) {
String result = memberService.addOrUpdateAwsAndGcpKey(
requestDto.getEmail(),
requestDto.getAccessKey(),
requestDto.getSecretKey(),
requestDto.getGcpKeyContent()
);
return responseService.getSingleResult(result);
}

@PostMapping("/update-credentials")
public CommonResult updateCredentials(@RequestBody MemberCredentialDTO memberCredentialDTO) {
System.out.println(memberCredentialDTO.getAccessKey());
System.out.println(memberCredentialDTO.getSecretKey());
memberService.addOrUpdateKeys(memberCredentialDTO.getEmail(),memberCredentialDTO.getAccessKey(), memberCredentialDTO.getSecretKey());
// AWS 키 삭제
@DeleteMapping("/delete-aws-key")
public CommonResult deleteAwsKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) {
// AWS 키 삭제
memberService.removeAwsKey(deleteKeyRequestDto.getMemberId());
return responseService.getSuccessResult();
}

// GCP 키 삭제
@DeleteMapping("/delete-gcp-key")
public CommonResult deleteGcpKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) {
// GCP 키 삭제
memberService.removeGcpKey(deleteKeyRequestDto.getMemberId());
return responseService.getSuccessResult();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package AIWA.MCPBackend_Member.Dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AddAwsAndGcpKeyRequestDto {
private String email;
private String accessKey;
private String secretKey;
private String gcpKeyContent;
}
25 changes: 25 additions & 0 deletions src/main/java/AIWA/MCPBackend_Member/Dto/AiwaKeyResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package AIWA.MCPBackend_Member.Dto;

import AIWA.MCPBackend_Member.Entity.AiwaKey;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AiwaKeyResponseDto {

private String companyName; // 회사 이름 (AWS, GCP 등)
private String accessKey; // Access Key (AWS의 경우만 있을 수 있음)
private String secretKey; // Secret Key (AWS의 경우만 있을 수 있음)
private String gcpKeyPath; // GCP Key Path (GCP의 경우만 있을 수 있음)

// Entity -> DTO 변환 메서드
public static AiwaKeyResponseDto toDto(AiwaKey aiwaKey) {
AiwaKeyResponseDto dto = new AiwaKeyResponseDto();
dto.setCompanyName(aiwaKey.getCompanyName());
dto.setAccessKey(aiwaKey.getAccessKey());
dto.setSecretKey(aiwaKey.getSecretKey());
dto.setGcpKeyPath(aiwaKey.getGcpKeyPath());
return dto;
}
}
18 changes: 0 additions & 18 deletions src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/java/AIWA/MCPBackend_Member/Dto/DeleteKeyRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package AIWA.MCPBackend_Member.Dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class DeleteKeyRequestDto {
private Long memberId;
private String companyName; // AWS 또는 GCP
}
19 changes: 0 additions & 19 deletions src/main/java/AIWA/MCPBackend_Member/Dto/MemberCredentialDTO.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package AIWA.MCPBackend_Member.Dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@NoArgsConstructor // 기본 생성자 추가
@Setter
public class MemberDeleteRequestDto {
private String email; // final 제거

public MemberDeleteRequestDto(String email) {
this.email = email;
}
}
private String email;
}
14 changes: 5 additions & 9 deletions src/main/java/AIWA/MCPBackend_Member/Dto/MemberRequestDto.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package AIWA.MCPBackend_Member.Dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MemberRequestDto {
private final String name;
private final String password;
private final String email;

public MemberRequestDto(String name, String password, String email) {
this.name = name;
this.password = password;
this.email = email;
}
private String name;
private String email;
private String password;
}
46 changes: 32 additions & 14 deletions src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package AIWA.MCPBackend_Member.Dto;


import AIWA.MCPBackend_Member.Entity.Member;
import lombok.Data;
import AIWA.MCPBackend_Member.Entity.AiwaKey;
import lombok.Getter;
import lombok.Setter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Getter
@Setter
public class MemberResponseDto {
private String userName;
private String email;
private String accessKey;

public MemberResponseDto(String userName, String email, String accessKey) {
this.userName = userName;
this.email = email;
this.accessKey = accessKey;
}

private Long id; // 회원 ID
private String name; // 회원 이름
private String email; // 회원 이메일

@JsonIgnore // 비밀번호는 반환하지 않음
private String password; // 회원 비밀번호

private List<AiwaKeyResponseDto> aiwaKeys; // 회원이 관리하는 회사들의 키 정보 리스트

// Entity -> DTO 변환 메서드
public static MemberResponseDto toDto(Member member) {
return new MemberResponseDto(member.getName(), member.getEmail(), member.getAccess_key());
MemberResponseDto memberResponseDto = new MemberResponseDto();
memberResponseDto.setId(member.getId());
memberResponseDto.setName(member.getName());
memberResponseDto.setEmail(member.getEmail());
memberResponseDto.setPassword(member.getPassword()); // 비밀번호는 필요 없다면 제외 가능

// AiwaKey 리스트를 AiwaKeyResponseDto 리스트로 변환
List<AiwaKeyResponseDto> aiwaKeyResponseDtoList = member.getAiwaKeys().stream()
.map(AiwaKeyResponseDto::toDto)
.collect(Collectors.toList());
memberResponseDto.setAiwaKeys(aiwaKeyResponseDtoList);

return memberResponseDto;
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package AIWA.MCPBackend_Member.Entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class AiwaKey {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "aiwa_key_id")
private Long id;

@Column(nullable = false)
private String companyName;

private String accessKey;
private String secretKey;
private String gcpKeyPath;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

public AiwaKey(String companyName, String accessKey, String secretKey, String gcpKeyPath, Member member) {
this.companyName = companyName;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.gcpKeyPath = gcpKeyPath;
this.member = member;
}
}
12 changes: 6 additions & 6 deletions src/main/java/AIWA/MCPBackend_Member/Entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;


@Entity
@Getter
Expand All @@ -27,15 +30,12 @@ public class Member {
@Column(unique = true, nullable = false)
private String email;

@Column(length = 1000)
private String access_key;
@Column(length = 1000)
private String secret_key;
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AiwaKey> aiwaKeys = new ArrayList<>();

public Member(String name, String password, String email) {
this.name = name;
this.password = password;
this.email = email;
}

}
}
Loading

0 comments on commit c387ae3

Please sign in to comment.