diff --git a/src/main/java/com/depromeet/fairer/api/MemberController.java b/src/main/java/com/depromeet/fairer/api/MemberController.java index 6f8e9f9e..a76978df 100644 --- a/src/main/java/com/depromeet/fairer/api/MemberController.java +++ b/src/main/java/com/depromeet/fairer/api/MemberController.java @@ -34,22 +34,18 @@ public class MemberController { @Tag(name = "members") @GetMapping("/me") + @ApiOperation(value = "내 정보 조회") public ResponseEntity getMe(@ApiIgnore @RequestMemberId Long memberId) { return ResponseEntity.ok(MemberResponseDto.from(memberService.find(memberId))); } - @Tag(name = "members") - @PutMapping("/me") - public ResponseEntity updateMe(@Valid MemberUpdateRequestDto request, @ApiIgnore @RequestMemberId Long memberId) { - return ResponseEntity.ok(MemberResponseDto.from(memberService.updateMember(memberId, request.getMemberName(), request.getProfilePath(), request.getStatusMessage()))); - } - /*** * 기본적으로 제공해주는 프로필 이미지는 profileImageDefaultPath 하위에 보관 * 추후에 유저가 업로드 하는 프로필 이미지는 각 유저 폴더에 보관 */ @Tag(name = "members") @GetMapping("/profile-image") + @ApiOperation(value = "기본 프로필 이미지 리스트 조회") public ResponseEntity getDefaultProfileImageList() { return ResponseEntity.ok( MemberProfileImageResponseDto.builder() @@ -61,9 +57,9 @@ public ResponseEntity getDefaultProfileImageList( @ApiOperation(value = "멤버 업데이트", notes = "멤버 정보 업데이트

" + "멤버 이름
프로필 url") @PatchMapping(value = "") - public ResponseEntity updateTeam(@ApiIgnore @RequestMemberId Long memberId, @RequestBody com.depromeet.fairer.dto.member.MemberUpdateRequestDto requestDto) { + public ResponseEntity updateTeam(@ApiIgnore @RequestMemberId Long memberId, @RequestBody MemberUpdateRequestDto requestDto) { // TODO 이름, url 정규식 검증 - memberService.updateMember(memberId, requestDto.getMemberName(), requestDto.getProfileUrl()); + memberService.updateMember(memberId, requestDto.getMemberName(), requestDto.getProfilePath(), requestDto.getStatusMessage()); return ResponseEntity.ok(CommonApiResult.createOk("멤버 정보가 업데이트 되었습니다.")); } } diff --git a/src/main/java/com/depromeet/fairer/domain/member/Member.java b/src/main/java/com/depromeet/fairer/domain/member/Member.java index c448e5b3..a49dc42b 100644 --- a/src/main/java/com/depromeet/fairer/domain/member/Member.java +++ b/src/main/java/com/depromeet/fairer/domain/member/Member.java @@ -91,8 +91,9 @@ public boolean hasTeam() { return this.team != null; } - public void update(String memberName, String profileUrl) { + public void update(String memberName, String profilePath, String statusMessage) { this.memberName = memberName; - this.profilePath = profileUrl; + this.profilePath = profilePath; + this.statusMessage = statusMessage; } } diff --git a/src/main/java/com/depromeet/fairer/domain/member/constant/ProfileImage.java b/src/main/java/com/depromeet/fairer/domain/member/constant/ProfileImage.java index 3b8a3177..531ff6c2 100644 --- a/src/main/java/com/depromeet/fairer/domain/member/constant/ProfileImage.java +++ b/src/main/java/com/depromeet/fairer/domain/member/constant/ProfileImage.java @@ -11,22 +11,22 @@ @Getter @AllArgsConstructor public enum ProfileImage { - PROFILE_1("%2Fblue3.png?alt=media&token=3b0ffa34-cf13-4eb2-9e19-ba91d8952c9a"), - PROFILE_2("%2Fblue4.png?alt=media&token=d31d6d31-a04e-4c4c-b2f6-8670ca122375"), - PROFILE_3("%2Forange1.png?alt=media&token=055a8cc0-9f37-4282-9acd-d237563410ae"), - PROFILE_4("%2Forange2.png?alt=media&token=f5c42e87-708e-4e97-a86f-9688d09a4d89"), - PROFILE_5("%2Fpink1.png?alt=media&token=8cde7d10-718e-4027-9f6f-02582d907bd5"), - PROFILE_6("%2Fpink3.png?alt=media&token=984009db-d0a9-4ae8-a89d-cd194b5f0af2"), - PROFILE_7("%2Fgreen1.png?alt=media&token=8d8711ff-1bfd-42ef-bd0d-64d91dab536c"), - PROFILE_8("%2Fgreen3.png?alt=media&token=9a326f5b-aaea-491b-aa9a-63b68a19562b"), - PROFILE_9("%2Fpurple1.png?alt=media&token=f6c2c333-1847-45a7-bd71-5149d41b02a8"), - PROFILE_10("%2Fpurple3.png?alt=media&token=e7b8a734-75a9-44aa-8c85-a505aee71d00"), - PROFILE_11("%2Fpurple2.png?alt=media&token=108ec0bc-5d7d-4c44-9f12-6e3b8f6b52a0"), - PROFILE_12("%2Fyellow1.png?alt=media&token=a4c653b8-0962-4e17-b91b-de3e75af38ba"), - PROFILE_13("%2Fyellow2.png?alt=media&token=ae0666de-7cf1-41dd-88cc-94c654ff4d44"), - PROFILE_14("%2Flight_blue1.png?alt=media&token=3b358768-8144-4adb-95fa-822e29ec07c1"), - PROFILE_15("%2Flight_blue2.png?alt=media&token=f52561f6-818e-4730-b72c-8530c48ccd0f"), - PROFILE_16("%2Findigo3.png?alt=media&token=933a7607-833f-4f4e-b5b9-e0fba1374d30"); + PROFILE_1("%2Fblue3-3x.png?alt=media&token=13eaabdf-1729-46b4-bd23-85c5f8908fdb"), + PROFILE_2("%2Fblue4-3x.png?alt=media&token=fa208353-fcb9-4996-b596-57e3d07a463d"), + PROFILE_3("%2Forange1-3x.png?alt=media&token=6a875a5f-3af0-41a7-872c-5c725ef1eb18"), + PROFILE_4("%2Forange2-3x.png?alt=media&token=bc4f0cc7-76d3-4aa2-95b3-aee112fecb28"), + PROFILE_5("%2Fpink1-3x.png?alt=media&token=2317c3c0-fdb9-4236-88ed-5991c4b47f17"), + PROFILE_6("%2Fpink3-3x.png?alt=media&token=bb23c78c-51ec-4fe4-95ad-7a93c7c59f84"), + PROFILE_7("%2Fgreen1-3x.png?alt=media&token=9a27b20c-602c-4750-a100-659cd08409af"), + PROFILE_8("%2Fgreen3-3x.png?alt=media&token=a17b07bb-816b-414c-836f-7d53a41d230b"), + PROFILE_9("%2Fpurple1-3x.png?alt=media&token=828f20f0-6451-40d9-a38f-83e5981ad029"), + PROFILE_10("%2Fpurple3-3x.png?alt=media&token=b8793e5c-9ebf-474e-805f-e0279e82bfa2"), + PROFILE_11("%2Fpurple2-3x.png?alt=media&token=1f38ac6e-6c49-49c6-be11-be161f2b3079"), + PROFILE_12("%2Fyellow1-3x.png?alt=media&token=adbdd7a8-8c57-406f-9433-b120b5626644"), + PROFILE_13("%2Fyellow2-3x.png?alt=media&token=ccf1bbcf-615f-4950-824a-c51b15ac719a"), + PROFILE_14("%2Flight-blue1-3x.png?alt=media&token=4df1d835-a7e2-4d04-9a66-3c47237f38ce"), + PROFILE_15("%2Flight-blue2-3x.png?alt=media&token=5d249bd7-648c-4dba-8d6b-a9b34befd821"), + PROFILE_16("%2Findigo3-3x.png?alt=media&token=7c0a18bb-d746-4d62-9fa1-87c3876d9eac"); final String bigImageName; diff --git a/src/main/java/com/depromeet/fairer/dto/member/MemberUpdateRequestDto.java b/src/main/java/com/depromeet/fairer/dto/member/MemberUpdateRequestDto.java deleted file mode 100644 index 49cac0d8..00000000 --- a/src/main/java/com/depromeet/fairer/dto/member/MemberUpdateRequestDto.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.depromeet.fairer.dto.member; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.*; - -import javax.validation.constraints.NotNull; - -@Data -@ApiModel(value = "멤버 정보 업데이트 요청 객체", description = "멤버 정보 업데이트 요청 객체") -public class MemberUpdateRequestDto { - - @ApiModelProperty(value = "멤버 이름") - @NotNull - private String memberName; - - @ApiModelProperty(value = "프로필 url") - @NotNull - private String profileUrl; -} diff --git a/src/main/java/com/depromeet/fairer/dto/member/request/MemberUpdateRequestDto.java b/src/main/java/com/depromeet/fairer/dto/member/request/MemberUpdateRequestDto.java index 789a4f70..490fa190 100644 --- a/src/main/java/com/depromeet/fairer/dto/member/request/MemberUpdateRequestDto.java +++ b/src/main/java/com/depromeet/fairer/dto/member/request/MemberUpdateRequestDto.java @@ -2,14 +2,17 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; @Data @Builder @ApiModel(value="멤버 정보 업데이트 요청 객체", description = "멤버 정보 업데이트 요청 객체") +@AllArgsConstructor @NoArgsConstructor public class MemberUpdateRequestDto { @NotBlank @ApiModelProperty(value = "프로필 이미지 경로") diff --git a/src/main/java/com/depromeet/fairer/global/exception/handler/GlobalExceptionHandler.java b/src/main/java/com/depromeet/fairer/global/exception/handler/GlobalExceptionHandler.java index 05ff4c03..682b3b1e 100644 --- a/src/main/java/com/depromeet/fairer/global/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/depromeet/fairer/global/exception/handler/GlobalExceptionHandler.java @@ -1,8 +1,6 @@ package com.depromeet.fairer.global.exception.handler; -import com.depromeet.fairer.global.exception.BadRequestException; -import com.depromeet.fairer.global.exception.CannotJoinTeamException; -import com.depromeet.fairer.global.exception.PermissionDeniedException; +import com.depromeet.fairer.global.exception.*; import com.depromeet.fairer.global.exception.dto.ErrorResponseDto; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -92,6 +90,12 @@ protected ResponseEntity handlePermissionDeniedException( return exceptionResponseEntity(e.getMessage(), HttpStatus.FORBIDDEN, request.getRequestURI()); } + @ExceptionHandler(NoSuchMemberException.class) + protected ResponseEntity handleNoSuchMemberException(NoSuchMemberException e, HttpServletRequest request) { + log.error("NoSuchMemberException", e); + return exceptionResponseEntity(e.getMessage(), HttpStatus.NOT_FOUND, request.getRequestURI()); + } + /** * 어떤 객체를 생성하지 못할 경우 발생 */ @@ -101,6 +105,20 @@ protected ResponseEntity handleCannotJoinTeamException(CannotJ return exceptionResponseEntity(e.getMessage(), HttpStatus.NOT_ACCEPTABLE, request.getRequestURI()); } + @ExceptionHandler(FeignClientException.class) + protected ResponseEntity handleFeignClientException(FeignClientException e, HttpServletRequest request) { + log.error("FeignClientException", e); + return exceptionResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, request.getRequestURI()); + } + + @ExceptionHandler(MemberTokenNotFoundException.class) + protected ResponseEntity handleMemberTokenNotFoundException(MemberTokenNotFoundException e, HttpServletRequest request) { + log.error("MemberTokenNotFoundException", e); + return exceptionResponseEntity(e.getMessage(), HttpStatus.NOT_FOUND, request.getRequestURI()); + } + + + /** * exception 발생사 ResponseEntity 로 변환 후 반환 * diff --git a/src/main/java/com/depromeet/fairer/service/member/MemberService.java b/src/main/java/com/depromeet/fairer/service/member/MemberService.java index 7183f17a..2f09dc65 100644 --- a/src/main/java/com/depromeet/fairer/service/member/MemberService.java +++ b/src/main/java/com/depromeet/fairer/service/member/MemberService.java @@ -38,15 +38,8 @@ public List getMemberListByHouseWorkId(Long houseWorkId) { return memberRepository.getMemberDtoListByHouseWorkId(houseWorkId); } - public void updateMember(Long memberId, String memberName, String profileUrl) { - final Member reqMember = find(memberId); - reqMember.update(memberName, profileUrl); - } - public Member updateMember(Long memberId, String memberName, String profilePath, String statusMessage) { Member member = this.find(memberId); - member.setMemberName(memberName); - member.setProfilePath(profilePath); - member.setStatusMessage(statusMessage); + member.update(memberName, profilePath, statusMessage); return memberRepository.save(member); }} diff --git a/src/main/java/com/depromeet/fairer/service/team/TeamService.java b/src/main/java/com/depromeet/fairer/service/team/TeamService.java index ed2637d1..9bd0bbfb 100644 --- a/src/main/java/com/depromeet/fairer/service/team/TeamService.java +++ b/src/main/java/com/depromeet/fairer/service/team/TeamService.java @@ -1,11 +1,14 @@ package com.depromeet.fairer.service.team; +import com.depromeet.fairer.domain.assignment.Assignment; import com.depromeet.fairer.domain.member.Member; import com.depromeet.fairer.domain.team.Team; import com.depromeet.fairer.global.exception.BadRequestException; import com.depromeet.fairer.global.exception.CannotJoinTeamException; import com.depromeet.fairer.global.exception.MemberTokenNotFoundException; +import com.depromeet.fairer.repository.assignment.AssignmentRepository; +import com.depromeet.fairer.repository.housework.HouseWorkRepository; import com.depromeet.fairer.repository.member.MemberRepository; import com.depromeet.fairer.repository.team.TeamRepository; import com.depromeet.fairer.service.member.MemberService; @@ -17,6 +20,7 @@ import javax.transaction.Transactional; import java.time.LocalDateTime; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -29,6 +33,8 @@ public class TeamService { private final MemberService memberService; private final TeamRepository teamRepository; private final MemberRepository memberRepository; + private final AssignmentRepository assignmentRepository; + private final HouseWorkRepository houseWorkRepository; public Team createTeam(Long memberId, String teamName) { final Member reqMember = memberService.findWithTeam(memberId); @@ -112,6 +118,17 @@ public void leaveTeam(Long memberId) { if (!member.hasTeam()) { throw new BadRequestException("소속된 팀이 없습니다."); } + + List assignmentList = assignmentRepository.findAllByMember(member); + assignmentRepository.deleteAll(assignmentList); + + for(Assignment assignment : assignmentList) { + int count = assignmentRepository.findAllByHouseWorkAndMemberNotIn(assignment.getHouseWork(), List.of(member)).size(); + if(count == 0) { + houseWorkRepository.delete(assignment.getHouseWork()); + } + } + Team team = member.getTeam(); team.getMembers().remove(member); member.setTeam(null);