diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/controller/GhostController.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/controller/GhostController.java new file mode 100644 index 0000000..2a6d9f9 --- /dev/null +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/controller/GhostController.java @@ -0,0 +1,36 @@ +package com.dontbe.www.DontBeServer.api.ghost.controller; + +import com.dontbe.www.DontBeServer.api.ghost.service.GhostCommandService; +import com.dontbe.www.DontBeServer.api.member.dto.request.MemberClickGhostRequestDto; +import com.dontbe.www.DontBeServer.common.response.ApiResponse; +import com.dontbe.www.DontBeServer.common.util.MemberUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + +import static com.dontbe.www.DontBeServer.common.response.SuccessStatus.CLICK_MEMBER_GHOST_SUCCESS; + +@RestController +@RequestMapping("/api/v1/") +@RequiredArgsConstructor +@SecurityRequirement(name = "JWT Auth") +@Tag(name="투명도 관련",description = "Ghost Api Document") +public class GhostController { + private final GhostCommandService ghostCommandServiceService; + + @PostMapping("ghost") + @Operation(summary = "투명도 낮추는 API입니다.",description = "MemberGhost") + public ResponseEntity> clickMemberGhost(Principal principal, @RequestBody MemberClickGhostRequestDto memberClickGhostRequestDto) { + Long memberId = MemberUtil.getMemberId(principal); + ghostCommandServiceService.clickMemberGhost(memberId, memberClickGhostRequestDto); + return ApiResponse.success(CLICK_MEMBER_GHOST_SUCCESS); + } +} diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/service/GhostCommandService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/service/GhostCommandService.java index 70539ff..e8b09fe 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/service/GhostCommandService.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/ghost/service/GhostCommandService.java @@ -1,13 +1,75 @@ package com.dontbe.www.DontBeServer.api.ghost.service; +import com.dontbe.www.DontBeServer.api.ghost.domain.Ghost; +import com.dontbe.www.DontBeServer.api.ghost.repository.GhostRepository; +import com.dontbe.www.DontBeServer.api.member.domain.Member; +import com.dontbe.www.DontBeServer.api.member.dto.request.MemberClickGhostRequestDto; +import com.dontbe.www.DontBeServer.api.member.repository.MemberRepository; +import com.dontbe.www.DontBeServer.api.notification.domain.Notification; +import com.dontbe.www.DontBeServer.api.notification.repository.NotificationRepository; +import com.dontbe.www.DontBeServer.common.exception.BadRequestException; +import com.dontbe.www.DontBeServer.common.response.ErrorStatus; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Objects; + @Service @RequiredArgsConstructor @Transactional public class GhostCommandService { // 생성/ 수정/ 삭제 + private final MemberRepository memberRepository; + private final GhostRepository ghostRepository; + private final NotificationRepository notificationRepository; + public void clickMemberGhost(Long memberId, MemberClickGhostRequestDto memberClickGhostRequestDto) { + Member triggerMember = memberRepository.findMemberByIdOrThrow(memberId); + Member targetMember = memberRepository.findMemberByIdOrThrow(memberClickGhostRequestDto.targetMemberId()); + + mySelfGhostBlock(triggerMember,targetMember); + isDuplicateMemberGhost(triggerMember,targetMember); + + Ghost ghost = Ghost.builder() + .ghostTargetMember(targetMember) + .ghostTriggerMember(triggerMember) + .build(); + Ghost savedGhost = ghostRepository.save(ghost); + + Notification notification = Notification.builder() + .notificationTargetMember(targetMember) + .notificationTriggerMemberId(memberId) + .notificationTriggerType(memberClickGhostRequestDto.alarmTriggerType()) + .notificationTriggerId(memberClickGhostRequestDto.alarmTriggerId()) //2차 스프린트 : 에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기(refineNotificationTriggerId에 추가) + .isNotificationChecked(false) + .notificationText("") + .build(); + Notification savedNotification = notificationRepository.save(notification); + + targetMember.decreaseGhost(); + + if(targetMember.getMemberGhost() == -85) { + Notification ghostNotification = Notification.builder() + .notificationTargetMember(targetMember) + .notificationTriggerMemberId(memberId) + .notificationTriggerType("beGhost") + .notificationTriggerId(memberClickGhostRequestDto.alarmTriggerId()) + .isNotificationChecked(false) + .notificationText("") + .build(); + Notification savedGhostNotification = notificationRepository.save(ghostNotification); + } + } + + private void isDuplicateMemberGhost(Member triggerMember, Member targetMember) { + if(ghostRepository.existsByGhostTargetMemberAndGhostTriggerMember(targetMember,triggerMember)) { + throw new BadRequestException(ErrorStatus.DUPLICATION_MEMBER_GHOST.getMessage()); + } + } + private void mySelfGhostBlock(Member triggerMember, Member targetMember) { + if(Objects.equals(triggerMember.getId(), targetMember.getId())) { + throw new BadRequestException(ErrorStatus.GHOST_MYSELF_BLOCK.getMessage()); + } + } } diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/controller/MemberController.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/controller/MemberController.java index 8e735f5..7f74b9f 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/controller/MemberController.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/controller/MemberController.java @@ -1,17 +1,15 @@ package com.dontbe.www.DontBeServer.api.member.controller; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberClickGhostRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberNicknameCheckRequestDto; import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto; import com.dontbe.www.DontBeServer.api.member.dto.response.MemberDetailGetResponseDto; import com.dontbe.www.DontBeServer.api.member.dto.response.MemberGetProfileResponseDto; -import com.dontbe.www.DontBeServer.api.member.service.MemberService; +import com.dontbe.www.DontBeServer.api.member.service.MemberCommandService; +import com.dontbe.www.DontBeServer.api.member.service.MemberQueryService; import com.dontbe.www.DontBeServer.common.response.ApiResponse; import com.dontbe.www.DontBeServer.common.util.MemberUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -26,14 +24,15 @@ @SecurityRequirement(name = "JWT Auth") @Tag(name="멤버 관련",description = "Member Api Document") public class MemberController { - private final MemberService memberService; + private final MemberCommandService memberCommandService; + private final MemberQueryService memberQueryService; @DeleteMapping("withdrawal") @Operation(summary = "유저 탈퇴 API입니다. 앱잼 기간 미사용",description = "MemberWithdrawal") public ResponseEntity> withdrawalMember(Principal principal) { Long memberId = MemberUtil.getMemberId(principal); - memberService.withdrawalMember(memberId); + memberCommandService.withdrawalMember(memberId); return ApiResponse.success(WITHDRAWAL_SUCCESS); } @@ -41,35 +40,27 @@ public ResponseEntity> withdrawalMember(Principal principal) @Operation(summary = "유저 상세 정보 조회 API입니다.",description = "MemberData") public ResponseEntity> getMemberDetail(Principal principal){ Long memberId = MemberUtil.getMemberId(principal); - return ApiResponse.success(GET_MEMBER_DETAIL, memberService.getMemberDetail(memberId)); + return ApiResponse.success(GET_MEMBER_DETAIL, memberQueryService.getMemberDetail(memberId)); } @GetMapping("viewmember/{viewmemberId}") @Operation(summary = "유저 프로필 정보 조회 API입니다.",description = "MemberProfile") public ResponseEntity> getMemberProfile(Principal principal,@PathVariable(name = "viewmemberId") Long viewmemberId) { - return ApiResponse.success(GET_PROFILE_SUCCESS, memberService.getMemberProfile(viewmemberId)); - } - - @PostMapping("ghost") - @Operation(summary = "투명도 낮추는 API입니다.",description = "MemberGhost") - public ResponseEntity> clickMemberGhost(Principal principal,@RequestBody MemberClickGhostRequestDto memberClickGhostRequestDto) { - Long memberId = MemberUtil.getMemberId(principal); - memberService.clickMemberGhost(memberId, memberClickGhostRequestDto); - return ApiResponse.success(CLICK_MEMBER_GHOST_SUCCESS); + return ApiResponse.success(GET_PROFILE_SUCCESS, memberQueryService.getMemberProfile(viewmemberId)); } @PatchMapping("user-profile") @Operation(summary = "유저 프로필 수정 API입니다.",description = "UserProfilePatch") public ResponseEntity> updateMemberProfile(Principal principal, @RequestBody MemberProfilePatchRequestDto memberProfilePatchRequestDto) { Long memberId = MemberUtil.getMemberId(principal); - memberService.updateMemberProfile(memberId, memberProfilePatchRequestDto); + memberCommandService.updateMemberProfile(memberId, memberProfilePatchRequestDto); return ApiResponse.success(PATCH_MEMBER_PROFILE); } @GetMapping("nickname-validation") @Operation(summary = "유저 닉네임 사용 가능 확인 API 입니다.",description = "NicknameValidation") public ResponseEntity> checkMemberNickname(Principal principal,@RequestParam(value = "nickname") String nickname) { - memberService.checkNicknameValidate(nickname); + memberQueryService.checkNicknameValidate(nickname); return ApiResponse.success(NICKNAME_CHECK_SUCCESS); } } \ No newline at end of file diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/dto/request/MemberNicknameCheckRequestDto.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/dto/request/MemberNicknameCheckRequestDto.java deleted file mode 100644 index a2f86b8..0000000 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/dto/request/MemberNicknameCheckRequestDto.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.dontbe.www.DontBeServer.api.member.dto.request; - -import jakarta.validation.constraints.NotBlank; - -public record MemberNicknameCheckRequestDto ( - @NotBlank String nickname -){ -} diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/Impl/MemberServiceImpl.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/Impl/MemberServiceImpl.java deleted file mode 100644 index 2f6211d..0000000 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/Impl/MemberServiceImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.dontbe.www.DontBeServer.api.member.service.Impl; - -import com.dontbe.www.DontBeServer.api.ghost.domain.Ghost; -import com.dontbe.www.DontBeServer.api.ghost.repository.GhostRepository; -import com.dontbe.www.DontBeServer.api.member.domain.Member; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberClickGhostRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberNicknameCheckRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.response.MemberDetailGetResponseDto; -import com.dontbe.www.DontBeServer.api.member.dto.response.MemberGetProfileResponseDto; -import com.dontbe.www.DontBeServer.api.member.repository.MemberRepository; -import com.dontbe.www.DontBeServer.api.member.service.MemberService; -import com.dontbe.www.DontBeServer.api.notification.domain.Notification; -import com.dontbe.www.DontBeServer.api.notification.repository.NotificationRepository; -import com.dontbe.www.DontBeServer.common.exception.BadRequestException; -import com.dontbe.www.DontBeServer.common.response.ErrorStatus; -import com.dontbe.www.DontBeServer.common.util.GhostUtil; -import com.dontbe.www.DontBeServer.common.util.TimeUtilCustom; -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.Objects; - - -@Service -@RequiredArgsConstructor -public class MemberServiceImpl implements MemberService { - private final MemberRepository memberRepository; - private final GhostRepository ghostRepository; - private final NotificationRepository notificationRepository; - - @Override - @Transactional - public void withdrawalMember(Long memberId) { - Member member = memberRepository.findMemberByIdOrThrow(memberId); - memberRepository.delete(member); - } - - @Override - public MemberDetailGetResponseDto getMemberDetail(Long memberId) { - Member member = memberRepository.findMemberByIdOrThrow(memberId); - String time = TimeUtilCustom.refineTimeMemberDetail(member.getCreatedAt()); - return MemberDetailGetResponseDto.of(member, time); - } - - @Override - public MemberGetProfileResponseDto getMemberProfile(Long memberId) { - Member member = memberRepository.findMemberByIdOrThrow(memberId); - int memberGhost = GhostUtil.refineGhost(member.getMemberGhost()); - return MemberGetProfileResponseDto.of(member, memberGhost); - } - - @Override - @Transactional - public void clickMemberGhost(Long memberId, MemberClickGhostRequestDto memberClickGhostRequestDto) { - Member triggerMember = memberRepository.findMemberByIdOrThrow(memberId); - Member targetMember = memberRepository.findMemberByIdOrThrow(memberClickGhostRequestDto.targetMemberId()); - - mySelfGhostBlock(triggerMember,targetMember); - isDuplicateMemberGhost(triggerMember,targetMember); - - Ghost ghost = Ghost.builder() - .ghostTargetMember(targetMember) - .ghostTriggerMember(triggerMember) - .build(); - Ghost savedGhost = ghostRepository.save(ghost); - - Notification notification = Notification.builder() - .notificationTargetMember(targetMember) - .notificationTriggerMemberId(memberId) - .notificationTriggerType(memberClickGhostRequestDto.alarmTriggerType()) - .notificationTriggerId(memberClickGhostRequestDto.alarmTriggerId()) //2차 스프린트 : 에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기(refineNotificationTriggerId에 추가) - .isNotificationChecked(false) - .notificationText("") - .build(); - Notification savedNotification = notificationRepository.save(notification); - - targetMember.decreaseGhost(); - - if(targetMember.getMemberGhost() == -85) { - Notification ghostNotification = Notification.builder() - .notificationTargetMember(targetMember) - .notificationTriggerMemberId(memberId) - .notificationTriggerType("beGhost") - .notificationTriggerId(memberClickGhostRequestDto.alarmTriggerId()) - .isNotificationChecked(false) - .notificationText("") - .build(); - Notification savedGhostNotification = notificationRepository.save(ghostNotification); - } - } - - - @Transactional - public void updateMemberProfile(Long memberId, MemberProfilePatchRequestDto memberProfilePatchRequestDto) { - Member existingMember = memberRepository.findMemberByIdOrThrow(memberId); - - // 업데이트할 속성만 복사 - if (memberProfilePatchRequestDto.nickname() != null) { - existingMember.updateNickname(memberProfilePatchRequestDto.nickname()); - } - if (memberProfilePatchRequestDto.member_intro() != null) { - existingMember.updateMemberIntro(memberProfilePatchRequestDto.member_intro()); - } - if (memberProfilePatchRequestDto.profile_url() != null) { - existingMember.updateProfileUrl(memberProfilePatchRequestDto.profile_url()); - } - if (memberProfilePatchRequestDto.is_alarm_allowed() | !memberProfilePatchRequestDto.is_alarm_allowed()) { - existingMember.updateMemberIsAlarmAllowed(memberProfilePatchRequestDto.is_alarm_allowed()); - } - - // 저장 - Member savedMember = memberRepository.save(existingMember); - } - - public void checkNicknameValidate(String nickname) { - if(memberRepository.existsByNickname(nickname)){ - throw new BadRequestException(ErrorStatus.NICKNAME_VALIDATE_ERROR.getMessage()); - } - } - - private void isDuplicateMemberGhost(Member triggerMember, Member targetMember) { - if(ghostRepository.existsByGhostTargetMemberAndGhostTriggerMember(targetMember,triggerMember)) { - throw new BadRequestException(ErrorStatus.DUPLICATION_MEMBER_GHOST.getMessage()); - } - } - - private void mySelfGhostBlock(Member triggerMember, Member targetMember) { - if(Objects.equals(triggerMember.getId(), targetMember.getId())) { - throw new BadRequestException(ErrorStatus.GHOST_MYSELF_BLOCK.getMessage()); - } - } -} diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberCommandService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberCommandService.java new file mode 100644 index 0000000..f9a59f0 --- /dev/null +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberCommandService.java @@ -0,0 +1,41 @@ +package com.dontbe.www.DontBeServer.api.member.service; + +import com.dontbe.www.DontBeServer.api.member.domain.Member; +import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto; +import com.dontbe.www.DontBeServer.api.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class MemberCommandService { + private final MemberRepository memberRepository; + + public void withdrawalMember(Long memberId) { + Member member = memberRepository.findMemberByIdOrThrow(memberId); + memberRepository.delete(member); + } + + public void updateMemberProfile(Long memberId, MemberProfilePatchRequestDto memberProfilePatchRequestDto) { + Member existingMember = memberRepository.findMemberByIdOrThrow(memberId); + + // 업데이트할 속성만 복사 + if (memberProfilePatchRequestDto.nickname() != null) { + existingMember.updateNickname(memberProfilePatchRequestDto.nickname()); + } + if (memberProfilePatchRequestDto.member_intro() != null) { + existingMember.updateMemberIntro(memberProfilePatchRequestDto.member_intro()); + } + if (memberProfilePatchRequestDto.profile_url() != null) { + existingMember.updateProfileUrl(memberProfilePatchRequestDto.profile_url()); + } + if (memberProfilePatchRequestDto.is_alarm_allowed() | !memberProfilePatchRequestDto.is_alarm_allowed()) { + existingMember.updateMemberIsAlarmAllowed(memberProfilePatchRequestDto.is_alarm_allowed()); + } + + // 저장 + Member savedMember = memberRepository.save(existingMember); + } +} diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberQueryService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberQueryService.java new file mode 100644 index 0000000..33d3533 --- /dev/null +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberQueryService.java @@ -0,0 +1,38 @@ +package com.dontbe.www.DontBeServer.api.member.service; + +import com.dontbe.www.DontBeServer.api.member.domain.Member; +import com.dontbe.www.DontBeServer.api.member.dto.response.MemberDetailGetResponseDto; +import com.dontbe.www.DontBeServer.api.member.dto.response.MemberGetProfileResponseDto; +import com.dontbe.www.DontBeServer.api.member.repository.MemberRepository; +import com.dontbe.www.DontBeServer.common.exception.BadRequestException; +import com.dontbe.www.DontBeServer.common.response.ErrorStatus; +import com.dontbe.www.DontBeServer.common.util.GhostUtil; +import com.dontbe.www.DontBeServer.common.util.TimeUtilCustom; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MemberQueryService { + private final MemberRepository memberRepository; + + public MemberDetailGetResponseDto getMemberDetail(Long memberId) { + Member member = memberRepository.findMemberByIdOrThrow(memberId); + String time = TimeUtilCustom.refineTimeMemberDetail(member.getCreatedAt()); + return MemberDetailGetResponseDto.of(member, time); + } + + public MemberGetProfileResponseDto getMemberProfile(Long memberId) { + Member member = memberRepository.findMemberByIdOrThrow(memberId); + int memberGhost = GhostUtil.refineGhost(member.getMemberGhost()); + return MemberGetProfileResponseDto.of(member, memberGhost); + } + + public void checkNicknameValidate(String nickname) { + if(memberRepository.existsByNickname(nickname)){ + throw new BadRequestException(ErrorStatus.NICKNAME_VALIDATE_ERROR.getMessage()); + } + } +} diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberService.java deleted file mode 100644 index c9a5315..0000000 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.dontbe.www.DontBeServer.api.member.service; - -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberClickGhostRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberNicknameCheckRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto; -import com.dontbe.www.DontBeServer.api.member.dto.response.MemberDetailGetResponseDto; -import com.dontbe.www.DontBeServer.api.member.dto.response.MemberGetProfileResponseDto; - -public interface MemberService { - //유저 탈퇴하기 - void withdrawalMember(Long memberId); - - MemberDetailGetResponseDto getMemberDetail(Long memberId); - - MemberGetProfileResponseDto getMemberProfile(Long memberId); - - void clickMemberGhost(Long memberId, MemberClickGhostRequestDto memberClickGhostRequestDto); - - void updateMemberProfile(Long memberId, MemberProfilePatchRequestDto memberProfilePatchRequestDto); - - void checkNicknameValidate(String nickname); -}