From 9fca6756c579e6bdc51aec6c737cb3b44d59ef57 Mon Sep 17 00:00:00 2001 From: Kim-DongHyuk <80240164+Kdonghs@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:16:18 +0900 Subject: [PATCH 01/12] =?UTF-8?q?fix:=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/team1/BE/seamless/service/AttendURLService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team1/BE/seamless/service/AttendURLService.java b/src/main/java/team1/BE/seamless/service/AttendURLService.java index bc96f20..2e9eacc 100644 --- a/src/main/java/team1/BE/seamless/service/AttendURLService.java +++ b/src/main/java/team1/BE/seamless/service/AttendURLService.java @@ -30,7 +30,7 @@ public AttendURLService(ProjectRepository projectRepository, ParsingPram parsing } public String generateAttendURL(HttpServletRequest req, @Valid Long projectId) { - ProjectEntity project = projectRepository.findByIdAndUserEntityEmail(projectId, + ProjectEntity project = projectRepository.findByIdAndUserEntityEmailAndIsDeletedFalse(projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "프로젝트가 존재하지 않음")); From 7b5a10b6f0133924f0c367690b6c2b541b577081 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Tue, 8 Oct 2024 12:48:00 +0900 Subject: [PATCH 02/12] test --- .../BE/seamless/service/MemberService.java | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index e46727f..9f2806c 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -34,13 +34,6 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe } public MemberEntity getMember(Long projectId, Long memberId) { -// Optional memberEntity = memberRepository.findById(memberId); -// if (memberEntity.isPresent()) { -// return memberEntity.get(); -// } -// else { -// throw new BaseHandler(HttpStatus.NOT_FOUND, "프로젝트가 존재하지 않음"); -// } return memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); } @@ -52,18 +45,6 @@ public Page getMemberList(@Valid Long projectId, } public MemberEntity createMember(Long projectId, CreateMember create) { -// Optional projectEntity = projectRepository.findById(projectId); -// if(projectEntity.isPresent()) { -// MemberEntity memberEntity = memberMapper.toMemberEntity(memberRequestDTO); -// memberEntity.setProject(projectEntity.get()); // 코드 구조상 어쩔 수 없이 setter 사용..(get메서드가 Optional기능이라 이렇게 함) -// memberRepository.save(memberEntity); -// // memberRepository.save(memberEntity) 리턴값은 MemberEntity임 JPA 기능임! -// MemberResponseDTO memberResponseDTO = new MemberResponseDTO("팀원이 추가되었습니다."); -// return memberResponseDTO; -// } -// else { -// throw new BaseHandler(HttpStatus.NOT_FOUND, "해당하는 프로젝트가 존재하지 않습니다."); -// } ProjectEntity project = projectRepository.findById(projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); @@ -75,16 +56,6 @@ public MemberEntity createMember(Long projectId, CreateMember create) { @Transactional public MemberEntity updateMember(Long projectId, Long memberId, UpdateMember update) { -// Optional existingMemberEntity = memberRepository.findById(memberId); -// if(existingMemberEntity.isPresent()) { -// MemberEntity updatedMember = memberMapper.toMemberUpdateEntity(memberRequestDTO,existingMemberEntity); -// memberRepository.save(updatedMember); -// MemberResponseDTO memberResponseDTO = new MemberResponseDTO("팀원 정보가 성공적으로 변경되었습니다."); -// return memberResponseDTO; -// } -// else { -// throw new BaseHandler(HttpStatus.NOT_FOUND,"해당하는 팀원이 존재하지 않습니다."); -// } MemberEntity member = memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); @@ -95,15 +66,6 @@ public MemberEntity updateMember(Long projectId, Long memberId, UpdateMember upd @Transactional public MemberEntity deleteMember(Long projectId, Long memberId) { -// Optional existingMemberEntity = memberRepository.findById(memberId); -// if(existingMemberEntity.isPresent()) { -// String name = existingMemberEntity.get().getName(); -// memberRepository.delete(existingMemberEntity.get()); -// return new MemberResponseDTO("팀원 (" + name + ")이 팀에서 삭제되었습니다."); -// } -// else { -// throw new BaseHandler(HttpStatus.NOT_FOUND,"해당하는 팀원이 존재하지 않습니다."); -// } MemberEntity member = memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); From 954ecba3d79b014634d7a03b3c16413f01819229 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Tue, 8 Oct 2024 12:49:17 +0900 Subject: [PATCH 03/12] test --- src/main/java/team1/BE/seamless/service/MemberService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 9f2806c..9564516 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -33,6 +33,7 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe this.projectRepository = projectRepository; } + public MemberEntity getMember(Long projectId, Long memberId) { return memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); From 1f2a987a352cb0a864913ab45811287ae3149b27 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Tue, 8 Oct 2024 12:49:47 +0900 Subject: [PATCH 04/12] test --- src/main/java/team1/BE/seamless/service/MemberService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 9564516..9f2806c 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -33,7 +33,6 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe this.projectRepository = projectRepository; } - public MemberEntity getMember(Long projectId, Long memberId) { return memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); From 8c4006ea6bdf6c92d007cbbee48f29ef1b7db88e Mon Sep 17 00:00:00 2001 From: suno-boy Date: Tue, 8 Oct 2024 20:18:12 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20Member=20CRUD=20=EA=B0=95?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PathVariable로 memberId 받아 쓰던 것을 헤더의 jwt토큰에서 email을 뽑아 쓰는 것으로 대체하도록 수정 - 멤버 CRUD에 팀장 or 팀원들만 접근할 수 있게 서비스 계층에서 jwt토큰에서 뽑아 권한 검증 로직 추가. --- .../seamless/controller/MemberController.java | 27 +++++----- .../seamless/repository/MemberRepository.java | 3 ++ .../BE/seamless/service/MemberService.java | 54 ++++++++++++++----- 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/main/java/team1/BE/seamless/controller/MemberController.java b/src/main/java/team1/BE/seamless/controller/MemberController.java index 1cdf351..2990b5e 100644 --- a/src/main/java/team1/BE/seamless/controller/MemberController.java +++ b/src/main/java/team1/BE/seamless/controller/MemberController.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; @@ -35,16 +36,17 @@ public class MemberController { @Operation(summary = "팀원 개별 조회") @GetMapping("/{member_id}") public SingleResult getMember(@Valid @PathVariable("project_id") Long projectId, - @Valid @PathVariable("member_id") Long memberId) { - return new SingleResult<>(memberService.getMember(projectId, memberId)); + HttpServletRequest req) { + return new SingleResult<>(memberService.getMember(projectId, req)); } @Operation(summary = "팀원 전체 조회") @GetMapping public PageResult getMemberList(@Valid @PathVariable("project_id") Long projectId, - @Valid MemberRequestDTO.getMemberList memberListRequestDTO) { + @Valid MemberRequestDTO.getMemberList memberListRequestDTO, + HttpServletRequest req) { return PageMapper.toPageResult( - memberService.getMemberList(projectId, memberListRequestDTO)); + memberService.getMemberList(projectId, memberListRequestDTO, req)); } @@ -52,25 +54,26 @@ public PageResult getMemberList(@Valid @PathVariable("project_id") @PostMapping public SingleResult createMember( @PathVariable("project_id") Long projectId, - @Valid @RequestBody MemberRequestDTO.CreateMember Create) { - return new SingleResult<>(memberService.createMember(projectId, Create)); + @Valid @RequestBody MemberRequestDTO.CreateMember Create, + HttpServletRequest req) { + return new SingleResult<>(memberService.createMember(projectId, Create, req)); } @Operation(summary = "팀원 정보 수정") @PutMapping("/{member_id}") public SingleResult updateMember( - @PathVariable("project_id") Long projectId, - @PathVariable("member_id") Long memberId - , @RequestBody MemberRequestDTO.UpdateMember update) { - return new SingleResult<>(memberService.updateMember(projectId, memberId, update)); + @PathVariable("project_id") Long projectId + , @RequestBody MemberRequestDTO.UpdateMember update, + HttpServletRequest req) { + return new SingleResult<>(memberService.updateMember(projectId, update, req)); } @Operation(summary = "팀원 삭제") @DeleteMapping("/{member_id}") public SingleResult deleteMember( @PathVariable("project_id") Long projectId, - @PathVariable("member_id") Long memberId) { + HttpServletRequest req) { - return new SingleResult<>(memberService.deleteMember(projectId, memberId)); + return new SingleResult<>(memberService.deleteMember(projectId, req)); } } diff --git a/src/main/java/team1/BE/seamless/repository/MemberRepository.java b/src/main/java/team1/BE/seamless/repository/MemberRepository.java index d0c86a7..6ce31a8 100644 --- a/src/main/java/team1/BE/seamless/repository/MemberRepository.java +++ b/src/main/java/team1/BE/seamless/repository/MemberRepository.java @@ -14,4 +14,7 @@ public interface MemberRepository extends JpaRepository { Optional findByIdAndProjectEntityIdAndIsDeleteFalse(Long id, Long projectId); Page findAllByProjectEntityIdAndIsDeleteFalse(Long projectId, Pageable pageable); + + Optional findByProjectEntityIdAndEmailAndIsDeleteFalse(Long projectId, String email); + } diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 9f2806c..0064ca2 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -1,5 +1,6 @@ package team1.BE.seamless.service; +import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -11,40 +12,57 @@ import team1.BE.seamless.DTO.MemberRequestDTO.getMemberList; import team1.BE.seamless.entity.MemberEntity; import team1.BE.seamless.entity.ProjectEntity; +import team1.BE.seamless.entity.enums.Role; import team1.BE.seamless.mapper.MemberMapper; import team1.BE.seamless.repository.MemberRepository; import team1.BE.seamless.repository.ProjectRepository; +import team1.BE.seamless.util.auth.ParsingPram; import team1.BE.seamless.util.errorException.BaseHandler; @Service public class MemberService { private final MemberRepository memberRepository; - private final MemberMapper memberMapper; - private final ProjectRepository projectRepository; + private final ParsingPram parsingPram; @Autowired public MemberService(MemberRepository memberRepository, MemberMapper memberMapper, - ProjectRepository projectRepository) { + ProjectRepository projectRepository, ParsingPram parsingPram) { this.memberRepository = memberRepository; this.memberMapper = memberMapper; this.projectRepository = projectRepository; + this.parsingPram = parsingPram; } - public MemberEntity getMember(Long projectId, Long memberId) { - return memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, projectId) + public MemberEntity getMember(Long projectId, HttpServletRequest req) { + // 팀원인지 확인 + if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"조회 권한이 없습니다."); + } + + return memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse(projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); } public Page getMemberList(@Valid Long projectId, - getMemberList memberListRequestDTO) { + getMemberList memberListRequestDTO, HttpServletRequest req) { + // 팀원인지 확인 + if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"조회 권한이 없습니다."); + } + return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId, memberListRequestDTO.toPageable()); } - public MemberEntity createMember(Long projectId, CreateMember create) { + public MemberEntity createMember(Long projectId, CreateMember create, HttpServletRequest req) { + // 팀원인지 확인 + if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"등록 권한이 없습니다."); + } + ProjectEntity project = projectRepository.findById(projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); @@ -55,9 +73,14 @@ public MemberEntity createMember(Long projectId, CreateMember create) { } @Transactional - public MemberEntity updateMember(Long projectId, Long memberId, UpdateMember update) { - MemberEntity member = memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, - projectId) + public MemberEntity updateMember(Long projectId, UpdateMember update, HttpServletRequest req) { + // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) + if (parsingPram.getRole(req).equals(Role.USER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); + } + + MemberEntity member = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse( + projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); memberMapper.toUpdate(member, update); @@ -65,9 +88,14 @@ public MemberEntity updateMember(Long projectId, Long memberId, UpdateMember upd } @Transactional - public MemberEntity deleteMember(Long projectId, Long memberId) { - MemberEntity member = memberRepository.findByIdAndProjectEntityIdAndIsDeleteFalse(memberId, - projectId) + public MemberEntity deleteMember(Long projectId, HttpServletRequest req) { + // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) + if (parsingPram.getRole(req).equals(Role.USER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); + } + + MemberEntity member = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse( + projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); member.setDelete(true); From 5055e7fe3095ab7cf156899ae32a409966791d00 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Wed, 9 Oct 2024 10:41:47 +0900 Subject: [PATCH 06/12] =?UTF-8?q?refactor:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team1/BE/seamless/repository/MemberRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/team1/BE/seamless/repository/MemberRepository.java b/src/main/java/team1/BE/seamless/repository/MemberRepository.java index 6ce31a8..0b288c9 100644 --- a/src/main/java/team1/BE/seamless/repository/MemberRepository.java +++ b/src/main/java/team1/BE/seamless/repository/MemberRepository.java @@ -11,8 +11,6 @@ @Repository public interface MemberRepository extends JpaRepository { - Optional findByIdAndProjectEntityIdAndIsDeleteFalse(Long id, Long projectId); - Page findAllByProjectEntityIdAndIsDeleteFalse(Long projectId, Pageable pageable); Optional findByProjectEntityIdAndEmailAndIsDeleteFalse(Long projectId, String email); From 1d2a73740079e25bdab3dacc22e05570f08956fb Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 15:53:28 +0900 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20=EC=B4=88=EA=B8=B0=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=84=A3=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team1/BE/seamless/init/InitData.java | 5 +++- .../team1/BE/seamless/init/MemberCreator.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/team1/BE/seamless/init/MemberCreator.java diff --git a/src/main/java/team1/BE/seamless/init/InitData.java b/src/main/java/team1/BE/seamless/init/InitData.java index 3ac6d89..81ae9bf 100644 --- a/src/main/java/team1/BE/seamless/init/InitData.java +++ b/src/main/java/team1/BE/seamless/init/InitData.java @@ -13,14 +13,16 @@ public class InitData { private final ProjectCreator projectCreator; private final UserCreator userCreator; private final OptionCreator optionCreator; + private final MemberCreator memberCreator; @Autowired public InitData(TestCreator testCreator, ProjectCreator projectCreator, UserCreator userCreator, - OptionCreator optionCreator) { + OptionCreator optionCreator, MemberCreator memberCreator) { this.testCreator = testCreator; this.projectCreator = projectCreator; this.userCreator = userCreator; this.optionCreator = optionCreator; + this.memberCreator = memberCreator; } @PostConstruct @@ -30,5 +32,6 @@ public void init() { userCreator.creator(); optionCreator.creator(); projectCreator.creator(); + memberCreator.creator(); } } diff --git a/src/main/java/team1/BE/seamless/init/MemberCreator.java b/src/main/java/team1/BE/seamless/init/MemberCreator.java new file mode 100644 index 0000000..07da476 --- /dev/null +++ b/src/main/java/team1/BE/seamless/init/MemberCreator.java @@ -0,0 +1,30 @@ +package team1.BE.seamless.init; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import team1.BE.seamless.DTO.MemberRequestDTO; +import team1.BE.seamless.service.MemberService; + +@Component +public class MemberCreator { + + private final MemberService memberService; + + @Autowired + public MemberCreator(MemberService memberService) { + this.memberService = memberService; + } + + public void creator() { + // 테스트용으로 request데이터 생성 + MemberRequestDTO.CreateMember member1 = new MemberRequestDTO.CreateMember("권순호","MEMBER","ex1@gmail.com","exURL1"); + memberService.createMember(1L, member1); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦 + + MemberRequestDTO.CreateMember member2 = new MemberRequestDTO.CreateMember("김동혁","USER","ex2@gmail.com","exURL2"); + memberService.createMember(1L, member2); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦 + + MemberRequestDTO.CreateMember member3 = new MemberRequestDTO.CreateMember("김도헌","MEMBER","ex3@gmail.com","exURL3"); + memberService.createMember(1L, member3); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦 + } + +} From 67678f1b6122900d04b2cbf507aa163120ffbb3e Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 15:54:32 +0900 Subject: [PATCH 08/12] =?UTF-8?q?refactor:=20=EB=B9=8C=EB=93=9C=EB=A5=BC?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20=EC=9D=B4=EC=8A=88=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=ED=8C=80=EC=9E=A5=EB=8B=98=EC=9D=B4=20=EB=A7=90=ED=95=9C=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 일단 빌드 되도록 수정해놓고 PR넣으라고 해서 이렇게 commit함 --- src/main/java/team1/BE/seamless/entity/ProjectEntity.java | 2 +- src/main/java/team1/BE/seamless/repository/UserRepository.java | 2 +- src/main/java/team1/BE/seamless/service/UserService.java | 2 +- src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/team1/BE/seamless/entity/ProjectEntity.java b/src/main/java/team1/BE/seamless/entity/ProjectEntity.java index 9480ac6..c9a9afc 100644 --- a/src/main/java/team1/BE/seamless/entity/ProjectEntity.java +++ b/src/main/java/team1/BE/seamless/entity/ProjectEntity.java @@ -47,7 +47,7 @@ public ProjectEntity(String name, UserEntity userEntity, List pro @Column(name = "is_deleted") private boolean isDeleted; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "user_id") private UserEntity userEntity; diff --git a/src/main/java/team1/BE/seamless/repository/UserRepository.java b/src/main/java/team1/BE/seamless/repository/UserRepository.java index 6505b88..a2e929e 100644 --- a/src/main/java/team1/BE/seamless/repository/UserRepository.java +++ b/src/main/java/team1/BE/seamless/repository/UserRepository.java @@ -11,5 +11,5 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); Optional findByEmailAndIsDeleteFalse(String email); - Optional findByEmailAndIsDeleteFalse(String email, Integer isDelete); +// Optional findByEmailAndIsDeleteFalse(String email, Integer isDelete); } diff --git a/src/main/java/team1/BE/seamless/service/UserService.java b/src/main/java/team1/BE/seamless/service/UserService.java index 04679c9..791b69e 100644 --- a/src/main/java/team1/BE/seamless/service/UserService.java +++ b/src/main/java/team1/BE/seamless/service/UserService.java @@ -48,7 +48,7 @@ public UserSimple updateUser(HttpServletRequest req, @Valid UserUpdate update) { @Transactional public UserSimple deleteUser(HttpServletRequest req) { - UserEntity user = userRepository.findByEmailAndIsDeleteFalse(parsingPram.getEmail(req), 0) + UserEntity user = userRepository.findByEmailAndIsDeleteFalse(parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 유저가 존재하지 않습니다.")); user.setIsDelete(); diff --git a/src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java b/src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java index fabd190..479e04a 100644 --- a/src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java +++ b/src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java @@ -59,7 +59,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti "/**/*.svg", "/**/*.jpg", "/**/*.html", "/**/*.css", "/**/*.js") .permitAll() // 인증, h2 - .requestMatchers("/h2-console/**").permitAll() + .requestMatchers("/h2-console/","/auth/**").permitAll() .anyRequest() .authenticated() ) From 594db0d45cbafed9c0c436804b94dd83635750f2 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 15:56:16 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 역할 인증 때문에 memberId받지않고 HttpServletRequest를 받아서 구현했는데, 이렇게 하니까 정상적인 테스트 안됨. - 반환 타입 Entity로 두니까 테스트할 때 불편해서 임의로 ResponseDTO 씌워놓음 --- .../BE/seamless/DTO/MemberResponseDTO.java | 12 ++++++- .../seamless/controller/MemberController.java | 14 +++++--- .../BE/seamless/mapper/MemberMapper.java | 8 +++++ .../BE/seamless/service/MemberService.java | 33 ++++++++++++++----- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java b/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java index 2bb798a..3a63933 100644 --- a/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java +++ b/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java @@ -4,8 +4,18 @@ public class MemberResponseDTO { private String message; - public MemberResponseDTO(String message) { + private String name; + + private String role; + + private String email; + + + public MemberResponseDTO(String message, String name, String role, String email) { this.message = message; + this.name = name; + this.role = role; + this.email = email; } public String getMessage() { diff --git a/src/main/java/team1/BE/seamless/controller/MemberController.java b/src/main/java/team1/BE/seamless/controller/MemberController.java index 2990b5e..4cfefc6 100644 --- a/src/main/java/team1/BE/seamless/controller/MemberController.java +++ b/src/main/java/team1/BE/seamless/controller/MemberController.java @@ -14,12 +14,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import team1.BE.seamless.DTO.MemberRequestDTO; +import team1.BE.seamless.DTO.MemberResponseDTO; import team1.BE.seamless.entity.MemberEntity; import team1.BE.seamless.service.MemberService; import team1.BE.seamless.util.page.PageMapper; import team1.BE.seamless.util.page.PageResult; import team1.BE.seamless.util.page.SingleResult; +import java.lang.reflect.Member; + @Tag(name = "팀원 관리") @RequestMapping("/api/project/{project_id}/member") @@ -35,8 +38,9 @@ public class MemberController { @Operation(summary = "팀원 개별 조회") @GetMapping("/{member_id}") - public SingleResult getMember(@Valid @PathVariable("project_id") Long projectId, - HttpServletRequest req) { + public SingleResult getMember(@Valid @PathVariable("project_id") Long projectId, + @Valid @PathVariable("") + HttpServletRequest req) { return new SingleResult<>(memberService.getMember(projectId, req)); } @@ -52,7 +56,7 @@ public PageResult getMemberList(@Valid @PathVariable("project_id") @Operation(summary = "새 팀원 추가") @PostMapping - public SingleResult createMember( + public SingleResult createMember( @PathVariable("project_id") Long projectId, @Valid @RequestBody MemberRequestDTO.CreateMember Create, HttpServletRequest req) { @@ -61,7 +65,7 @@ public SingleResult createMember( @Operation(summary = "팀원 정보 수정") @PutMapping("/{member_id}") - public SingleResult updateMember( + public SingleResult updateMember( @PathVariable("project_id") Long projectId , @RequestBody MemberRequestDTO.UpdateMember update, HttpServletRequest req) { @@ -70,7 +74,7 @@ public SingleResult updateMember( @Operation(summary = "팀원 삭제") @DeleteMapping("/{member_id}") - public SingleResult deleteMember( + public SingleResult deleteMember( @PathVariable("project_id") Long projectId, HttpServletRequest req) { diff --git a/src/main/java/team1/BE/seamless/mapper/MemberMapper.java b/src/main/java/team1/BE/seamless/mapper/MemberMapper.java index bd927ce..b697d4a 100644 --- a/src/main/java/team1/BE/seamless/mapper/MemberMapper.java +++ b/src/main/java/team1/BE/seamless/mapper/MemberMapper.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Component; import team1.BE.seamless.DTO.MemberRequestDTO.CreateMember; import team1.BE.seamless.DTO.MemberRequestDTO.UpdateMember; +import team1.BE.seamless.DTO.MemberResponseDTO; import team1.BE.seamless.entity.MemberEntity; import team1.BE.seamless.entity.ProjectEntity; @@ -28,4 +29,11 @@ public MemberEntity toUpdate(MemberEntity member, UpdateMember update) { return member; } + public MemberResponseDTO toResponseDTO(MemberEntity memberEntity) { + return new MemberResponseDTO("성공적으로 조회되었습니다.", + memberEntity.getName(), + memberEntity.getRole(), + memberEntity.getEmail()); + } + } diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 0064ca2..6879693 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -10,6 +10,7 @@ import team1.BE.seamless.DTO.MemberRequestDTO.CreateMember; import team1.BE.seamless.DTO.MemberRequestDTO.UpdateMember; import team1.BE.seamless.DTO.MemberRequestDTO.getMemberList; +import team1.BE.seamless.DTO.MemberResponseDTO; import team1.BE.seamless.entity.MemberEntity; import team1.BE.seamless.entity.ProjectEntity; import team1.BE.seamless.entity.enums.Role; @@ -36,14 +37,16 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe this.parsingPram = parsingPram; } - public MemberEntity getMember(Long projectId, HttpServletRequest req) { + public MemberResponseDTO getMember(Long projectId, HttpServletRequest req) { // 팀원인지 확인 if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"조회 권한이 없습니다."); } - return memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse(projectId, parsingPram.getEmail(req)) + MemberEntity memberEntity = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse(projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); + + return memberMapper.toResponseDTO(memberEntity); } public Page getMemberList(@Valid Long projectId, @@ -57,7 +60,7 @@ public Page getMemberList(@Valid Long projectId, memberListRequestDTO.toPageable()); } - public MemberEntity createMember(Long projectId, CreateMember create, HttpServletRequest req) { + public MemberResponseDTO createMember(Long projectId, CreateMember create, HttpServletRequest req) { // 팀원인지 확인 if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"등록 권한이 없습니다."); @@ -69,11 +72,23 @@ public MemberEntity createMember(Long projectId, CreateMember create, HttpServle MemberEntity member = memberMapper.toEntity(create, project); memberRepository.save(member); - return member; + return memberMapper.toResponseDTO(member); + } + + public MemberResponseDTO createMember(Long projectId, CreateMember create) { + // 테스트용 오버로딩임. 삭제 금지 + + ProjectEntity project = projectRepository.findById(projectId) + .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); + + MemberEntity member = memberMapper.toEntity(create, project); + memberRepository.save(member); + + return memberMapper.toResponseDTO(member); } @Transactional - public MemberEntity updateMember(Long projectId, UpdateMember update, HttpServletRequest req) { + public MemberResponseDTO updateMember(Long projectId, UpdateMember update, HttpServletRequest req) { // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); @@ -83,12 +98,12 @@ public MemberEntity updateMember(Long projectId, UpdateMember update, HttpServle projectId, parsingPram.getEmail(req)) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); - memberMapper.toUpdate(member, update); - return member; + MemberEntity memberEntity = memberMapper.toUpdate(member, update); + return memberMapper.toResponseDTO(memberEntity); } @Transactional - public MemberEntity deleteMember(Long projectId, HttpServletRequest req) { + public MemberResponseDTO deleteMember(Long projectId, HttpServletRequest req) { // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); @@ -100,6 +115,6 @@ public MemberEntity deleteMember(Long projectId, HttpServletRequest req) { member.setDelete(true); - return member; + return memberMapper.toResponseDTO(member); } } From 6a94f1f8b8e670b37ac39402feae43ff1869f519 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 16:50:14 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 토큰 없는 init데이터라서, 토큰으로부터 email뽑는 테스트가 안됨. 그래서 memberId로 CRUD하도록 다시 수정함 -> 추후에 팀장님이 테스트 토큰 완성하시면 다시 또 수정해놓을 예정 --- .../BE/seamless/DTO/MemberResponseDTO.java | 25 ++++++++++- .../seamless/controller/MemberController.java | 12 +++--- .../BE/seamless/mapper/MemberMapper.java | 23 ++++++++++- .../seamless/repository/MemberRepository.java | 2 + .../BE/seamless/service/MemberService.java | 41 ++++++++----------- 5 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java b/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java index 3a63933..4268dd1 100644 --- a/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java +++ b/src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java @@ -10,7 +10,6 @@ public class MemberResponseDTO { private String email; - public MemberResponseDTO(String message, String name, String role, String email) { this.message = message; this.name = name; @@ -18,6 +17,30 @@ public MemberResponseDTO(String message, String name, String role, String email) this.email = email; } + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + public String getMessage() { return message; } diff --git a/src/main/java/team1/BE/seamless/controller/MemberController.java b/src/main/java/team1/BE/seamless/controller/MemberController.java index 4cfefc6..a0099ab 100644 --- a/src/main/java/team1/BE/seamless/controller/MemberController.java +++ b/src/main/java/team1/BE/seamless/controller/MemberController.java @@ -39,9 +39,9 @@ public class MemberController { @Operation(summary = "팀원 개별 조회") @GetMapping("/{member_id}") public SingleResult getMember(@Valid @PathVariable("project_id") Long projectId, - @Valid @PathVariable("") + @Valid @PathVariable("member_id") Long memberId, HttpServletRequest req) { - return new SingleResult<>(memberService.getMember(projectId, req)); + return new SingleResult<>(memberService.getMember(projectId, memberId, req)); } @Operation(summary = "팀원 전체 조회") @@ -66,18 +66,20 @@ public SingleResult createMember( @Operation(summary = "팀원 정보 수정") @PutMapping("/{member_id}") public SingleResult updateMember( - @PathVariable("project_id") Long projectId + @PathVariable("project_id") Long projectId, + @PathVariable("member_id") Long memberId , @RequestBody MemberRequestDTO.UpdateMember update, HttpServletRequest req) { - return new SingleResult<>(memberService.updateMember(projectId, update, req)); + return new SingleResult<>(memberService.updateMember(projectId, memberId, update, req)); } @Operation(summary = "팀원 삭제") @DeleteMapping("/{member_id}") public SingleResult deleteMember( @PathVariable("project_id") Long projectId, + @PathVariable("member_id") Long memberId, HttpServletRequest req) { - return new SingleResult<>(memberService.deleteMember(projectId, req)); + return new SingleResult<>(memberService.deleteMember(projectId, memberId, req)); } } diff --git a/src/main/java/team1/BE/seamless/mapper/MemberMapper.java b/src/main/java/team1/BE/seamless/mapper/MemberMapper.java index b697d4a..56f6ce5 100644 --- a/src/main/java/team1/BE/seamless/mapper/MemberMapper.java +++ b/src/main/java/team1/BE/seamless/mapper/MemberMapper.java @@ -29,11 +29,32 @@ public MemberEntity toUpdate(MemberEntity member, UpdateMember update) { return member; } - public MemberResponseDTO toResponseDTO(MemberEntity memberEntity) { + public MemberResponseDTO toGetResponseDTO(MemberEntity memberEntity) { return new MemberResponseDTO("성공적으로 조회되었습니다.", memberEntity.getName(), memberEntity.getRole(), memberEntity.getEmail()); } + public MemberResponseDTO toDeleteResponseDTO(MemberEntity memberEntity) { + return new MemberResponseDTO("성공적으로 삭제되었습니다.", + memberEntity.getName(), + memberEntity.getRole(), + memberEntity.getEmail()); + } + + public MemberResponseDTO toCreateResponseDTO(MemberEntity memberEntity) { + return new MemberResponseDTO("성공적으로 생성되었습니다.", + memberEntity.getName(), + memberEntity.getRole(), + memberEntity.getEmail()); + } + + public MemberResponseDTO toPutResponseDTO(MemberEntity memberEntity) { + return new MemberResponseDTO("성공적으로 수정되었습니다.", + memberEntity.getName(), + memberEntity.getRole(), + memberEntity.getEmail()); + } + } diff --git a/src/main/java/team1/BE/seamless/repository/MemberRepository.java b/src/main/java/team1/BE/seamless/repository/MemberRepository.java index 0b288c9..0cac24b 100644 --- a/src/main/java/team1/BE/seamless/repository/MemberRepository.java +++ b/src/main/java/team1/BE/seamless/repository/MemberRepository.java @@ -15,4 +15,6 @@ public interface MemberRepository extends JpaRepository { Optional findByProjectEntityIdAndEmailAndIsDeleteFalse(Long projectId, String email); + Optional findByProjectEntityIdAndIdAndIsDeleteFalse(Long projectId, Long memberId); + } diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 6879693..456e7fd 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -37,34 +37,25 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe this.parsingPram = parsingPram; } - public MemberResponseDTO getMember(Long projectId, HttpServletRequest req) { - // 팀원인지 확인 - if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { - throw new BaseHandler(HttpStatus.UNAUTHORIZED,"조회 권한이 없습니다."); - } + public MemberResponseDTO getMember(Long projectId, Long memberId, HttpServletRequest req) { + // 팀원인지 확인.. 삭제함 - MemberEntity memberEntity = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse(projectId, parsingPram.getEmail(req)) + MemberEntity memberEntity = memberRepository.findByProjectEntityIdAndIdAndIsDeleteFalse(projectId, memberId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); - return memberMapper.toResponseDTO(memberEntity); + return memberMapper.toGetResponseDTO(memberEntity); } public Page getMemberList(@Valid Long projectId, getMemberList memberListRequestDTO, HttpServletRequest req) { - // 팀원인지 확인 - if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { - throw new BaseHandler(HttpStatus.UNAUTHORIZED,"조회 권한이 없습니다."); - } + // 팀원인지 확인.. 삭제함 return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId, memberListRequestDTO.toPageable()); } public MemberResponseDTO createMember(Long projectId, CreateMember create, HttpServletRequest req) { - // 팀원인지 확인 - if (parsingPram.getRole(req).equals(Role.MEMBER.toString())) { - throw new BaseHandler(HttpStatus.UNAUTHORIZED,"등록 권한이 없습니다."); - } + // 팀원인지 확인.. 삭제함 ProjectEntity project = projectRepository.findById(projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); @@ -72,7 +63,7 @@ public MemberResponseDTO createMember(Long projectId, CreateMember create, HttpS MemberEntity member = memberMapper.toEntity(create, project); memberRepository.save(member); - return memberMapper.toResponseDTO(member); + return memberMapper.toCreateResponseDTO(member); } public MemberResponseDTO createMember(Long projectId, CreateMember create) { @@ -84,37 +75,37 @@ public MemberResponseDTO createMember(Long projectId, CreateMember create) { MemberEntity member = memberMapper.toEntity(create, project); memberRepository.save(member); - return memberMapper.toResponseDTO(member); + return memberMapper.toCreateResponseDTO(member); } @Transactional - public MemberResponseDTO updateMember(Long projectId, UpdateMember update, HttpServletRequest req) { + public MemberResponseDTO updateMember(Long projectId, Long memberId, UpdateMember update, HttpServletRequest req) { // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); } - MemberEntity member = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse( - projectId, parsingPram.getEmail(req)) + MemberEntity member = memberRepository.findByProjectEntityIdAndIdAndIsDeleteFalse( + projectId,memberId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); MemberEntity memberEntity = memberMapper.toUpdate(member, update); - return memberMapper.toResponseDTO(memberEntity); + return memberMapper.toPutResponseDTO(memberEntity); } @Transactional - public MemberResponseDTO deleteMember(Long projectId, HttpServletRequest req) { + public MemberResponseDTO deleteMember(Long projectId, Long memberId, HttpServletRequest req) { // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); } - MemberEntity member = memberRepository.findByProjectEntityIdAndEmailAndIsDeleteFalse( - projectId, parsingPram.getEmail(req)) + MemberEntity member = memberRepository.findByProjectEntityIdAndIdAndIsDeleteFalse( + projectId, memberId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); member.setDelete(true); - return memberMapper.toResponseDTO(member); + return memberMapper.toDeleteResponseDTO(member); } } From 5abd6fae303e89536b5879a3ddf11d37d6e99f4c Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 20:11:13 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20CRUD=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프로젝트 기간에 관한 인증 로직 --- .../repository/ProjectRepository.java | 3 ++ .../BE/seamless/service/MemberService.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/team1/BE/seamless/repository/ProjectRepository.java b/src/main/java/team1/BE/seamless/repository/ProjectRepository.java index 4674197..67b2786 100644 --- a/src/main/java/team1/BE/seamless/repository/ProjectRepository.java +++ b/src/main/java/team1/BE/seamless/repository/ProjectRepository.java @@ -20,4 +20,7 @@ public interface ProjectRepository extends JpaRepository { Optional findByIdAndIsDeletedFalse(Long id); Page findByUserEntityEmailAndIsDeletedFalse(Pageable pageable, String email); + + Optional findByIdAndUserEntityIdAndIsDeletedFalse(Long projectId, Long userId); + } diff --git a/src/main/java/team1/BE/seamless/service/MemberService.java b/src/main/java/team1/BE/seamless/service/MemberService.java index 456e7fd..4102347 100644 --- a/src/main/java/team1/BE/seamless/service/MemberService.java +++ b/src/main/java/team1/BE/seamless/service/MemberService.java @@ -20,6 +20,8 @@ import team1.BE.seamless.util.auth.ParsingPram; import team1.BE.seamless.util.errorException.BaseHandler; +import java.time.LocalDateTime; + @Service public class MemberService { @@ -40,6 +42,13 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe public MemberResponseDTO getMember(Long projectId, Long memberId, HttpServletRequest req) { // 팀원인지 확인.. 삭제함 + ProjectEntity project = projectRepository.findById(projectId) + .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); + +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + MemberEntity memberEntity = memberRepository.findByProjectEntityIdAndIdAndIsDeleteFalse(projectId, memberId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 멤버가 존재하지 않습니다.")); @@ -50,6 +59,13 @@ public Page getMemberList(@Valid Long projectId, getMemberList memberListRequestDTO, HttpServletRequest req) { // 팀원인지 확인.. 삭제함 + ProjectEntity project = projectRepository.findById(projectId) + .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); + +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId, memberListRequestDTO.toPageable()); } @@ -60,6 +76,11 @@ public MemberResponseDTO createMember(Long projectId, CreateMember create, HttpS ProjectEntity project = projectRepository.findById(projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); + // 아래는 프로젝트가 종료됐는데, 그 후에 팀원이 참여링크를 통해 프로젝트 참여를 했을 때 걸러내는거임ㅇㅇ +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + MemberEntity member = memberMapper.toEntity(create, project); memberRepository.save(member); @@ -72,6 +93,10 @@ public MemberResponseDTO createMember(Long projectId, CreateMember create) { ProjectEntity project = projectRepository.findById(projectId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + MemberEntity member = memberMapper.toEntity(create, project); memberRepository.save(member); @@ -80,6 +105,12 @@ public MemberResponseDTO createMember(Long projectId, CreateMember create) { @Transactional public MemberResponseDTO updateMember(Long projectId, Long memberId, UpdateMember update, HttpServletRequest req) { + ProjectEntity project = projectRepository.findById(projectId) + .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); + +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); @@ -95,6 +126,13 @@ public MemberResponseDTO updateMember(Long projectId, Long memberId, UpdateMembe @Transactional public MemberResponseDTO deleteMember(Long projectId, Long memberId, HttpServletRequest req) { + ProjectEntity project = projectRepository.findById(projectId) + .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다.")); +// +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) if (parsingPram.getRole(req).equals(Role.USER.toString())) { throw new BaseHandler(HttpStatus.UNAUTHORIZED,"수정 권한이 없습니다."); From 8f885a551c9a23acbe7695a21972bd9a233532e4 Mon Sep 17 00:00:00 2001 From: suno-boy Date: Fri, 11 Oct 2024 20:12:04 +0900 Subject: [PATCH 12/12] =?UTF-8?q?feat:=20=EC=B0=B8=EC=97=AC=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=20=EC=83=9D=EC=84=B1=20=EC=9D=B8=EC=A6=9D=20=EB=B3=B4?= =?UTF-8?q?=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프로젝트 기간에 관한 인증 로직 - 팀장인지에 대한 검증 --- .../controller/AttendUrlController.java | 7 ++++--- .../BE/seamless/service/AttendURLService.java | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/team1/BE/seamless/controller/AttendUrlController.java b/src/main/java/team1/BE/seamless/controller/AttendUrlController.java index bc4e9a7..0d21292 100644 --- a/src/main/java/team1/BE/seamless/controller/AttendUrlController.java +++ b/src/main/java/team1/BE/seamless/controller/AttendUrlController.java @@ -39,9 +39,10 @@ public AttendUrlController(AttendURLService attendURLService) { * less) */ @Operation(summary = "팀원초대 링크 생성") - @PostMapping("/api/project/{project_id}/invite-link") + @PostMapping("/api/project/{project_id}/invite-link/{user-id}") public SingleResult generateInviteLink(HttpServletRequest req, - @Valid @PathVariable("project_id") Long projectId) { - return new SingleResult<>(attendURLService.generateAttendURL(req, projectId)); + @Valid @PathVariable("project_id") Long projectId, + @Valid @PathVariable("user-id") Long userId) { + return new SingleResult<>(attendURLService.generateAttendURL(req, projectId, userId)); } } \ No newline at end of file diff --git a/src/main/java/team1/BE/seamless/service/AttendURLService.java b/src/main/java/team1/BE/seamless/service/AttendURLService.java index 2e9eacc..25744e8 100644 --- a/src/main/java/team1/BE/seamless/service/AttendURLService.java +++ b/src/main/java/team1/BE/seamless/service/AttendURLService.java @@ -9,6 +9,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import team1.BE.seamless.entity.ProjectEntity; +import team1.BE.seamless.entity.enums.Role; import team1.BE.seamless.repository.ProjectRepository; import team1.BE.seamless.util.auth.AesEncrypt; import team1.BE.seamless.util.auth.ParsingPram; @@ -29,11 +30,23 @@ public AttendURLService(ProjectRepository projectRepository, ParsingPram parsing this.aesEncrypt = aesEncrypt; } - public String generateAttendURL(HttpServletRequest req, @Valid Long projectId) { - ProjectEntity project = projectRepository.findByIdAndUserEntityEmailAndIsDeletedFalse(projectId, - parsingPram.getEmail(req)) + public String generateAttendURL(HttpServletRequest req, @Valid Long projectId, @Valid Long userId) { +// ProjectEntity project = projectRepository.findByIdAndUserEntityEmailAndIsDeletedFalse(projectId, +// parsingPram.getEmail(req)) 토큰에서 이메일 찾는 로직 테스트 안 돼서, 일단 프로젝트 id+유저id 로 찾는 로직으로 해놓음(추후 다시 수정 예정) + ProjectEntity project = projectRepository.findByIdAndUserEntityIdAndIsDeletedFalse(projectId,userId) .orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "프로젝트가 존재하지 않음")); + // 현재 시간이 프로젝트 종료 기한을 넘어섰는지 체크 +// if (project.getEndDate().isBefore(LocalDateTime.now())) { +// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다."); +// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ + + // 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.) + if (parsingPram.getRole(req).equals(Role.USER.toString())) { + throw new BaseHandler(HttpStatus.UNAUTHORIZED,"생성 권한이 없습니다."); + } + + // 코드는 프로젝트id + exp로 구성 // exp는 1일로 가정 String code = aesEncrypt.encrypt(