From 2d21a8067b4d515242a2a9832635d66b833e8ffc Mon Sep 17 00:00:00 2001 From: SangWoon123 Date: Thu, 7 Nov 2024 16:24:05 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=84=A4=EA=B3=84=20=EC=9C=A0?= =?UTF-8?q?=EC=97=B0=EC=84=B1=20=EA=B0=9C=EC=84=A0=20(User=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../planding/common/JsonConverter.java | 31 ++++++ .../common/infrastructure/SystemUserCode.java | 14 +++ .../common/service/UserCodeHolder.java | 5 + .../chat/controller/ChatController.java | 16 +-- .../domain/chat/service/ChatService.java | 9 +- .../controller/GroupFavoriteController.java | 14 +-- .../controller/GroupInviteController.java | 18 ++-- .../group/controller/GroupRoomController.java | 27 +++--- .../entity/domain/GroupFavoriteDomain.java | 15 +++ .../group/entity/domain/GroupRoomDomain.java | 36 +++++++ .../group/entity/domain/UserGroupDomain.java | 15 +++ .../UserGroupRepositoryCustomImpl.java | 1 - .../group/service/GroupFavoriteService.java | 25 ++--- .../group/service/GroupInviteService.java | 31 +++--- .../group/service/GroupRoomService.java | 43 ++++---- ....java => RedisGroupInviteServiceImpl.java} | 29 ++---- .../group/service/UserGroupService.java | 3 +- .../service/port/RedisGroupInviteService.java | 14 +++ .../notify/controller/FireBaseController.java | 6 +- .../notify/controller/NotifyController.java | 14 +-- .../UserNotificationSettingController.java | 13 +-- .../notify/service/NotificationHandler.java | 8 +- .../PersonalScheduleNotificationHandler.java | 11 ++- .../controller/GroupPlannerController.java | 14 +-- .../controller/PersonalPlannerController.java | 14 +-- .../planner/entity/domain/PlannerDomain.java | 28 ++++++ .../entity/domain/PlannerUserDomain.java | 16 +++ .../planner/service/GroupPlannerService.java | 27 +++--- .../service/PersonalPlannerService.java | 13 +-- .../controller/CommonScheduleController.java | 10 +- .../GroupScheduleAttendanceController.java | 8 +- .../controller/GroupScheduleController.java | 24 ++--- .../PersonalScheduleController.java | 30 +++--- .../entity/domain/GroupScheduleDomain.java | 18 ++++ .../entity/domain/PersonalScheduleDomain.java | 17 ++++ .../entity/domain/ScheduleDomain.java | 37 +++++++ .../repository/ScheduleRepositoryCustom.java | 2 - .../service/CommonScheduleService.java | 11 +-- .../GroupScheduleAttendanceService.java | 9 +- .../service/GroupScheduleService.java | 22 ++--- .../service/PersonalScheduleService.java | 29 +++--- .../user/controller/UserController.java | 9 +- .../domain/user/dto/AndroidLoginRequest.java | 2 + .../domain/user/dto/AndroidLoginResponse.java | 9 ++ .../domain/user/dto/ProfileResponse.java | 15 ++- .../planding/domain/user/dto/UserInfo.java | 30 ------ .../domain/user/dto/UserResponse.java | 36 +++++++ .../domain/user/entity/SocialType.java | 5 +- .../planding/domain/user/entity/User.java | 37 ++++--- .../domain/user/entity/UserDomain.java | 90 +++++++++++++++++ .../domain/user/mapper/UserMapper.java | 30 ------ .../user/repository/UserJpaRepository.java | 20 ++++ .../user/repository/UserRepository.java | 17 ++-- .../user/repository/UserRepositoryImpl.java | 51 ++++++++++ .../user/service/AndroidLoginService.java | 16 +-- .../user/service/UserCodeGeneratorImpl.java | 22 +++++ .../domain/user/service/UserQueryService.java | 26 ++--- .../domain/user/service/UserService.java | 63 ++++-------- .../user/service/port/UserCodeGenerator.java | 5 + .../aop/PersonalNotificationAspect.java | 27 +++--- .../planding/global/config/CacheConfig.java | 3 - .../security/jwt/JwtAuthenticationFilter.java | 13 +-- .../details/CustomUserDetailsService.java | 8 +- .../oauth/service/CustomOAuth2Service.java | 19 ++-- .../group/service/GroupRoomServiceTest.java | 5 +- .../domain/user/entity/UserDomainTest.java | 97 +++++++++++++++++++ .../domain/user/service/UserServiceTest.java | 82 ++++++++++++++++ .../mock/FakeRedisGroupInviteService.java | 34 +++++++ .../planding/mock/FakeUserRepository.java | 67 +++++++++++++ .../planding/mock/TestUserCodeGenerator.java | 13 +++ .../planding/mock/TestUserCodeHolder.java | 16 +++ 71 files changed, 1140 insertions(+), 454 deletions(-) create mode 100644 src/main/java/com/tukorea/planding/common/JsonConverter.java create mode 100644 src/main/java/com/tukorea/planding/common/infrastructure/SystemUserCode.java create mode 100644 src/main/java/com/tukorea/planding/common/service/UserCodeHolder.java create mode 100644 src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupFavoriteDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupRoomDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/group/entity/domain/UserGroupDomain.java rename src/main/java/com/tukorea/planding/domain/group/service/{RedisGroupInviteService.java => RedisGroupInviteServiceImpl.java} (62%) create mode 100644 src/main/java/com/tukorea/planding/domain/group/service/port/RedisGroupInviteService.java create mode 100644 src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerUserDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/schedule/entity/domain/GroupScheduleDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/schedule/entity/domain/PersonalScheduleDomain.java create mode 100644 src/main/java/com/tukorea/planding/domain/schedule/entity/domain/ScheduleDomain.java delete mode 100644 src/main/java/com/tukorea/planding/domain/user/dto/UserInfo.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/dto/UserResponse.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/entity/UserDomain.java delete mode 100644 src/main/java/com/tukorea/planding/domain/user/mapper/UserMapper.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/repository/UserJpaRepository.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/repository/UserRepositoryImpl.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/service/UserCodeGeneratorImpl.java create mode 100644 src/main/java/com/tukorea/planding/domain/user/service/port/UserCodeGenerator.java create mode 100644 src/test/java/com/tukorea/planding/domain/user/entity/UserDomainTest.java create mode 100644 src/test/java/com/tukorea/planding/domain/user/service/UserServiceTest.java create mode 100644 src/test/java/com/tukorea/planding/mock/FakeRedisGroupInviteService.java create mode 100644 src/test/java/com/tukorea/planding/mock/FakeUserRepository.java create mode 100644 src/test/java/com/tukorea/planding/mock/TestUserCodeGenerator.java create mode 100644 src/test/java/com/tukorea/planding/mock/TestUserCodeHolder.java diff --git a/src/main/java/com/tukorea/planding/common/JsonConverter.java b/src/main/java/com/tukorea/planding/common/JsonConverter.java new file mode 100644 index 0000000..4a823bf --- /dev/null +++ b/src/main/java/com/tukorea/planding/common/JsonConverter.java @@ -0,0 +1,31 @@ +package com.tukorea.planding.common; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +@RequiredArgsConstructor +public class JsonConverter { + + private final ObjectMapper objectMapper; + + public String convertObjectToJson(Object obj) { + try { + return objectMapper.writeValueAsString(obj); + } catch (JsonProcessingException e) { + return null; + } + } + + public T convertJsonToObject(String json, Class clazz) { + try { + return objectMapper.readValue(json, clazz); + } catch (IOException e) { + return null; + } + } +} diff --git a/src/main/java/com/tukorea/planding/common/infrastructure/SystemUserCode.java b/src/main/java/com/tukorea/planding/common/infrastructure/SystemUserCode.java new file mode 100644 index 0000000..29fc5f7 --- /dev/null +++ b/src/main/java/com/tukorea/planding/common/infrastructure/SystemUserCode.java @@ -0,0 +1,14 @@ +package com.tukorea.planding.common.infrastructure; + +import com.tukorea.planding.common.service.UserCodeHolder; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +public class SystemUserCode implements UserCodeHolder { + @Override + public String userCode() { + return "#" + UUID.randomUUID().toString().substring(0, 4); + } +} diff --git a/src/main/java/com/tukorea/planding/common/service/UserCodeHolder.java b/src/main/java/com/tukorea/planding/common/service/UserCodeHolder.java new file mode 100644 index 0000000..cf0ece8 --- /dev/null +++ b/src/main/java/com/tukorea/planding/common/service/UserCodeHolder.java @@ -0,0 +1,5 @@ +package com.tukorea.planding.common.service; + +public interface UserCodeHolder { + String userCode(); +} diff --git a/src/main/java/com/tukorea/planding/domain/chat/controller/ChatController.java b/src/main/java/com/tukorea/planding/domain/chat/controller/ChatController.java index b4c2173..7f49823 100644 --- a/src/main/java/com/tukorea/planding/domain/chat/controller/ChatController.java +++ b/src/main/java/com/tukorea/planding/domain/chat/controller/ChatController.java @@ -2,19 +2,13 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; -import com.tukorea.planding.domain.chat.config.RedisChatService; import com.tukorea.planding.domain.chat.dto.MessageRequest; import com.tukorea.planding.domain.chat.dto.MessageResponse; import com.tukorea.planding.domain.chat.service.ChatService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.messaging.handler.annotation.DestinationVariable; -import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.messaging.handler.annotation.SendTo; -import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -28,15 +22,15 @@ public class ChatController { private final ChatService chatService; @PostMapping("/{groupCode}") - public CommonResponse sendMessage(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @RequestBody MessageRequest request) { - MessageResponse messageResponse = chatService.sendMessage(userInfo.getUserCode(), request, groupCode); + public CommonResponse sendMessage(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode, @RequestBody MessageRequest request) { + MessageResponse messageResponse = chatService.sendMessage(userResponse.getUserCode(), request, groupCode); return CommonUtils.success(messageResponse); } @Operation(summary = "채팅방 내용 불러오기") @GetMapping("/{groupCode}/message") - public CommonResponse> getMessages(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - List responses = chatService.getMessages(userInfo, groupCode); + public CommonResponse> getMessages(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + List responses = chatService.getMessages(userResponse, groupCode); return CommonUtils.success(responses); } } diff --git a/src/main/java/com/tukorea/planding/domain/chat/service/ChatService.java b/src/main/java/com/tukorea/planding/domain/chat/service/ChatService.java index dbdc0b7..a6a797d 100644 --- a/src/main/java/com/tukorea/planding/domain/chat/service/ChatService.java +++ b/src/main/java/com/tukorea/planding/domain/chat/service/ChatService.java @@ -6,8 +6,9 @@ import com.tukorea.planding.domain.chat.entity.ChatMessage; import com.tukorea.planding.domain.chat.repository.ChatMessageRepository; import com.tukorea.planding.domain.group.service.query.UserGroupQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -30,7 +31,7 @@ public class ChatService { private final UserGroupQueryService userGroupQueryService; public MessageResponse sendMessage(String sender, MessageRequest messageDTO, String groupCode) { - User user = userQueryService.getUserByUserCode(sender); + UserDomain user = userQueryService.getUserByUserCode(sender); ChatMessage chatMessage = ChatMessage.builder() .content(messageDTO.getContent()) @@ -53,8 +54,8 @@ public MessageResponse sendMessage(String sender, MessageRequest messageDTO, Str return response; } - public List getMessages(UserInfo userInfo, String groupCode) { - if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode())) { + public List getMessages(UserResponse userResponse, String groupCode) { + if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode())) { throw new BusinessException(ErrorCode.ACCESS_DENIED); } diff --git a/src/main/java/com/tukorea/planding/domain/group/controller/GroupFavoriteController.java b/src/main/java/com/tukorea/planding/domain/group/controller/GroupFavoriteController.java index cb32f0a..0be5af6 100644 --- a/src/main/java/com/tukorea/planding/domain/group/controller/GroupFavoriteController.java +++ b/src/main/java/com/tukorea/planding/domain/group/controller/GroupFavoriteController.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.group.dto.response.GroupFavoriteResponse; import com.tukorea.planding.domain.group.dto.response.GroupResponse; import com.tukorea.planding.domain.group.service.GroupFavoriteService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -24,21 +24,21 @@ public class GroupFavoriteController { @Operation(summary = "즐겨찾기 그룹 조회") @GetMapping() - public CommonResponse> searchFavorite(@AuthenticationPrincipal UserInfo userInfo) { - return CommonUtils.success(groupFavoriteService.findFavoriteGroupsByUser(userInfo)); + public CommonResponse> searchFavorite(@AuthenticationPrincipal UserResponse userResponse) { + return CommonUtils.success(groupFavoriteService.findFavoriteGroupsByUser(userResponse)); } @Operation(summary = "그룹 즐겨찾기 추가") @PostMapping("/{groupCode}") - public CommonResponse addFavorite(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - GroupFavoriteResponse response = groupFavoriteService.addFavorite(userInfo, groupCode); + public CommonResponse addFavorite(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + GroupFavoriteResponse response = groupFavoriteService.addFavorite(userResponse, groupCode); return CommonUtils.success(response); } @Operation(summary = "그룹 즐겨찾기 해제") @DeleteMapping("/{groupCode}") - public CommonResponse deleteFavorite(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - groupFavoriteService.deleteFavorite(userInfo, groupCode); + public CommonResponse deleteFavorite(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + groupFavoriteService.deleteFavorite(userResponse, groupCode); return CommonUtils.success("즐겨찾기 해제 완료."); } diff --git a/src/main/java/com/tukorea/planding/domain/group/controller/GroupInviteController.java b/src/main/java/com/tukorea/planding/domain/group/controller/GroupInviteController.java index db1d171..c9a0122 100644 --- a/src/main/java/com/tukorea/planding/domain/group/controller/GroupInviteController.java +++ b/src/main/java/com/tukorea/planding/domain/group/controller/GroupInviteController.java @@ -6,7 +6,7 @@ import com.tukorea.planding.domain.group.dto.response.GroupInviteAcceptResponse; import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse; import com.tukorea.planding.domain.group.service.GroupInviteService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -24,28 +24,28 @@ public class GroupInviteController { @Operation(summary = "유저에게 초대를 보낸다") @PostMapping() - public CommonResponse invite(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupInviteRequest groupInviteRequest) { - return CommonUtils.success(groupInviteService.inviteGroupRoom(userInfo, groupInviteRequest)); + public CommonResponse invite(@AuthenticationPrincipal UserResponse userResponse, @RequestBody GroupInviteRequest groupInviteRequest) { + return CommonUtils.success(groupInviteService.inviteGroupRoom(userResponse, groupInviteRequest)); } @Operation(summary = "초대를 수락한다") @GetMapping("/accept/{groupCode}/{inviteCode}") - public CommonResponse accept(@AuthenticationPrincipal UserInfo userInfo, @PathVariable(name = "groupCode") String groupCode, @PathVariable(name = "inviteCode") String code) { - GroupInviteAcceptResponse response = groupInviteService.acceptInvitation(userInfo, code, groupCode); + public CommonResponse accept(@AuthenticationPrincipal UserResponse userResponse, @PathVariable(name = "groupCode") String groupCode, @PathVariable(name = "inviteCode") String code) { + GroupInviteAcceptResponse response = groupInviteService.acceptInvitation(userResponse, code, groupCode); return CommonUtils.success(response); } @Operation(summary = "초대를 받은 목록", description = "아직 초대의 상태를 바꾸지 않은 경우만") @GetMapping() - public CommonResponse> getInvitations(@AuthenticationPrincipal UserInfo userInfo) { - List groupInviteResponse = groupInviteService.getInvitations(userInfo); + public CommonResponse> getInvitations(@AuthenticationPrincipal UserResponse userResponse) { + List groupInviteResponse = groupInviteService.getInvitations(userResponse); return CommonUtils.success(groupInviteResponse); } @Operation(summary = "초대를 거절한다.") @DeleteMapping("/decline/{inviteCode}") - public CommonResponse declineInvitation(@AuthenticationPrincipal UserInfo userInfo, @PathVariable(name = "inviteCode") String code) { - groupInviteService.declineInvitation(userInfo, code); + public CommonResponse declineInvitation(@AuthenticationPrincipal UserResponse userResponse, @PathVariable(name = "inviteCode") String code) { + groupInviteService.declineInvitation(userResponse, code); return CommonUtils.success("거절하였습니다."); } } diff --git a/src/main/java/com/tukorea/planding/domain/group/controller/GroupRoomController.java b/src/main/java/com/tukorea/planding/domain/group/controller/GroupRoomController.java index c7f1568..fbec8d7 100644 --- a/src/main/java/com/tukorea/planding/domain/group/controller/GroupRoomController.java +++ b/src/main/java/com/tukorea/planding/domain/group/controller/GroupRoomController.java @@ -7,12 +7,11 @@ import com.tukorea.planding.domain.group.dto.response.GroupInformationResponse; import com.tukorea.planding.domain.group.dto.response.GroupResponse; import com.tukorea.planding.domain.group.service.GroupRoomService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; -import org.springframework.data.web.PageableDefault; import org.springframework.http.MediaType; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -30,49 +29,49 @@ public class GroupRoomController { @Operation(summary = "메인페이지 API", description = "내 그룹 가져오기") @GetMapping("/paging") - public CommonResponse> getAllGroupRoomByUser(@AuthenticationPrincipal UserInfo userInfo, + public CommonResponse> getAllGroupRoomByUser(@AuthenticationPrincipal UserResponse userResponse, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "11") int size) { PageRequest pageRequest = PageRequest.of(page, size); - List groupResponses = groupRoomService.getAllGroupRoomByUser(userInfo, pageRequest); + List groupResponses = groupRoomService.getAllGroupRoomByUser(userResponse, pageRequest); return CommonUtils.success(groupResponses); } @Operation(summary = "그룹 정보 조회") @GetMapping("/{groupCode}") - public CommonResponse getUserByGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - GroupInformationResponse responses = groupRoomService.getGroupUsers(userInfo, groupCode); + public CommonResponse getUserByGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + GroupInformationResponse responses = groupRoomService.getGroupUsers(userResponse, groupCode); return CommonUtils.success(responses); } @Operation(summary = "그룹 생성") @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public CommonResponse createGroupRoom(@AuthenticationPrincipal UserInfo userInfo, + public CommonResponse createGroupRoom(@AuthenticationPrincipal UserResponse userResponse, @RequestPart(value = "request") GroupCreateRequest createGroupRoom, @RequestPart(value = "thumbnail", required = false) MultipartFile thumbnailFile) { - GroupResponse groupResponse = groupRoomService.createGroupRoom(userInfo, createGroupRoom, thumbnailFile); + GroupResponse groupResponse = groupRoomService.createGroupRoom(userResponse, createGroupRoom, thumbnailFile); return CommonUtils.success(groupResponse); } @Operation(summary = "그룹 정보 수정") @PatchMapping() - public CommonResponse updateGroupNameOrDescription(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupUpdateRequest groupUpdateRequest) { - GroupResponse groupResponses = groupRoomService.updateGroupNameOrDescription(userInfo, groupUpdateRequest); + public CommonResponse updateGroupNameOrDescription(@AuthenticationPrincipal UserResponse userResponse, @RequestBody GroupUpdateRequest groupUpdateRequest) { + GroupResponse groupResponses = groupRoomService.updateGroupNameOrDescription(userResponse, groupUpdateRequest); return CommonUtils.success(groupResponses); } @Operation(summary = "그룹 삭제") @DeleteMapping("/{groupCode}") - public CommonResponse deleteGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - groupRoomService.deleteGroup(userInfo, groupCode); + public CommonResponse deleteGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + groupRoomService.deleteGroup(userResponse, groupCode); return CommonUtils.success("그룹삭제 완료."); } @Operation(summary = "그룹 나가기") @DeleteMapping("/leave/{groupCode}") - public CommonResponse leaveGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) { - groupRoomService.leaveGroup(userInfo, groupCode); + public CommonResponse leaveGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) { + groupRoomService.leaveGroup(userResponse, groupCode); return CommonUtils.success("그룹 나가기 완료."); } } diff --git a/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupFavoriteDomain.java b/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupFavoriteDomain.java new file mode 100644 index 0000000..c6e4770 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupFavoriteDomain.java @@ -0,0 +1,15 @@ +package com.tukorea.planding.domain.group.entity.domain; + +import com.tukorea.planding.domain.group.entity.GroupRoom; +import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; + +public class GroupFavoriteDomain { + + private Long id; + + private UserDomain user; + + private GroupRoomDomain groupRoom; + +} diff --git a/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupRoomDomain.java b/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupRoomDomain.java new file mode 100644 index 0000000..3413145 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/group/entity/domain/GroupRoomDomain.java @@ -0,0 +1,36 @@ +package com.tukorea.planding.domain.group.entity.domain; + +import com.tukorea.planding.domain.group.entity.GroupFavorite; +import com.tukorea.planding.domain.group.entity.UserGroup; +import com.tukorea.planding.domain.schedule.entity.GroupSchedule; +import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; +import jakarta.persistence.JoinColumn; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class GroupRoomDomain { + private Long id; + + private String name; + + private String description; + + private UserDomain owner; + + private String groupCode; // 그룹방 고유 식별값 + + private String thumbnail; + + private boolean alarm = true; + + private final Set userGroups = new HashSet<>(); + + private final List groupSchedules = new ArrayList<>(); + + private final List groupFavorites = new ArrayList<>(); + +} diff --git a/src/main/java/com/tukorea/planding/domain/group/entity/domain/UserGroupDomain.java b/src/main/java/com/tukorea/planding/domain/group/entity/domain/UserGroupDomain.java new file mode 100644 index 0000000..cefc226 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/group/entity/domain/UserGroupDomain.java @@ -0,0 +1,15 @@ +package com.tukorea.planding.domain.group.entity.domain; + + +import com.tukorea.planding.domain.group.entity.GroupRoom; +import com.tukorea.planding.domain.user.entity.UserDomain; + +public class UserGroupDomain { + private Long id; + private UserDomain user; + + private GroupRoomDomain groupRoom; + + private boolean isConnected; + +} diff --git a/src/main/java/com/tukorea/planding/domain/group/repository/usergroup/UserGroupRepositoryCustomImpl.java b/src/main/java/com/tukorea/planding/domain/group/repository/usergroup/UserGroupRepositoryCustomImpl.java index b597eed..eeb7a48 100644 --- a/src/main/java/com/tukorea/planding/domain/group/repository/usergroup/UserGroupRepositoryCustomImpl.java +++ b/src/main/java/com/tukorea/planding/domain/group/repository/usergroup/UserGroupRepositoryCustomImpl.java @@ -11,7 +11,6 @@ import static com.tukorea.planding.domain.group.entity.QUserGroup.userGroup; import static com.tukorea.planding.domain.user.entity.QUser.user; - @Repository @RequiredArgsConstructor public class UserGroupRepositoryCustomImpl implements UserGroupRepositoryCustom { diff --git a/src/main/java/com/tukorea/planding/domain/group/service/GroupFavoriteService.java b/src/main/java/com/tukorea/planding/domain/group/service/GroupFavoriteService.java index aa6a0b9..9afbedb 100644 --- a/src/main/java/com/tukorea/planding/domain/group/service/GroupFavoriteService.java +++ b/src/main/java/com/tukorea/planding/domain/group/service/GroupFavoriteService.java @@ -6,8 +6,9 @@ import com.tukorea.planding.domain.group.entity.GroupRoom; import com.tukorea.planding.domain.group.repository.favorite.GroupFavoriteRepository; import com.tukorea.planding.domain.group.service.query.GroupQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -32,33 +33,33 @@ public class GroupFavoriteService { @Transactional(readOnly = true) - public List findFavoriteGroupsByUser(UserInfo userInfo) { - return groupFavoriteRepository.findFavoriteGroupsByUser(userInfo.getId()) + public List findFavoriteGroupsByUser(UserResponse userResponse) { + return groupFavoriteRepository.findFavoriteGroupsByUser(userResponse.getId()) .stream() .map(GroupFavorite::getGroupRoom) .map(GroupResponse::from) .collect(Collectors.toList()); } - public GroupFavoriteResponse addFavorite(UserInfo userInfo, String groupCode) { - log.info("Add 그룹 즐겨찾기 for userCodes {} and group {}", userInfo.getUserCode(), groupCode); - if (groupFavoriteRepository.existsByUserAndGroupRoom(userInfo.getUserCode(), groupCode)) { + public GroupFavoriteResponse addFavorite(UserResponse userResponse, String groupCode) { + log.info("Add 그룹 즐겨찾기 for userCodes {} and group {}", userResponse.getUserCode(), groupCode); + if (groupFavoriteRepository.existsByUserAndGroupRoom(userResponse.getUserCode(), groupCode)) { throw new BusinessException(ErrorCode.FAVORITE_ALREADY_ADD); } - User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + UserDomain user = userQueryService.getUserByUserCode(userResponse.getUserCode()); GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); - GroupFavorite groupFavorite = GroupFavorite.createGroupFavorite(user, groupRoom); + GroupFavorite groupFavorite = GroupFavorite.createGroupFavorite(User.fromModel(user), groupRoom); GroupFavorite save = groupFavoriteRepository.save(groupFavorite); - log.info("그룹 즐겨찾기 등록완료 for userCodes {} and group {}", userInfo.getUserCode(), groupCode); + log.info("그룹 즐겨찾기 등록완료 for userCodes {} and group {}", userResponse.getUserCode(), groupCode); return GroupFavoriteResponse.from(save); } - public void deleteFavorite(UserInfo userInfo, String groupCode) { - log.info("Deleting 그룹 즐겨찾기 for userCodes {} and group {}", userInfo.getUserCode(), groupCode); + public void deleteFavorite(UserResponse userResponse, String groupCode) { + log.info("Deleting 그룹 즐겨찾기 for userCodes {} and group {}", userResponse.getUserCode(), groupCode); try { - groupFavoriteRepository.deleteByUserIdAndGroupRoomId(userInfo.getId(), groupCode); + groupFavoriteRepository.deleteByUserIdAndGroupRoomId(userResponse.getId(), groupCode); } catch (EmptyResultDataAccessException e) { throw new BusinessException(ErrorCode.FAVORITE_ALREADY_DELETE); } diff --git a/src/main/java/com/tukorea/planding/domain/group/service/GroupInviteService.java b/src/main/java/com/tukorea/planding/domain/group/service/GroupInviteService.java index 6c68fdf..4f029d0 100644 --- a/src/main/java/com/tukorea/planding/domain/group/service/GroupInviteService.java +++ b/src/main/java/com/tukorea/planding/domain/group/service/GroupInviteService.java @@ -10,8 +10,9 @@ import com.tukorea.planding.domain.group.service.query.GroupQueryService; import com.tukorea.planding.domain.group.service.query.UserGroupQueryService; import com.tukorea.planding.domain.notify.service.NotificationEventHandler; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -33,13 +34,13 @@ public class GroupInviteService { private final GroupQueryService groupQueryService; private final UserGroupQueryService userGroupQueryService; private final NotificationEventHandler eventHandler; - private final RedisGroupInviteService redisGroupInviteService; + private final RedisGroupInviteServiceImpl redisGroupInviteServiceImpl; private final ChatRoomRepository chatRoomRepository; - public GroupInviteMessageResponse inviteGroupRoom(UserInfo userInfo, GroupInviteRequest groupInviteRequest) { + public GroupInviteMessageResponse inviteGroupRoom(UserResponse userResponse, GroupInviteRequest groupInviteRequest) { // 초대하는 사용자와 초대 대상 사용자가 같은지 확인 - if (userInfo.getUserCode().equals(groupInviteRequest.userCode())) { + if (userResponse.getUserCode().equals(groupInviteRequest.userCode())) { throw new BusinessException(ErrorCode.CANNOT_INVITE_YOURSELF); } // 그룹이 존재하는지 @@ -51,29 +52,29 @@ public GroupInviteMessageResponse inviteGroupRoom(UserInfo userInfo, GroupInvite throw new BusinessException(ErrorCode.USER_ALREADY_IN_GROUP); } // 그룹안에 속해있는지 - if (!groupQueryService.existGroupInUser(groupInviteRequest.groupCode(), userInfo.getUserCode())) { + if (!groupQueryService.existGroupInUser(groupInviteRequest.groupCode(), userResponse.getUserCode())) { throw new BusinessException(ErrorCode.ACCESS_DENIED); } GroupRoom group = groupQueryService.getGroupByCode(groupInviteRequest.groupCode()); - GroupInviteMessageResponse groupInviteMessageResponse = GroupInviteMessageResponse.create("IN" + UUID.randomUUID(), group.getGroupCode(), group.getName(), groupInviteRequest.userCode(), userInfo.getUsername(), GroupResponse.from(group), LocalDateTime.now()); + GroupInviteMessageResponse groupInviteMessageResponse = GroupInviteMessageResponse.create("IN" + UUID.randomUUID(), group.getGroupCode(), group.getName(), groupInviteRequest.userCode(), userResponse.getUsername(), GroupResponse.from(group), LocalDateTime.now()); - redisGroupInviteService.createInvitation(groupInviteRequest.userCode(), groupInviteMessageResponse); + redisGroupInviteServiceImpl.createInvitation(groupInviteRequest.userCode(), groupInviteMessageResponse); eventHandler.notifyInvitation(groupInviteRequest.userCode(), group.getName()); return groupInviteMessageResponse; } - public GroupInviteAcceptResponse acceptInvitation(UserInfo userInfo, String code, String groupCode) { - User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + public GroupInviteAcceptResponse acceptInvitation(UserResponse userResponse, String code, String groupCode) { + UserDomain user = userQueryService.getUserByUserCode(userResponse.getUserCode()); GroupRoom group = groupQueryService.getGroupByCode(groupCode); - final UserGroup userGroup = UserGroup.createUserGroup(user, group); + final UserGroup userGroup = UserGroup.createUserGroup(User.fromModel(user), group); userGroupQueryService.save(userGroup); - redisGroupInviteService.deleteInvitation(userInfo.getUserCode(), code); + redisGroupInviteServiceImpl.deleteInvitation(userResponse.getUserCode(), code); /** 채팅방 참여 **/ TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @@ -88,11 +89,11 @@ public void afterCommit() { } @Transactional(readOnly = true) - public List getInvitations(UserInfo userInfo) { - return redisGroupInviteService.getAllInvitations(userInfo.getUserCode()); + public List getInvitations(UserResponse userResponse) { + return redisGroupInviteServiceImpl.getAllInvitations(userResponse.getUserCode()); } - public void declineInvitation(UserInfo userInfo, String inviteCode) { - redisGroupInviteService.deleteInvitation(userInfo.getUserCode(), inviteCode); + public void declineInvitation(UserResponse userResponse, String inviteCode) { + redisGroupInviteServiceImpl.deleteInvitation(userResponse.getUserCode(), inviteCode); } } diff --git a/src/main/java/com/tukorea/planding/domain/group/service/GroupRoomService.java b/src/main/java/com/tukorea/planding/domain/group/service/GroupRoomService.java index 5f4a5e7..8955c5b 100644 --- a/src/main/java/com/tukorea/planding/domain/group/service/GroupRoomService.java +++ b/src/main/java/com/tukorea/planding/domain/group/service/GroupRoomService.java @@ -10,9 +10,10 @@ import com.tukorea.planding.domain.group.entity.UserGroup; import com.tukorea.planding.domain.group.service.query.GroupQueryService; import com.tukorea.planding.domain.group.service.query.UserGroupQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.dto.UserInfoSimple; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -43,12 +44,12 @@ public class GroupRoomService { private final ChatRoomRepository chatRoomRepository; - public GroupResponse createGroupRoom(UserInfo userInfo, GroupCreateRequest createGroupRoom, MultipartFile thumbnailFile) { - User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + public GroupResponse createGroupRoom(UserResponse userResponse, GroupCreateRequest createGroupRoom, MultipartFile thumbnailFile) { + UserDomain user = userQueryService.getUserByUserCode(userResponse.getUserCode()); - GroupRoom newGroupRoom = groupRoomFactory.createGroupRoom(createGroupRoom, user, thumbnailFile); + GroupRoom newGroupRoom = groupRoomFactory.createGroupRoom(createGroupRoom, User.fromModel(user), thumbnailFile); GroupRoom savedGroupRoom = groupQueryService.createGroup(newGroupRoom); - final UserGroup userGroup = UserGroup.createUserGroup(user, savedGroupRoom); + final UserGroup userGroup = UserGroup.createUserGroup(User.fromModel(user), savedGroupRoom); // 중간테이블에 유저, 그룹 정보 저장 userGroupQueryService.save(userGroup); @@ -61,11 +62,11 @@ public void afterCommit() { return toGroupResponse(newGroupRoom); } - public GroupResponse updateGroupNameOrDescription(UserInfo userInfo, GroupUpdateRequest groupUpdateRequest) { + public GroupResponse updateGroupNameOrDescription(UserResponse userResponse, GroupUpdateRequest groupUpdateRequest) { GroupRoom groupRoom = groupQueryService.getGroupById(groupUpdateRequest.groupId()); // TODO 그룹의 팀원도 변경가능하도록 - validateOwner(userInfo,groupRoom); + validateOwner(userResponse,groupRoom); groupRoom.updateName(groupUpdateRequest.name()); groupRoom.updateDescription(groupUpdateRequest.description()); @@ -73,28 +74,28 @@ public GroupResponse updateGroupNameOrDescription(UserInfo userInfo, GroupUpdate return toGroupResponse(groupRoom); } - public void deleteGroup(UserInfo userInfo, String groupCode) { + public void deleteGroup(UserResponse userResponse, String groupCode) { GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); - validateOwner(userInfo,groupRoom); + validateOwner(userResponse,groupRoom); groupQueryService.delete(groupRoom); } // 유저가 속한 그룹룸 가져오기 - public List getAllGroupRoomByUser(UserInfo userInfo, PageRequest request) { - List groupRooms = groupQueryService.findGroupsByUserId(userInfo.getId(), request); + public List getAllGroupRoomByUser(UserResponse userResponse, PageRequest request) { + List groupRooms = groupQueryService.findGroupsByUserId(userResponse.getId(), request); return groupRooms.stream() .map(this::toGroupResponse) .collect(Collectors.toList()); } @Transactional(readOnly = true) - public GroupInformationResponse getGroupUsers(UserInfo userInfo, String groupCode) { + public GroupInformationResponse getGroupUsers(UserResponse userResponse, String groupCode) { GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); boolean isMember = groupRoom.getUserGroups().stream() - .anyMatch(userGroup -> userGroup.getUser().getUserCode().equals(userInfo.getUserCode())); + .anyMatch(userGroup -> userGroup.getUser().getUserCode().equals(userResponse.getUserCode())); if (!isMember) { throw new BusinessException(ErrorCode.ACCESS_DENIED); @@ -114,17 +115,17 @@ public GroupInformationResponse getGroupUsers(UserInfo userInfo, String groupCod .description(groupRoom.getDescription()) .createdBy(LocalDate.from(groupRoom.getCreatedDate())) .thumbnailUrl(groupRoom.getThumbnail()) - .isGroupAdmin(isGroupOwner(userInfo,groupRoom)) + .isGroupAdmin(isGroupOwner(userResponse,groupRoom)) .isFavorite(groupRoom.getGroupFavorites().stream().anyMatch(a -> a.getGroupRoom().getGroupCode().equals(groupCode))) .isAlarm(groupRoom.isAlarm()) .build(); } - public void leaveGroup(UserInfo userInfo, String groupCode) { + public void leaveGroup(UserResponse userResponse, String groupCode) { GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); - UserGroup userGroup = userGroupQueryService.findByUserIdAndGroupId(userInfo.getId(), groupRoom.getId()); + UserGroup userGroup = userGroupQueryService.findByUserIdAndGroupId(userResponse.getId(), groupRoom.getId()); - if (isGroupOwner(userInfo,groupRoom)) { + if (isGroupOwner(userResponse,groupRoom)) { groupQueryService.delete(groupRoom); } else { userGroupQueryService.delete(userGroup); @@ -141,14 +142,14 @@ private GroupResponse toGroupResponse(GroupRoom groupRoom) { return GroupResponse.from(groupRoom); } - private void validateOwner(UserInfo userInfo, GroupRoom groupRoom) { - if (!groupRoom.getOwner().getUserCode().equals(userInfo.getUserCode())) { + private void validateOwner(UserResponse userResponse, GroupRoom groupRoom) { + if (!groupRoom.getOwner().getUserCode().equals(userResponse.getUserCode())) { throw new BusinessException(ErrorCode.ACCESS_DENIED); } } - private boolean isGroupOwner(UserInfo userInfo, GroupRoom groupRoom) { - return groupRoom.getOwner().getUserCode().equals(userInfo.getUserCode()); + private boolean isGroupOwner(UserResponse userResponse, GroupRoom groupRoom) { + return groupRoom.getOwner().getUserCode().equals(userResponse.getUserCode()); } public void updateGroupRoomAlarmSetting(String userCode, String groupCode, boolean alarmEnabled) { diff --git a/src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteService.java b/src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteServiceImpl.java similarity index 62% rename from src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteService.java rename to src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteServiceImpl.java index eac4f0e..6584281 100644 --- a/src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteService.java +++ b/src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteServiceImpl.java @@ -1,29 +1,28 @@ package com.tukorea.planding.domain.group.service; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.tukorea.planding.common.JsonConverter; import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse; +import com.tukorea.planding.domain.group.service.port.RedisGroupInviteService; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service @RequiredArgsConstructor -public class RedisGroupInviteService { +public class RedisGroupInviteServiceImpl implements RedisGroupInviteService { private final StringRedisTemplate redisTemplate; - private final ObjectMapper objectMapper; + private final JsonConverter jsonConverter; // 초대 생성 public void createInvitation(String userCode, GroupInviteMessageResponse inviteDTO) { String key = "userInvites:" + userCode; // 유저별 키 String field = inviteDTO.getInviteCode(); // 초대 코드를 필드로 사용 - String value = convertObjectToJson(inviteDTO); // 초대 정보를 JSON 문자열로 변환 + String value = jsonConverter.convertObjectToJson(inviteDTO); // 초대 정보를 JSON 문자열로 변환 if (value != null) { redisTemplate.opsForHash().put(key, field, value); @@ -36,7 +35,7 @@ public List getAllInvitations(String userCode) { String key = "userInvites:" + userCode; List values = redisTemplate.opsForHash().values(key); return values.stream() - .map(value -> convertJsonToObject((String) value, GroupInviteMessageResponse.class)) + .map(value -> jsonConverter.convertJsonToObject((String) value, GroupInviteMessageResponse.class)) .collect(Collectors.toList()); } @@ -45,20 +44,4 @@ public void deleteInvitation(String userCode, String inviteCode) { String key = "userInvites:" + userCode; redisTemplate.opsForHash().delete(key, inviteCode); } - - private String convertObjectToJson(Object obj) { - try { - return objectMapper.writeValueAsString(obj); - } catch (JsonProcessingException e) { - return null; - } - } - - private T convertJsonToObject(String json, Class clazz) { - try { - return objectMapper.readValue(json, clazz); - } catch (IOException e) { - return null; - } - } } diff --git a/src/main/java/com/tukorea/planding/domain/group/service/UserGroupService.java b/src/main/java/com/tukorea/planding/domain/group/service/UserGroupService.java index eb2600d..9a5db48 100644 --- a/src/main/java/com/tukorea/planding/domain/group/service/UserGroupService.java +++ b/src/main/java/com/tukorea/planding/domain/group/service/UserGroupService.java @@ -5,6 +5,7 @@ import com.tukorea.planding.domain.group.repository.normal.GroupRoomRepository; import com.tukorea.planding.domain.group.repository.usergroup.UserGroupRepository; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -24,7 +25,7 @@ public class UserGroupService { public void updateConnectionStatus(String userCode, String groupCode, boolean isConnected) { - User user = userQueryService.getUserByUserCode(userCode); + UserDomain user = userQueryService.getUserByUserCode(userCode); GroupRoom groupRoom = groupRoomRepository.findByGroupCode(groupCode) .orElseThrow(() -> new BusinessException(ErrorCode.GROUP_ROOM_NOT_FOUND)); diff --git a/src/main/java/com/tukorea/planding/domain/group/service/port/RedisGroupInviteService.java b/src/main/java/com/tukorea/planding/domain/group/service/port/RedisGroupInviteService.java new file mode 100644 index 0000000..2458c20 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/group/service/port/RedisGroupInviteService.java @@ -0,0 +1,14 @@ +package com.tukorea.planding.domain.group.service.port; + +import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse; + +import java.util.List; + +public interface RedisGroupInviteService { + void createInvitation(String userCode, GroupInviteMessageResponse inviteDTO); + + List getAllInvitations(String userCode); + + void deleteInvitation(String userCode, String inviteCode); + +} diff --git a/src/main/java/com/tukorea/planding/domain/notify/controller/FireBaseController.java b/src/main/java/com/tukorea/planding/domain/notify/controller/FireBaseController.java index 4ce9f54..8e4b89c 100644 --- a/src/main/java/com/tukorea/planding/domain/notify/controller/FireBaseController.java +++ b/src/main/java/com/tukorea/planding/domain/notify/controller/FireBaseController.java @@ -3,7 +3,7 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; import com.tukorea.planding.domain.notify.dto.FcmDTO; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -20,8 +20,8 @@ public class FireBaseController { private final UserService userService; @PostMapping("/token") - public CommonResponse saveNotification(@AuthenticationPrincipal UserInfo userInfo, @RequestBody FcmDTO fcmDTO) { - userService.updateFcmToken(userInfo.getUserCode(), fcmDTO); + public CommonResponse saveNotification(@AuthenticationPrincipal UserResponse userResponse, @RequestBody FcmDTO fcmDTO) { + userService.updateFcmToken(userResponse.getUserCode(), fcmDTO); return CommonUtils.successWithEmptyData(); } } diff --git a/src/main/java/com/tukorea/planding/domain/notify/controller/NotifyController.java b/src/main/java/com/tukorea/planding/domain/notify/controller/NotifyController.java index 0179d38..1576ac4 100644 --- a/src/main/java/com/tukorea/planding/domain/notify/controller/NotifyController.java +++ b/src/main/java/com/tukorea/planding/domain/notify/controller/NotifyController.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.notify.dto.NotificationReadRequest; import com.tukorea.planding.domain.notify.dto.NotificationScheduleResponse; import com.tukorea.planding.domain.notify.service.NotificationHandler; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -27,21 +27,21 @@ public class NotifyController { //TODO 어떤 방 알림을 구독할지 정해야함 @Operation(description = "기본적인 알림을 받는다") @GetMapping(value = "/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) - public SseEmitter subscribe(@AuthenticationPrincipal UserInfo userInfo) { - return notificationHandler.subscribe(userInfo.getUserCode()); + public SseEmitter subscribe(@AuthenticationPrincipal UserResponse userResponse) { + return notificationHandler.subscribe(userResponse.getUserCode()); } @Operation(description = "스케줄 타입 알람 목록 가져온다") @GetMapping("/schedules") - public CommonResponse> getNotifications(@AuthenticationPrincipal UserInfo userInfo){ - List response = notificationHandler.getNotifications(userInfo); + public CommonResponse> getNotifications(@AuthenticationPrincipal UserResponse userResponse){ + List response = notificationHandler.getNotifications(userResponse); return CommonUtils.success(response); } @Operation(description = "스케줄 타입 알람을 삭제한다") @DeleteMapping("/{scheduleId}") - public CommonResponse deleteNotification(@AuthenticationPrincipal UserInfo userInfo,@PathVariable Long scheduleId){ - notificationHandler.deleteNotification(userInfo,scheduleId); + public CommonResponse deleteNotification(@AuthenticationPrincipal UserResponse userResponse, @PathVariable Long scheduleId){ + notificationHandler.deleteNotification(userResponse,scheduleId); return CommonUtils.successWithEmptyData(); } diff --git a/src/main/java/com/tukorea/planding/domain/notify/controller/UserNotificationSettingController.java b/src/main/java/com/tukorea/planding/domain/notify/controller/UserNotificationSettingController.java index d016850..5835d10 100644 --- a/src/main/java/com/tukorea/planding/domain/notify/controller/UserNotificationSettingController.java +++ b/src/main/java/com/tukorea/planding/domain/notify/controller/UserNotificationSettingController.java @@ -2,9 +2,8 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; -import com.tukorea.planding.domain.group.dto.response.GroupResponse; import com.tukorea.planding.domain.group.service.GroupRoomService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -12,8 +11,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import java.util.List; - @Tag(name = "User Setting", description = "사용자 알림 설정 관련") @RestController @RequiredArgsConstructor @@ -25,17 +22,17 @@ public class UserNotificationSettingController { @Operation(description = "개인 스케줄 알림 설정을 업데이트한다") @PutMapping("/alarm") - public CommonResponse updateAlarmSetting(@AuthenticationPrincipal UserInfo userInfo, @RequestParam boolean alarmEnabled) { - userService.updateAlarmSetting(userInfo.getUserCode(), alarmEnabled); + public CommonResponse updateAlarmSetting(@AuthenticationPrincipal UserResponse userResponse, @RequestParam boolean alarmEnabled) { + userService.updateAlarmSetting(userResponse.getUserCode(), alarmEnabled); return CommonUtils.successWithEmptyData(); } @Operation(description = "그룹 스케줄 알림 설정을 업데이트한다") @PutMapping("/{groupCode}/alarm") - public CommonResponse updateGroupRoomAlarmSetting(@AuthenticationPrincipal UserInfo userInfo, + public CommonResponse updateGroupRoomAlarmSetting(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode, @RequestParam boolean alarmEnabled) { - groupRoomService.updateGroupRoomAlarmSetting(userInfo.getUserCode(), groupCode, alarmEnabled); + groupRoomService.updateGroupRoomAlarmSetting(userResponse.getUserCode(), groupCode, alarmEnabled); return CommonUtils.successWithEmptyData(); } } diff --git a/src/main/java/com/tukorea/planding/domain/notify/service/NotificationHandler.java b/src/main/java/com/tukorea/planding/domain/notify/service/NotificationHandler.java index 1c9230e..ad5ba37 100644 --- a/src/main/java/com/tukorea/planding/domain/notify/service/NotificationHandler.java +++ b/src/main/java/com/tukorea/planding/domain/notify/service/NotificationHandler.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.notify.entity.Notification; import com.tukorea.planding.domain.notify.repository.NotificationRepository; import com.tukorea.planding.domain.notify.service.sse.SseEmitterService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; import lombok.RequiredArgsConstructor; @@ -44,12 +44,12 @@ public void markNotificationAsRead(NotificationReadRequest notificationReadReque } @Transactional(readOnly = true) - public List getNotifications(UserInfo userInfo) { - return notificationRepository.findByUserCode(userInfo.getUserCode()); + public List getNotifications(UserResponse userResponse) { + return notificationRepository.findByUserCode(userResponse.getUserCode()); } - public void deleteNotification(UserInfo userInfo, Long scheduleId) { + public void deleteNotification(UserResponse userResponse, Long scheduleId) { notificationRepository.deleteById(scheduleId); } } diff --git a/src/main/java/com/tukorea/planding/domain/notify/service/schedule/PersonalScheduleNotificationHandler.java b/src/main/java/com/tukorea/planding/domain/notify/service/schedule/PersonalScheduleNotificationHandler.java index fdfa81c..f892e5a 100644 --- a/src/main/java/com/tukorea/planding/domain/notify/service/schedule/PersonalScheduleNotificationHandler.java +++ b/src/main/java/com/tukorea/planding/domain/notify/service/schedule/PersonalScheduleNotificationHandler.java @@ -8,8 +8,9 @@ import com.tukorea.planding.domain.notify.service.ScheduleNotificationService; import com.tukorea.planding.domain.notify.service.fcm.FCMService; import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import lombok.RequiredArgsConstructor; @@ -35,7 +36,7 @@ public class PersonalScheduleNotificationHandler implements NotificationHandler @Override public void sendNotification(NotificationDTO request) { try { - User user = userQueryService.getUserByUserCode(request.getUserCode()); + UserDomain user = userQueryService.getUserByUserCode(request.getUserCode()); if (!user.isAlarm()) { return; } @@ -90,7 +91,7 @@ public void registerScheduleBeforeOneHour(String userCode, PersonalScheduleRespo } } - public void updateScheduleBeforeOneHour(Long scheduleId, PersonalScheduleResponse request, UserInfo userInfo) { + public void updateScheduleBeforeOneHour(Long scheduleId, PersonalScheduleResponse request, UserResponse userResponse) { try { NotificationDTO notification = scheduleNotificationService.getNotificationByScheduleId(scheduleId); if (notification != null) { @@ -100,10 +101,10 @@ public void updateScheduleBeforeOneHour(Long scheduleId, PersonalScheduleRespons LocalTime starTime = LocalTime.of(request.startTime(), 0); LocalDateTime oneHourBefore = LocalDateTime.of(request.scheduleDate(), starTime).minusHours(1); - NotificationDTO oneHourBeforeNotification = NotificationDTO.createPersonalSchedule(userInfo.getUserCode(), request); + NotificationDTO oneHourBeforeNotification = NotificationDTO.createPersonalSchedule(userResponse.getUserCode(), request); scheduleNotificationService.scheduleNotification(oneHourBeforeNotification, oneHourBefore); } catch (Exception e) { - log.error("[Personal Schedule] 1시간 전 알림 업데이트 실패 for userCodes {}: {}", userInfo.getUserCode(), e.getMessage(), e); + log.error("[Personal Schedule] 1시간 전 알림 업데이트 실패 for userCodes {}: {}", userResponse.getUserCode(), e.getMessage(), e); } } diff --git a/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java b/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java index f9403d6..9399d07 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java +++ b/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.planner.dto.*; import com.tukorea.planding.domain.planner.dto.group.PlannerWeekResponse; import com.tukorea.planding.domain.planner.service.GroupPlannerService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -49,22 +49,22 @@ public CommonResponse updatePlanner(StompHeaderAccessor accessor, @Destinatio @Operation(summary = "그룹 스케줄 플래너: 개별조회") @GetMapping("/api/v1/group-rooms/planner/{groupCode}/{plannerId}") - public CommonResponse getPlannerByGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @PathVariable Long plannerId) { - return CommonUtils.success(groupPlannerService.getPlannerByGroup(userInfo, groupCode, plannerId)); + public CommonResponse getPlannerByGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode, @PathVariable Long plannerId) { + return CommonUtils.success(groupPlannerService.getPlannerByGroup(userResponse, groupCode, plannerId)); } @Operation(summary = "그룹 스케줄 플래너: 조회") @GetMapping("/api/v1/group-rooms/{groupCode}/planner/{scheduleId}") - public CommonResponse getPlannersByGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @PathVariable Long scheduleId) { - return CommonUtils.success(groupPlannerService.getPlannersByGroup(userInfo, groupCode, scheduleId)); + public CommonResponse getPlannersByGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode, @PathVariable Long scheduleId) { + return CommonUtils.success(groupPlannerService.getPlannersByGroup(userResponse, groupCode, scheduleId)); } @Operation(summary = "그룹 플래너 주간: 조회") @GetMapping("/api/v1/group-rooms/planner/week/{groupCode}/{startDate}/{endDate}") public CommonResponse> getWeekPlannerByGroup(@PathVariable String groupCode, @PathVariable LocalDate startDate, @PathVariable LocalDate endDate - , @AuthenticationPrincipal UserInfo userInfo) { - return CommonUtils.success(groupPlannerService.findPlannersByGroupCodeAndDateRange(startDate, endDate, groupCode, userInfo)); + , @AuthenticationPrincipal UserResponse userResponse) { + return CommonUtils.success(groupPlannerService.findPlannersByGroupCodeAndDateRange(startDate, endDate, groupCode, userResponse)); } diff --git a/src/main/java/com/tukorea/planding/domain/planner/controller/PersonalPlannerController.java b/src/main/java/com/tukorea/planding/domain/planner/controller/PersonalPlannerController.java index 9771891..f6456d7 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/controller/PersonalPlannerController.java +++ b/src/main/java/com/tukorea/planding/domain/planner/controller/PersonalPlannerController.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.planner.dto.PlannerRequest; import com.tukorea.planding.domain.planner.dto.personal.PersonalPlannerResponse; import com.tukorea.planding.domain.planner.service.PersonalPlannerService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -23,22 +23,22 @@ public class PersonalPlannerController { @Operation(summary = "개인 플래너: 생성") @PostMapping("/personal") public CommonResponse createPersonalPlanner( - @AuthenticationPrincipal UserInfo userInfo, + @AuthenticationPrincipal UserResponse userResponse, @RequestBody PlannerRequest request) { - return CommonUtils.success(plannerService.createPersonalPlanner(userInfo, request)); + return CommonUtils.success(plannerService.createPersonalPlanner(userResponse, request)); } @Operation(summary = "개인 플래너:삭제") @DeleteMapping("/{plannerId}") - public CommonResponse deletePlanner(@AuthenticationPrincipal UserInfo userInfo, @PathVariable Long plannerId) { - plannerService.deletePlanner(userInfo, plannerId); + public CommonResponse deletePlanner(@AuthenticationPrincipal UserResponse userResponse, @PathVariable Long plannerId) { + plannerService.deletePlanner(userResponse, plannerId); return CommonUtils.successWithEmptyData(); } @Operation(summary = "개인 플래너:수정") @PatchMapping("/{plannerId}") - public CommonResponse updatePlanner(@AuthenticationPrincipal UserInfo userInfo, @RequestBody PlannerRequest request, @PathVariable Long plannerId) { - return CommonUtils.success(plannerService.updatePlanner(userInfo, request, plannerId)); + public CommonResponse updatePlanner(@AuthenticationPrincipal UserResponse userResponse, @RequestBody PlannerRequest request, @PathVariable Long plannerId) { + return CommonUtils.success(plannerService.updatePlanner(userResponse, request, plannerId)); } diff --git a/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerDomain.java b/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerDomain.java new file mode 100644 index 0000000..509227a --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerDomain.java @@ -0,0 +1,28 @@ +package com.tukorea.planding.domain.planner.entity.domain; + +import com.tukorea.planding.domain.planner.PlannerStatus; +import com.tukorea.planding.domain.planner.entity.PlannerUser; +import com.tukorea.planding.domain.schedule.entity.Schedule; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +public class PlannerDomain { + private Long id; + + private Integer plannerNumber; + + private String title; + + private String content; + + private PlannerStatus status; + + private LocalDateTime deadline; + + private Schedule schedule; + + private final List users = new ArrayList<>(); + +} diff --git a/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerUserDomain.java b/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerUserDomain.java new file mode 100644 index 0000000..572e297 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/planner/entity/domain/PlannerUserDomain.java @@ -0,0 +1,16 @@ +package com.tukorea.planding.domain.planner.entity.domain; + +import com.tukorea.planding.domain.planner.PlannerRole; +import com.tukorea.planding.domain.planner.entity.Planner; +import com.tukorea.planding.domain.user.entity.User; + +public class PlannerUserDomain { + private Long id; + + private PlannerDomain planner; + + private User user; + + private PlannerRole role; + +} diff --git a/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java b/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java index 1aa7c38..aa2af2a 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java +++ b/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java @@ -16,8 +16,9 @@ import com.tukorea.planding.domain.schedule.entity.Action; import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.service.ScheduleQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -63,12 +64,12 @@ public GroupPlannerResponse createGroupPlanner(String userCode, PlannerRequest r if (!request.getUserCodes().isEmpty()) { request.getUserCodes().stream() .map(userQueryService::getUserByUserCode) // 유저를 조회 - .forEach(user -> planner.getUsers().add(assignUserToPlanner(planner, user, PlannerRole.GENERAL))); // 유저를 플래너에 할당 + .forEach(user -> planner.getUsers().add(assignUserToPlanner(planner, User.fromModel(user), PlannerRole.GENERAL))); // 유저를 플래너에 할당 } - User manager = userQueryService.getUserByUserCode(request.getManagerCode()); - planner.getUsers().add(assignUserToPlanner(planner, manager, PlannerRole.MANAGER)); + UserDomain manager = userQueryService.getUserByUserCode(request.getManagerCode()); + planner.getUsers().add(assignUserToPlanner(planner, User.fromModel(manager), PlannerRole.MANAGER)); return GroupPlannerResponse.fromEntity(planner, Action.CREATE); @@ -115,8 +116,8 @@ private void adjustPlannerNumbers(Schedule schedule, int deletedPlannerNumber) { } } - public PlannerResponse getPlannerByGroup(UserInfo userInfo, String groupCode, Long plannerId) { - if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode())) { + public PlannerResponse getPlannerByGroup(UserResponse userResponse, String groupCode, Long plannerId) { + if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode())) { throw new BusinessException(ErrorCode.ACCESS_DENIED); } Planner planner = plannerRepository.findById(plannerId) @@ -132,8 +133,8 @@ public GroupPlannerResponse updateGroupPlanner(String userCode, String groupCode Planner planner = plannerRepository.findById(request.plannerId()) .orElseThrow(() -> new IllegalArgumentException("Planner not found with id: " + request.plannerId())); - User newManager = userQueryService.getUserByUserCode(request.managerCode()); - planner.updateManager(newManager); + UserDomain newManager = userQueryService.getUserByUserCode(request.managerCode()); + planner.updateManager(User.fromModel(newManager)); updateUsers(planner, request.userCodes()); @@ -158,15 +159,15 @@ private void updateUsers(Planner planner, List newUserCodes) { // 새로운 사용자를 추가 for (String userCode : newUserCodes) { - User user = userQueryService.getUserByUserCode(userCode); + UserDomain user = userQueryService.getUserByUserCode(userCode); if (currentUsers.stream().noneMatch(plannerUser -> plannerUser.getUser().equals(user))) { - assignUserToPlanner(planner, user, PlannerRole.GENERAL); + assignUserToPlanner(planner, User.fromModel(user), PlannerRole.GENERAL); } } } - public SchedulePlannerResponse getPlannersByGroup(UserInfo userInfo, String groupCode, Long scheduleId) { - if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode())) { + public SchedulePlannerResponse getPlannersByGroup(UserResponse userResponse, String groupCode, Long scheduleId) { + if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode())) { throw new BusinessException(ErrorCode.ACCESS_DENIED); } Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); @@ -175,7 +176,7 @@ public SchedulePlannerResponse getPlannersByGroup(UserInfo userInfo, String grou return SchedulePlannerResponse.fromEntity(planners, schedule); } - public List findPlannersByGroupCodeAndDateRange(LocalDate startDate, LocalDate endDate, String groupCode, UserInfo userInfo) { + public List findPlannersByGroupCodeAndDateRange(LocalDate startDate, LocalDate endDate, String groupCode, UserResponse userResponse) { List planners = plannerRepository.findAllByGroupAndDateRange(groupCode, startDate, endDate); Map> groupedPlanners = planners.stream().collect(Collectors.groupingBy(planner -> planner.getSchedule().getId())); diff --git a/src/main/java/com/tukorea/planding/domain/planner/service/PersonalPlannerService.java b/src/main/java/com/tukorea/planding/domain/planner/service/PersonalPlannerService.java index 35a680c..ed03f0b 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/service/PersonalPlannerService.java +++ b/src/main/java/com/tukorea/planding/domain/planner/service/PersonalPlannerService.java @@ -9,8 +9,9 @@ import com.tukorea.planding.domain.planner.repository.PlannerUserRepository; import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.service.ScheduleQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -30,7 +31,7 @@ public class PersonalPlannerService { private final PlannerUserRepository plannerUserRepository; private final ScheduleQueryService scheduleQueryService; - public PersonalPlannerResponse createPersonalPlanner(UserInfo userInfo, PlannerRequest request) { + public PersonalPlannerResponse createPersonalPlanner(UserResponse userResponse, PlannerRequest request) { Schedule schedule = scheduleQueryService.findScheduleById(request.getScheduleId()); Planner planner = Planner.builder() @@ -44,8 +45,8 @@ public PersonalPlannerResponse createPersonalPlanner(UserInfo userInfo, PlannerR Planner savedPlanner = plannerRepository.save(planner); savedPlanner.generatePlannerNumber(); - User manager = userQueryService.getUserByUserCode(request.getManagerCode()); - planner.getUsers().add(assignUserToPlanner(planner, manager, PlannerRole.MANAGER)); + UserDomain manager = userQueryService.getUserByUserCode(request.getManagerCode()); + planner.getUsers().add(assignUserToPlanner(planner, User.fromModel(manager), PlannerRole.MANAGER)); return PersonalPlannerResponse.fromEntity(planner); @@ -60,7 +61,7 @@ private PlannerUser assignUserToPlanner(Planner planner, User user, PlannerRole return plannerUserRepository.save(plannerUser); } - public void deletePlanner(UserInfo userInfo, Long plannerId) { + public void deletePlanner(UserResponse userResponse, Long plannerId) { Planner planner = plannerRepository.findById(plannerId) .orElseThrow(() -> new IllegalArgumentException("Planner not found with id: " + plannerId)); @@ -75,7 +76,7 @@ public void deletePlanner(UserInfo userInfo, Long plannerId) { } - public PersonalPlannerResponse updatePlanner(UserInfo userInfo, PlannerRequest request, Long plannerId) { + public PersonalPlannerResponse updatePlanner(UserResponse userResponse, PlannerRequest request, Long plannerId) { Planner planner = plannerRepository.findById(plannerId) .orElseThrow(() -> new IllegalArgumentException("Planner not found with id: " + plannerId)); diff --git a/src/main/java/com/tukorea/planding/domain/schedule/controller/CommonScheduleController.java b/src/main/java/com/tukorea/planding/domain/schedule/controller/CommonScheduleController.java index 9e2f64c..79e404b 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/controller/CommonScheduleController.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/controller/CommonScheduleController.java @@ -4,7 +4,7 @@ import com.tukorea.planding.common.CommonUtils; import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse; import com.tukorea.planding.domain.schedule.service.CommonScheduleService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -27,8 +27,8 @@ public class CommonScheduleController { @Operation(summary = "오늘 스케줄 조회") @GetMapping("/today") - public CommonResponse> showTodaySchedule(@AuthenticationPrincipal UserInfo userInfo) { - List responses = commonScheduleService.showTodaySchedule(userInfo); + public CommonResponse> showTodaySchedule(@AuthenticationPrincipal UserResponse userResponse) { + List responses = commonScheduleService.showTodaySchedule(userResponse); return CommonUtils.success(responses); } @@ -36,8 +36,8 @@ public CommonResponse> showTodaySchedule(@AuthenticationP @GetMapping("/week/{startDate}/{endDate}") public CommonResponse> getWeekSchedule(@PathVariable(name = "startDate") LocalDate startDate, @PathVariable(name = "endDate") LocalDate endDate - , @AuthenticationPrincipal UserInfo userInfo) { - List scheduleResponse = commonScheduleService.getWeekSchedule(startDate, endDate, userInfo); + , @AuthenticationPrincipal UserResponse userResponse) { + List scheduleResponse = commonScheduleService.getWeekSchedule(startDate, endDate, userResponse); return CommonUtils.success(scheduleResponse); } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleAttendanceController.java b/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleAttendanceController.java index f4c893b..b4528e9 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleAttendanceController.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleAttendanceController.java @@ -4,12 +4,10 @@ import com.tukorea.planding.common.CommonUtils; import com.tukorea.planding.domain.schedule.dto.request.GroupScheduleAttendanceRequest; import com.tukorea.planding.domain.schedule.service.GroupScheduleAttendanceService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -23,7 +21,7 @@ public class GroupScheduleAttendanceController { @PostMapping() @Operation(summary = "스케줄 참여 여부 선택") - public CommonResponse participationGroupSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupScheduleAttendanceRequest status) { - return CommonUtils.success(groupScheduleAttendanceService.participationGroupSchedule(userInfo, status)); + public CommonResponse participationGroupSchedule(@AuthenticationPrincipal UserResponse userResponse, @RequestBody GroupScheduleAttendanceRequest status) { + return CommonUtils.success(groupScheduleAttendanceService.participationGroupSchedule(userResponse, status)); } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleController.java b/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleController.java index d0fd9ef..fd41e0d 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleController.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/controller/GroupScheduleController.java @@ -8,7 +8,7 @@ import com.tukorea.planding.domain.schedule.dto.response.GroupScheduleResponse; import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse; import com.tukorea.planding.domain.schedule.service.GroupScheduleService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -56,15 +56,15 @@ public CommonResponse deleteGroupSchedule(StompHeaderAccessor accessor, @Dest @Operation(summary = "그룹 스케줄: 작성 목록 조회") @GetMapping("/api/v1/group-rooms/{groupCode}") - public CommonResponse> getSchedulesByGroupRoom(@PathVariable String groupCode, @AuthenticationPrincipal UserInfo userInfo) { - List scheduleResponses = groupScheduleService.getSchedulesByGroupRoom(groupCode, userInfo); + public CommonResponse> getSchedulesByGroupRoom(@PathVariable String groupCode, @AuthenticationPrincipal UserResponse userResponse) { + List scheduleResponses = groupScheduleService.getSchedulesByGroupRoom(groupCode, userResponse); return CommonUtils.success(scheduleResponses); } @Operation(summary = "그룹 스케줄: 조회") @GetMapping("/api/v1/group-rooms/{groupCode}/{scheduleId}") - public CommonResponse getGroupSchedule(@PathVariable String groupCode, @PathVariable Long scheduleId, @AuthenticationPrincipal UserInfo userInfo) { - GroupScheduleResponse scheduleResponses = groupScheduleService.getGroupScheduleById(userInfo, groupCode, scheduleId); + public CommonResponse getGroupSchedule(@PathVariable String groupCode, @PathVariable Long scheduleId, @AuthenticationPrincipal UserResponse userResponse) { + GroupScheduleResponse scheduleResponses = groupScheduleService.getGroupScheduleById(userResponse, groupCode, scheduleId); return CommonUtils.success(scheduleResponses); } @@ -72,8 +72,8 @@ public CommonResponse getGroupSchedule(@PathVariable Stri @GetMapping("/api/v1/group-rooms/week/{startDate}/{endDate}") public CommonResponse> getWeekSchedule(@PathVariable(name = "startDate") LocalDate startDate, @PathVariable(name = "endDate") LocalDate endDate - , @AuthenticationPrincipal UserInfo userInfo) { - List scheduleResponse = groupScheduleService.getWeekSchedule(startDate, endDate, userInfo); + , @AuthenticationPrincipal UserResponse userResponse) { + List scheduleResponse = groupScheduleService.getWeekSchedule(startDate, endDate, userResponse); return CommonUtils.success(scheduleResponse); } @@ -81,16 +81,16 @@ public CommonResponse> getWeekSchedule(@PathVariable(name @GetMapping("/api/v1/group-rooms/week/{groupCode}/{startDate}/{endDate}") public CommonResponse> getWeekScheduleByGroup(@PathVariable String groupCode, @PathVariable LocalDate startDate, @PathVariable LocalDate endDate - , @AuthenticationPrincipal UserInfo userInfo) { - List scheduleResponse = groupScheduleService.getWeekScheduleByGroupCode(startDate, endDate, groupCode, userInfo); + , @AuthenticationPrincipal UserResponse userResponse) { + List scheduleResponse = groupScheduleService.getWeekScheduleByGroupCode(startDate, endDate, groupCode, userResponse); return CommonUtils.success(scheduleResponse); } @Operation(summary = "그룹: 그룹 전체 데이터 조회") @GetMapping("/api/v1/group-rooms/all/{startDate}/{endDate}") - public CommonResponse> getAllScheduleByGroup( @AuthenticationPrincipal UserInfo userInfo,@PathVariable LocalDate startDate, - @PathVariable LocalDate endDate){ - List scheduleResponse = groupScheduleService.getAllScheduleByGroup(startDate, endDate, userInfo); + public CommonResponse> getAllScheduleByGroup(@AuthenticationPrincipal UserResponse userResponse, @PathVariable LocalDate startDate, + @PathVariable LocalDate endDate){ + List scheduleResponse = groupScheduleService.getAllScheduleByGroup(startDate, endDate, userResponse); return CommonUtils.success(scheduleResponse); } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/controller/PersonalScheduleController.java b/src/main/java/com/tukorea/planding/domain/schedule/controller/PersonalScheduleController.java index e5773cd..d3ec330 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/controller/PersonalScheduleController.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/controller/PersonalScheduleController.java @@ -7,7 +7,7 @@ import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse; import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse; import com.tukorea.planding.domain.schedule.service.PersonalScheduleService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -30,38 +30,38 @@ public class PersonalScheduleController { @Operation(summary = "개인 메인 페이지 API") @GetMapping() - public CommonResponse> getWeekSchedule(@AuthenticationPrincipal UserInfo userInfo, + public CommonResponse> getWeekSchedule(@AuthenticationPrincipal UserResponse userResponse, @RequestParam int weekOffset) { - List responses = personalScheduleService.getAllSchedule(userInfo, weekOffset); + List responses = personalScheduleService.getAllSchedule(userResponse, weekOffset); return CommonUtils.success(responses); } @Operation(summary = "개인 스케줄: 생성") @PostMapping() - public CommonResponse createSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody @Valid PersonalScheduleRequest personalScheduleRequest) { - PersonalScheduleResponse response = personalScheduleService.createSchedule(userInfo, personalScheduleRequest); + public CommonResponse createSchedule(@AuthenticationPrincipal UserResponse userResponse, @RequestBody @Valid PersonalScheduleRequest personalScheduleRequest) { + PersonalScheduleResponse response = personalScheduleService.createSchedule(userResponse, personalScheduleRequest); return CommonUtils.success(response); } @Operation(summary = "개인 스케줄: 삭제") @DeleteMapping("/{id}") - public ResponseEntity deleteSchedule(@AuthenticationPrincipal UserInfo userInfo, @PathVariable Long id) { - personalScheduleService.deleteSchedule(userInfo, id); + public ResponseEntity deleteSchedule(@AuthenticationPrincipal UserResponse userResponse, @PathVariable Long id) { + personalScheduleService.deleteSchedule(userResponse, id); return new ResponseEntity<>(HttpStatus.OK); } @Operation(summary = "개인 스케줄: 조회") @GetMapping("/{schedule_id}") - public CommonResponse getScheduleById(@PathVariable(name = "schedule_id") Long id, @AuthenticationPrincipal UserInfo userInfo) { - PersonalScheduleResponse scheduleResponse = personalScheduleService.getSchedule(id, userInfo); + public CommonResponse getScheduleById(@PathVariable(name = "schedule_id") Long id, @AuthenticationPrincipal UserResponse userResponse) { + PersonalScheduleResponse scheduleResponse = personalScheduleService.getSchedule(id, userResponse); return CommonUtils.success(scheduleResponse); } //TODO 아직 요구사항 미정 @Operation(summary = "개인 스케줄: 제목,내용,시작시간,끝낼시간 항목 수정") @PatchMapping("/{schedule_id}") - public CommonResponse updateSchedule(@PathVariable(name = "schedule_id") Long id, @RequestBody @Valid PersonalScheduleRequest personalScheduleRequest, @AuthenticationPrincipal UserInfo userInfo) { - PersonalScheduleResponse scheduleResponse = personalScheduleService.updateSchedule(id, personalScheduleRequest, userInfo); + public CommonResponse updateSchedule(@PathVariable(name = "schedule_id") Long id, @RequestBody @Valid PersonalScheduleRequest personalScheduleRequest, @AuthenticationPrincipal UserResponse userResponse) { + PersonalScheduleResponse scheduleResponse = personalScheduleService.updateSchedule(id, personalScheduleRequest, userResponse); return CommonUtils.success(scheduleResponse); } @@ -69,15 +69,15 @@ public CommonResponse updateSchedule(@PathVariable(nam @GetMapping("/week/{startDate}/{endDate}") public CommonResponse> getWeekSchedule(@PathVariable(name = "startDate") LocalDate startDate, @PathVariable(name = "endDate") LocalDate endDate - , @AuthenticationPrincipal UserInfo userInfo) { - List scheduleResponse = personalScheduleService.getWeekSchedule(startDate, endDate, userInfo); + , @AuthenticationPrincipal UserResponse userResponse) { + List scheduleResponse = personalScheduleService.getWeekSchedule(startDate, endDate, userResponse); return CommonUtils.success(scheduleResponse); } @Operation(summary = "스케줄 생성시 중복 스케줄 확인") @PostMapping("/overlap") - public CommonResponse> findOverlapSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody ScheduleRequest scheduleRequest) { - List scheduleResponses = personalScheduleService.findOverlapSchedule(userInfo.getId(), scheduleRequest); + public CommonResponse> findOverlapSchedule(@AuthenticationPrincipal UserResponse userResponse, @RequestBody ScheduleRequest scheduleRequest) { + List scheduleResponses = personalScheduleService.findOverlapSchedule(userResponse.getId(), scheduleRequest); return CommonUtils.success(scheduleResponses); } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/GroupScheduleDomain.java b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/GroupScheduleDomain.java new file mode 100644 index 0000000..f46ed02 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/GroupScheduleDomain.java @@ -0,0 +1,18 @@ +package com.tukorea.planding.domain.schedule.entity.domain; + +import com.tukorea.planding.domain.group.entity.GroupRoom; +import com.tukorea.planding.domain.group.entity.domain.GroupRoomDomain; +import com.tukorea.planding.domain.schedule.entity.Schedule; + +import java.util.HashSet; +import java.util.Set; + +public class GroupScheduleDomain { + + private Long id; + + private GroupRoomDomain groupRoom; + + private Set schedules = new HashSet<>(); + +} diff --git a/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/PersonalScheduleDomain.java b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/PersonalScheduleDomain.java new file mode 100644 index 0000000..54c6070 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/PersonalScheduleDomain.java @@ -0,0 +1,17 @@ +package com.tukorea.planding.domain.schedule.entity.domain; + +import com.tukorea.planding.domain.schedule.entity.Schedule; +import com.tukorea.planding.domain.user.entity.User; + +import java.util.HashSet; +import java.util.Set; + +public class PersonalScheduleDomain { + + private Long id; + + private User user; + + private Set schedules = new HashSet<>(); + +} diff --git a/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/ScheduleDomain.java b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/ScheduleDomain.java new file mode 100644 index 0000000..cd77116 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/schedule/entity/domain/ScheduleDomain.java @@ -0,0 +1,37 @@ +package com.tukorea.planding.domain.schedule.entity.domain; + +import com.tukorea.planding.domain.planner.entity.Planner; +import com.tukorea.planding.domain.schedule.entity.GroupSchedule; +import com.tukorea.planding.domain.schedule.entity.PersonalSchedule; +import com.tukorea.planding.domain.schedule.entity.ScheduleType; +import com.tukorea.planding.global.audit.BaseEntity; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class ScheduleDomain { + + private Long id; + + private String title; + + private String content; + + private LocalDate scheduleDate; + + private Integer startTime; + + private Integer endTime; + + private boolean isComplete; + + private ScheduleType type; + + private PersonalScheduleDomain personalSchedule; + + private GroupScheduleDomain groupSchedule; + + private final List planners = new ArrayList<>(); + +} diff --git a/src/main/java/com/tukorea/planding/domain/schedule/repository/ScheduleRepositoryCustom.java b/src/main/java/com/tukorea/planding/domain/schedule/repository/ScheduleRepositoryCustom.java index 7cee2b2..eda2f0a 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/repository/ScheduleRepositoryCustom.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/repository/ScheduleRepositoryCustom.java @@ -1,8 +1,6 @@ package com.tukorea.planding.domain.schedule.repository; import com.tukorea.planding.domain.schedule.entity.Schedule; -import com.tukorea.planding.domain.user.dto.UserInfo; -import org.springframework.data.jpa.repository.Query; import java.time.LocalDate; import java.util.List; diff --git a/src/main/java/com/tukorea/planding/domain/schedule/service/CommonScheduleService.java b/src/main/java/com/tukorea/planding/domain/schedule/service/CommonScheduleService.java index 36bc43c..8528cfd 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/service/CommonScheduleService.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/service/CommonScheduleService.java @@ -1,8 +1,7 @@ package com.tukorea.planding.domain.schedule.service; -import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest; import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,15 +16,15 @@ public class CommonScheduleService { private final ScheduleQueryService scheduleQueryService; - public List showTodaySchedule(UserInfo userInfo) { - return scheduleQueryService.showTodaySchedule(userInfo.getId()) + public List showTodaySchedule(UserResponse userResponse) { + return scheduleQueryService.showTodaySchedule(userResponse.getId()) .stream() .map(ScheduleResponse::from) .collect(Collectors.toList()); } - public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserInfo userInfo) { - return scheduleQueryService.findWeeklyScheduleByUser(startDate, endDate, userInfo.getId()) + public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserResponse userResponse) { + return scheduleQueryService.findWeeklyScheduleByUser(startDate, endDate, userResponse.getId()) .stream() .map(ScheduleResponse::from) .collect(Collectors.toList()); diff --git a/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleAttendanceService.java b/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleAttendanceService.java index 77bbd15..e931e26 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleAttendanceService.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleAttendanceService.java @@ -5,8 +5,9 @@ import com.tukorea.planding.domain.schedule.entity.GroupScheduleAttendance; import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.repository.GroupScheduleAttendanceRepository; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -23,15 +24,15 @@ public class GroupScheduleAttendanceService { private final GroupScheduleAttendanceRepository groupScheduleAttendanceRepository; @Transactional - public GroupScheduleAttendanceResponse participationGroupSchedule(UserInfo userInfo, GroupScheduleAttendanceRequest request) { - User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + public GroupScheduleAttendanceResponse participationGroupSchedule(UserResponse userResponse, GroupScheduleAttendanceRequest request) { + UserDomain user = userQueryService.getUserByUserCode(userResponse.getUserCode()); Schedule schedule = scheduleQueryService.findScheduleById(request.scheduleId()); GroupScheduleAttendance attendance = groupScheduleAttendanceRepository .findByUserIdAndScheduleId(user.getId(), schedule.getId()) .orElseGet(GroupScheduleAttendance::new); - attendance.addUser(user); + attendance.addUser(User.fromModel(user)); attendance.addSchedule(schedule); switch (request.status()) { diff --git a/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleService.java b/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleService.java index af96db3..1661c17 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleService.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/service/GroupScheduleService.java @@ -15,7 +15,7 @@ import com.tukorea.planding.domain.schedule.entity.*; import com.tukorea.planding.domain.schedule.repository.GroupScheduleAttendanceRepository; import com.tukorea.planding.domain.schedule.repository.GroupScheduleRepository; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -121,8 +121,8 @@ public void afterCommit() { } @Transactional(readOnly = true) - public GroupScheduleResponse getGroupScheduleById(UserInfo userInfo, String groupCode, Long scheduleId) { - checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode()); + public GroupScheduleResponse getGroupScheduleById(UserResponse userResponse, String groupCode, Long scheduleId) { + checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode()); GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); @@ -133,8 +133,8 @@ public GroupScheduleResponse getGroupScheduleById(UserInfo userInfo, String grou } @Transactional(readOnly = true) - public List getSchedulesByGroupRoom(String groupCode, UserInfo userInfo) { - checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode()); + public List getSchedulesByGroupRoom(String groupCode, UserResponse userResponse) { + checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode()); List schedules = scheduleQueryService.findByGroupRoomCode(groupCode); GroupRoom groupRoom = groupQueryService.getGroupByCode(groupCode); @@ -143,24 +143,24 @@ public List getSchedulesByGroupRoom(String groupCode, Use .collect(Collectors.toList()); } - public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserInfo userInfo) { - return scheduleQueryService.findWeeklyGroupScheduleByUser(startDate, endDate, userInfo.getId()) + public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserResponse userResponse) { + return scheduleQueryService.findWeeklyGroupScheduleByUser(startDate, endDate, userResponse.getId()) .stream() .map(ScheduleResponse::from) .sorted(ScheduleResponse.getComparatorByStartTime()) .collect(Collectors.toList()); } - public List getWeekScheduleByGroupCode(LocalDate startDate, LocalDate endDate, String groupRoomCode, UserInfo userInfo) { - return scheduleQueryService.findWeeklyGroupScheduleByGroupCode(startDate, endDate, userInfo.getId(), groupRoomCode) + public List getWeekScheduleByGroupCode(LocalDate startDate, LocalDate endDate, String groupRoomCode, UserResponse userResponse) { + return scheduleQueryService.findWeeklyGroupScheduleByGroupCode(startDate, endDate, userResponse.getId(), groupRoomCode) .stream() .map(ScheduleResponse::from) .sorted(ScheduleResponse.getComparatorByStartTime()) .collect(Collectors.toList()); } - public List getAllScheduleByGroup(LocalDate startDate, LocalDate endDate, UserInfo userInfo) { - return scheduleQueryService.findAllGroupScheduleByGroupCode(startDate, endDate, userInfo.getId()) + public List getAllScheduleByGroup(LocalDate startDate, LocalDate endDate, UserResponse userResponse) { + return scheduleQueryService.findAllGroupScheduleByGroupCode(startDate, endDate, userResponse.getId()) .stream() .map(ScheduleResponse::from) .sorted(ScheduleResponse.getComparatorByStartTime()) diff --git a/src/main/java/com/tukorea/planding/domain/schedule/service/PersonalScheduleService.java b/src/main/java/com/tukorea/planding/domain/schedule/service/PersonalScheduleService.java index 09448e9..8011af4 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/service/PersonalScheduleService.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/service/PersonalScheduleService.java @@ -8,8 +8,9 @@ import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.entity.ScheduleType; import com.tukorea.planding.domain.schedule.repository.PersonalScheduleRepository; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -31,50 +32,50 @@ public class PersonalScheduleService { // 메인페이지 - public List getAllSchedule(UserInfo userInfo, int weekOffset) { + public List getAllSchedule(UserResponse userResponse, int weekOffset) { LocalDate today = LocalDate.now().plusWeeks(weekOffset); LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY)); LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY)); - List schedules = scheduleQueryService.findByUserAndScheduleDateBetween(userInfo.getId(), startOfWeek, endOfWeek); + List schedules = scheduleQueryService.findByUserAndScheduleDateBetween(userResponse.getId(), startOfWeek, endOfWeek); return schedules.stream() .map(ScheduleResponse::from) .collect(Collectors.toList()); } - public PersonalScheduleResponse createSchedule(UserInfo userInfo, PersonalScheduleRequest personalScheduleRequest) { - User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + public PersonalScheduleResponse createSchedule(UserResponse userResponse, PersonalScheduleRequest personalScheduleRequest) { + UserDomain user = userQueryService.getUserByUserCode(userResponse.getUserCode()); // 개인 스케줄 생성 - PersonalSchedule personalSchedule = createPersonalSchedule(user); + PersonalSchedule personalSchedule = createPersonalSchedule(User.fromModel(user)); Schedule schedule = create(personalSchedule, personalScheduleRequest); return PersonalScheduleResponse.from(schedule); } @Transactional(readOnly = true) - public PersonalScheduleResponse getSchedule(Long scheduleId, UserInfo userInfo) { + public PersonalScheduleResponse getSchedule(Long scheduleId, UserResponse userResponse) { Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); - schedule.getPersonalSchedule().checkOwnership(userInfo.getId()); + schedule.getPersonalSchedule().checkOwnership(userResponse.getId()); return PersonalScheduleResponse.from(schedule); } - public void deleteSchedule(UserInfo userInfo, Long scheduleId) { + public void deleteSchedule(UserResponse userResponse, Long scheduleId) { Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); - schedule.getPersonalSchedule().checkOwnership(userInfo.getId()); + schedule.getPersonalSchedule().checkOwnership(userResponse.getId()); scheduleQueryService.delete(schedule); } - public PersonalScheduleResponse updateSchedule(Long scheduleId, PersonalScheduleRequest scheduleRequest, UserInfo userInfo) { + public PersonalScheduleResponse updateSchedule(Long scheduleId, PersonalScheduleRequest scheduleRequest, UserResponse userResponse) { Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); - schedule.getPersonalSchedule().checkOwnership(userInfo.getId()); + schedule.getPersonalSchedule().checkOwnership(userResponse.getId()); schedule.update(scheduleRequest.title(), scheduleRequest.content(), scheduleRequest.startTime(), scheduleRequest.endTime()); return PersonalScheduleResponse.from(schedule); } - public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserInfo userInfo) { - return scheduleQueryService.findWeeklyPersonalScheduleByUser(startDate, endDate, userInfo.getId()) + public List getWeekSchedule(LocalDate startDate, LocalDate endDate, UserResponse userResponse) { + return scheduleQueryService.findWeeklyPersonalScheduleByUser(startDate, endDate, userResponse.getId()) .stream() .map(PersonalScheduleResponse::from) .collect(Collectors.toList()); diff --git a/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java b/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java index 9701494..15356f9 100644 --- a/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java +++ b/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java @@ -2,11 +2,10 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; -import com.tukorea.planding.domain.group.entity.GroupRoom; import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; import com.tukorea.planding.domain.user.dto.AndroidLoginResponse; import com.tukorea.planding.domain.user.dto.ProfileResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.service.AndroidLoginService; import com.tukorea.planding.domain.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; @@ -15,8 +14,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import java.util.List; - @Tag(name = "User", description = "회원 API 문서") @RestController @RequestMapping("/api/v1") @@ -35,8 +32,8 @@ public CommonResponse signupApp(@RequestBody AndroidLoginR @Operation(summary = "프로필 가져오기", description = "즐겨찾는 그룹, 그룹요청") @GetMapping("/profile") - public CommonResponse getProfile(@AuthenticationPrincipal UserInfo userInfo) { - ProfileResponse profile = userService.getProfile(userInfo); + public CommonResponse getProfile(@AuthenticationPrincipal UserResponse userResponse) { + ProfileResponse profile = userService.getProfile(userResponse.getId()); return CommonUtils.success(profile); } } diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginRequest.java b/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginRequest.java index 7fde8fc..d9f965e 100644 --- a/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginRequest.java +++ b/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginRequest.java @@ -1,7 +1,9 @@ package com.tukorea.planding.domain.user.dto; import com.tukorea.planding.domain.user.entity.SocialType; +import lombok.Builder; +@Builder public record AndroidLoginRequest( String profileNickname, String accountEmail, diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginResponse.java b/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginResponse.java index ad09349..7d7dc3f 100644 --- a/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginResponse.java +++ b/src/main/java/com/tukorea/planding/domain/user/dto/AndroidLoginResponse.java @@ -1,5 +1,6 @@ package com.tukorea.planding.domain.user.dto; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.global.oauth.details.Role; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -12,4 +13,12 @@ public class AndroidLoginResponse { private String userCode; private String accessToken; private String refreshToken; + + public static AndroidLoginResponse toAndroidLoginResponse(UserDomain userDomain, String accessToken, String refreshToken) { + return AndroidLoginResponse.builder() + .userCode(userDomain.getUserCode()) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } } diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java b/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java index 6fc7d7a..9dc3963 100644 --- a/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java +++ b/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java @@ -1,8 +1,8 @@ package com.tukorea.planding.domain.user.dto; +import com.tukorea.planding.domain.group.service.port.RedisGroupInviteService; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.global.oauth.details.Role; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; import lombok.Builder; @Builder @@ -15,4 +15,15 @@ public record ProfileResponse( Long groupFavorite, Long groupRequest ) { + public static ProfileResponse toProfileResponse(UserDomain userDomain, RedisGroupInviteService redisGroupInviteService){ + return ProfileResponse.builder() + .userCode(userDomain.getUserCode()) + .email(userDomain.getEmail()) + .username(userDomain.getUsername()) + .profileImage(userDomain.getProfileImage()) + .groupFavorite((long) userDomain.getGroupFavorites().size()) + .groupRequest((long) redisGroupInviteService.getAllInvitations(userDomain.getUserCode()).size()) + .role(Role.USER) + .build(); + } } diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/UserInfo.java b/src/main/java/com/tukorea/planding/domain/user/dto/UserInfo.java deleted file mode 100644 index 1fee96a..0000000 --- a/src/main/java/com/tukorea/planding/domain/user/dto/UserInfo.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.tukorea.planding.domain.user.dto; - -import com.tukorea.planding.global.oauth.details.Role; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class UserInfo{ - private Long id; - - private String username; - - private String email; - - private String profileImage; - - @Enumerated(EnumType.STRING) - private Role role; - - private String userCode; -} diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/UserResponse.java b/src/main/java/com/tukorea/planding/domain/user/dto/UserResponse.java new file mode 100644 index 0000000..a3166ee --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/dto/UserResponse.java @@ -0,0 +1,36 @@ +package com.tukorea.planding.domain.user.dto; + +import com.tukorea.planding.domain.user.entity.UserDomain; +import com.tukorea.planding.global.oauth.details.Role; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class UserResponse { + private Long id; + + private String username; + + private String email; + + private String profileImage; + + @Enumerated(EnumType.STRING) + private Role role; + + private String userCode; + + public static UserResponse toResponse(UserDomain userDomain) { + return UserResponse.builder() + .id(userDomain.getId()) + .email(userDomain.getEmail()) + .profileImage(userDomain.getProfileImage()) + .role(userDomain.getRole()) + .username(userDomain.getUsername()) + .userCode(userDomain.getUserCode()) + .build(); + } +} diff --git a/src/main/java/com/tukorea/planding/domain/user/entity/SocialType.java b/src/main/java/com/tukorea/planding/domain/user/entity/SocialType.java index 28acf71..7417e1a 100644 --- a/src/main/java/com/tukorea/planding/domain/user/entity/SocialType.java +++ b/src/main/java/com/tukorea/planding/domain/user/entity/SocialType.java @@ -7,15 +7,14 @@ @AllArgsConstructor public enum SocialType { - NAVER("NAVER"), KAKAO("KAKAO"); private final String socialName; public static SocialType getSocialType(String registrationId) { - if(KAKAO.socialName.equals(registrationId.toUpperCase())) { + if (KAKAO.socialName.equals(registrationId.toUpperCase())) { return SocialType.KAKAO; } - return SocialType.NAVER; + return null; } } diff --git a/src/main/java/com/tukorea/planding/domain/user/entity/User.java b/src/main/java/com/tukorea/planding/domain/user/entity/User.java index fae1246..a3c66a5 100644 --- a/src/main/java/com/tukorea/planding/domain/user/entity/User.java +++ b/src/main/java/com/tukorea/planding/domain/user/entity/User.java @@ -5,10 +5,7 @@ import com.tukorea.planding.global.audit.BaseEntity; import com.tukorea.planding.global.oauth.details.Role; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.*; @@ -69,16 +66,30 @@ public User(String email, String profileImage, String username, Role role, Socia this.fcmToken = fcmToken; } - public static String createCode() { - String c = UUID.randomUUID().toString(); - return "#" + c.substring(0, 4); + public static User fromModel(UserDomain userDomain){ + return User.builder() + .socialType(userDomain.getSocialType()) + .socialId(userDomain.getSocialId()) + .profileImage(userDomain.getProfileImage()) + .fcmToken(userDomain.getFcmToken()) + .email(userDomain.getEmail()) + .role(userDomain.getRole()) + .username(userDomain.getUsername()) + .userCode(userDomain.getUserCode()) + .build(); } - public void updateFcmToken(String fcmToken) { - this.fcmToken = fcmToken; - } - - public void updateAlarm(boolean alarm) { - this.alarm = alarm; + public UserDomain toModel(){ + return UserDomain.builder() + .id(id) + .email(email) + .profileImage(profileImage) + .username(username) + .userCode(userCode) + .socialId(socialId) + .socialType(socialType) + .fcmToken(fcmToken) + .alarm(alarm) + .build(); } } diff --git a/src/main/java/com/tukorea/planding/domain/user/entity/UserDomain.java b/src/main/java/com/tukorea/planding/domain/user/entity/UserDomain.java new file mode 100644 index 0000000..88e62ae --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/entity/UserDomain.java @@ -0,0 +1,90 @@ +package com.tukorea.planding.domain.user.entity; + +import com.tukorea.planding.common.service.UserCodeHolder; +import com.tukorea.planding.domain.group.entity.GroupFavorite; +import com.tukorea.planding.domain.group.entity.UserGroup; +import com.tukorea.planding.domain.group.entity.domain.GroupFavoriteDomain; +import com.tukorea.planding.domain.group.entity.domain.UserGroupDomain; +import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; +import com.tukorea.planding.global.oauth.details.Role; +import lombok.Builder; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Getter +public class UserDomain { + private final Long id; + private final String email; + private final String profileImage; + private final String username; + private final Role role; + private final SocialType socialType; + private final String socialId; + private final String userCode; + private final boolean alarm; + private final String fcmToken; + private final Set userGroup = new HashSet<>(); + private final List groupFavorites = new ArrayList<>(); + + @Builder + public UserDomain(Long id, String email, String profileImage, String username, Role role, SocialType socialType, String socialId, String userCode, boolean alarm, String fcmToken) { + this.id = id; + this.email = email; + this.profileImage = profileImage; + this.username = username; + this.role = role; + this.socialType = socialType; + this.socialId = socialId; + this.userCode = userCode; + this.alarm = alarm; + this.fcmToken = fcmToken; + } + + public static UserDomain androidCreate(AndroidLoginRequest androidLoginRequest, String userCode) { + return UserDomain.builder() + .socialId(androidLoginRequest.socialId()) + .socialType(SocialType.KAKAO) + .username(androidLoginRequest.profileNickname()) + .email(androidLoginRequest.accountEmail()) + .profileImage(androidLoginRequest.profileImage()) + .userCode(userCode) + .role(Role.USER) + .build(); + } + + public UserDomain updateFcmToken(String fcmToken) { + return UserDomain.builder() + .id(id) + .email(email) + .profileImage(profileImage) + .username(username) + .role(role) + .socialType(socialType) + .socialId(socialId) + .alarm(alarm) + .userCode(userCode) + .fcmToken(fcmToken) + .build(); + } + + public UserDomain updateAlarm(boolean alarm) { + return UserDomain.builder() + .id(id) + .email(email) + .profileImage(profileImage) + .username(username) + .role(role) + .socialType(socialType) + .socialId(socialId) + .alarm(alarm) + .userCode(userCode) + .fcmToken(fcmToken) + .build(); + } + + +} diff --git a/src/main/java/com/tukorea/planding/domain/user/mapper/UserMapper.java b/src/main/java/com/tukorea/planding/domain/user/mapper/UserMapper.java deleted file mode 100644 index 4d33094..0000000 --- a/src/main/java/com/tukorea/planding/domain/user/mapper/UserMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.tukorea.planding.domain.user.mapper; - -import com.tukorea.planding.domain.user.dto.AndroidLoginResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; -import com.tukorea.planding.domain.user.entity.User; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UserMapper { - - public static UserInfo toUserInfo(User user) { - return UserInfo.builder() - .id(user.getId()) - .email(user.getEmail()) - .profileImage(user.getProfileImage()) - .role(user.getRole()) - .username(user.getUsername()) - .userCode(user.getUserCode()) - .build(); - } - - public static AndroidLoginResponse toAndroidLoginResponse(User user, String accessToken, String refreshToken) { - return AndroidLoginResponse.builder() - .userCode(user.getUserCode()) - .accessToken(accessToken) - .refreshToken(refreshToken) - .build(); - } -} diff --git a/src/main/java/com/tukorea/planding/domain/user/repository/UserJpaRepository.java b/src/main/java/com/tukorea/planding/domain/user/repository/UserJpaRepository.java new file mode 100644 index 0000000..937907d --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/repository/UserJpaRepository.java @@ -0,0 +1,20 @@ +package com.tukorea.planding.domain.user.repository; + +import com.tukorea.planding.domain.user.entity.SocialType; +import com.tukorea.planding.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface UserJpaRepository extends JpaRepository { + + Optional findByUserCode(String userCode); + + Optional findByEmail(String email); + + Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId); + + Optional getUserById(Long userId); + + boolean existsByUserCode(String userCode); +} diff --git a/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java index df2cb42..a30f3a5 100644 --- a/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java +++ b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java @@ -1,20 +1,19 @@ package com.tukorea.planding.domain.user.repository; import com.tukorea.planding.domain.user.entity.SocialType; -import com.tukorea.planding.domain.user.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; +import com.tukorea.planding.domain.user.entity.UserDomain; import java.util.Optional; -public interface UserRepository extends JpaRepository { +public interface UserRepository { + Optional findByUserCode(String userCode); - Optional findByUserCode(String userCode); + Optional findByEmail(String email); - Optional findByEmail(String email); - - Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId); - - Optional getUserById(Long userId); + Optional getUserById(Long userId); + Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId); boolean existsByUserCode(String userCode); + + UserDomain save(UserDomain userDomain); } diff --git a/src/main/java/com/tukorea/planding/domain/user/repository/UserRepositoryImpl.java b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepositoryImpl.java new file mode 100644 index 0000000..b2666cd --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepositoryImpl.java @@ -0,0 +1,51 @@ +package com.tukorea.planding.domain.user.repository; + +import com.tukorea.planding.domain.user.dto.UserResponse; +import com.tukorea.planding.domain.user.entity.SocialType; +import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; +import com.tukorea.planding.global.error.BusinessException; +import com.tukorea.planding.global.error.ErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +@RequiredArgsConstructor +public class UserRepositoryImpl implements UserRepository { + + private final UserJpaRepository userJpaRepository; + + @Override + public Optional findByUserCode(String userCode) { + return userJpaRepository.findByUserCode(userCode).map(User::toModel); + } + + @Override + public Optional findByEmail(String email) { + return userJpaRepository.findByEmail(email).map(User::toModel); + } + + @Override + public Optional getUserById(Long userId) { + return userJpaRepository.getUserById(userId).map(User::toModel); + } + + @Override + public Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId) { + return userJpaRepository.findBySocialTypeAndSocialId(socialType, socialId).map(User::toModel); + } + + @Override + public boolean existsByUserCode(String userCode) { + return userJpaRepository.existsByUserCode(userCode); + } + + + @Override + public UserDomain save(UserDomain userDomain) { + return userJpaRepository.save(User.fromModel(userDomain)).toModel(); + } +} diff --git a/src/main/java/com/tukorea/planding/domain/user/service/AndroidLoginService.java b/src/main/java/com/tukorea/planding/domain/user/service/AndroidLoginService.java index 26debc5..24b33f2 100644 --- a/src/main/java/com/tukorea/planding/domain/user/service/AndroidLoginService.java +++ b/src/main/java/com/tukorea/planding/domain/user/service/AndroidLoginService.java @@ -2,8 +2,7 @@ import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; import com.tukorea.planding.domain.user.dto.AndroidLoginResponse; -import com.tukorea.planding.domain.user.entity.User; -import com.tukorea.planding.domain.user.mapper.UserMapper; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.global.config.security.jwt.JwtTokenHandler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,19 +18,20 @@ public class AndroidLoginService { private final JwtTokenHandler jwtTokenHandler; private final UserService userService; private final UserQueryService userQueryService; + private final UserCodeGeneratorImpl userCodeGenerator; public AndroidLoginResponse signupApp(AndroidLoginRequest androidLoginRequest) { - User user = userQueryService.findByEmail(androidLoginRequest.accountEmail()); + UserDomain userDomain = userQueryService.findByEmail(androidLoginRequest.accountEmail()); - if (user == null) { + if (userDomain == null) { // 유저가 존재하지 않으면 회원가입 - user = userService.createUserFromRequest(androidLoginRequest); + userDomain = userService.createAndroid(androidLoginRequest); } - String accessToken = jwtTokenHandler.generateAccessToken(user.getId(), user.getUserCode()); - String refreshToken = jwtTokenHandler.generateRefreshToken(user.getId(), user.getUserCode()); + String accessToken = jwtTokenHandler.generateAccessToken(userDomain.getId(), userDomain.getUserCode()); + String refreshToken = jwtTokenHandler.generateRefreshToken(userDomain.getId(), userDomain.getUserCode()); - return UserMapper.toAndroidLoginResponse(user, accessToken, refreshToken); + return AndroidLoginResponse.toAndroidLoginResponse(userDomain, accessToken, refreshToken); } } diff --git a/src/main/java/com/tukorea/planding/domain/user/service/UserCodeGeneratorImpl.java b/src/main/java/com/tukorea/planding/domain/user/service/UserCodeGeneratorImpl.java new file mode 100644 index 0000000..4256d2e --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/service/UserCodeGeneratorImpl.java @@ -0,0 +1,22 @@ +package com.tukorea.planding.domain.user.service; + +import com.tukorea.planding.common.service.UserCodeHolder; +import com.tukorea.planding.domain.user.service.port.UserCodeGenerator; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class UserCodeGeneratorImpl implements UserCodeGenerator { + private final UserQueryService userQueryService; + private final UserCodeHolder userCodeHolder; + + @Override + public String generateUniqueUserCode() { + String userCode; + do { + userCode = userCodeHolder.userCode(); + } while (userQueryService.existsByUserCode(userCode)); + return userCode; + } +} diff --git a/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java b/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java index 75db36d..c31af5f 100644 --- a/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java +++ b/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java @@ -1,7 +1,8 @@ package com.tukorea.planding.domain.user.service; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.repository.UserRepository; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -18,38 +19,31 @@ public class UserQueryService { private final UserRepository userRepository; - public User save(User user) { - return userRepository.save(user); + public UserDomain save(UserDomain userDomain) { + return userRepository.save(User.fromModel(userDomain).toModel()); } @Transactional(readOnly = true) - public User getUserByUserCode(String userCode) { + public UserDomain getUserByUserCode(String userCode) { return userRepository.findByUserCode(userCode) .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); } // 유저 정보를 조회하는 메서드에 캐싱을 적용 @Cacheable(value = "userInfoCache", key = "#userCode") - public UserInfo getUserInfo(String userCode) { - User user = getUserByUserCode(userCode); - return UserInfo.builder() - .id(user.getId()) - .username(user.getUsername()) - .email(user.getEmail()) - .profileImage(user.getProfileImage()) - .role(user.getRole()) - .userCode(user.getUserCode()) - .build(); + public UserResponse getUserInfo(String userCode) { + UserDomain user = getUserByUserCode(userCode); + return UserResponse.toResponse(user); } @Transactional(readOnly = true) - public User getUserProfile(Long userId) { + public UserDomain getUserProfile(Long userId) { return userRepository.getUserById(userId) .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); } @Transactional(readOnly = true) - public User findByEmail(String email) { + public UserDomain findByEmail(String email) { return userRepository.findByEmail(email).orElse(null); } diff --git a/src/main/java/com/tukorea/planding/domain/user/service/UserService.java b/src/main/java/com/tukorea/planding/domain/user/service/UserService.java index f2cb34e..c4f707e 100644 --- a/src/main/java/com/tukorea/planding/domain/user/service/UserService.java +++ b/src/main/java/com/tukorea/planding/domain/user/service/UserService.java @@ -1,13 +1,12 @@ package com.tukorea.planding.domain.user.service; -import com.tukorea.planding.domain.group.service.RedisGroupInviteService; +import com.tukorea.planding.domain.group.service.port.RedisGroupInviteService; import com.tukorea.planding.domain.notify.dto.FcmDTO; import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; import com.tukorea.planding.domain.user.dto.ProfileResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; -import com.tukorea.planding.domain.user.entity.SocialType; -import com.tukorea.planding.domain.user.entity.User; -import com.tukorea.planding.global.oauth.details.Role; +import com.tukorea.planding.domain.user.entity.UserDomain; +import com.tukorea.planding.domain.user.service.port.UserCodeGenerator; +import lombok.Builder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -15,68 +14,46 @@ @Service @Slf4j +@Builder @Transactional @RequiredArgsConstructor public class UserService { private final UserQueryService userQueryService; private final RedisGroupInviteService redisGroupInviteService; + private final UserCodeGenerator userCodeGenerator; - public User createUserFromRequest(AndroidLoginRequest androidLoginRequest) { - - String userCode = generateUniqueUserCode(); - User user = User.builder() - .socialId(androidLoginRequest.socialId()) - .socialType(SocialType.KAKAO) - .username(androidLoginRequest.profileNickname()) - .email(androidLoginRequest.accountEmail()) - .profileImage(androidLoginRequest.profileImage()) - .userCode(userCode) - .role(Role.USER) - .build(); - - User savedUser = userQueryService.save(user); - return savedUser; + public UserDomain createAndroid(AndroidLoginRequest androidLoginRequest) { + String userCode = userCodeGenerator.generateUniqueUserCode(); + UserDomain userDomain = UserDomain.androidCreate(androidLoginRequest, userCode); + return userQueryService.save(userDomain); } //TODO 즐겨찾는 그룹, 그룹 요청 // N+1문제는 발생하지 않지만 user조회쿼리 3개나감 - public ProfileResponse getProfile(UserInfo userInfo) { - User userProfile = userQueryService.getUserProfile(userInfo.getId()); - return ProfileResponse.builder() - .userCode(userProfile.getUserCode()) - .email(userProfile.getEmail()) - .username(userProfile.getUsername()) - .profileImage(userProfile.getProfileImage()) - .groupFavorite((long) userProfile.getGroupFavorites().size()) - .groupRequest((long) redisGroupInviteService.getAllInvitations(userInfo.getUserCode()).size()) - .role(Role.USER) - .build(); + public ProfileResponse getProfile(Long userId) { + UserDomain userDomain = userQueryService.getUserProfile(userId); + return ProfileResponse.toProfileResponse(userDomain, redisGroupInviteService); } - public String generateUniqueUserCode() { - String userCode; - do { - userCode = User.createCode(); - } while (userQueryService.existsByUserCode(userCode)); - return userCode; - } public void updateAlarmSetting(String userCode, boolean alarmSetting) { - User user = userQueryService.getUserByUserCode(userCode); - user.updateAlarm(alarmSetting); + UserDomain user = userQueryService.getUserByUserCode(userCode); + user = user.updateAlarm(alarmSetting); + userQueryService.save(user); } @Transactional(readOnly = true) public String getFcmTokenByUserCode(String userCode) { - User user = userQueryService.getUserByUserCode(userCode); + UserDomain user = userQueryService.getUserByUserCode(userCode); return user.getFcmToken(); } public void updateFcmToken(String userCode, FcmDTO fcmDTO) { - User user = userQueryService.getUserByUserCode(userCode); + UserDomain user = userQueryService.getUserByUserCode(userCode); log.info(userCode, fcmDTO.fcmToken()); - user.updateFcmToken(fcmDTO.fcmToken()); + user = user.updateFcmToken(fcmDTO.fcmToken()); + userQueryService.save(user); log.info("FCM 토큰 업데이트 완료: 사용자 코드: {}, FCM 토큰: {}", userCode, fcmDTO.fcmToken()); } diff --git a/src/main/java/com/tukorea/planding/domain/user/service/port/UserCodeGenerator.java b/src/main/java/com/tukorea/planding/domain/user/service/port/UserCodeGenerator.java new file mode 100644 index 0000000..be5d4ff --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/service/port/UserCodeGenerator.java @@ -0,0 +1,5 @@ +package com.tukorea.planding.domain.user.service.port; + +public interface UserCodeGenerator { + String generateUniqueUserCode(); +} diff --git a/src/main/java/com/tukorea/planding/global/aop/PersonalNotificationAspect.java b/src/main/java/com/tukorea/planding/global/aop/PersonalNotificationAspect.java index 18cfc7a..7614160 100644 --- a/src/main/java/com/tukorea/planding/global/aop/PersonalNotificationAspect.java +++ b/src/main/java/com/tukorea/planding/global/aop/PersonalNotificationAspect.java @@ -1,10 +1,9 @@ package com.tukorea.planding.global.aop; -import com.tukorea.planding.domain.notify.service.NotificationHandler; import com.tukorea.planding.domain.notify.service.schedule.PersonalScheduleNotificationHandler; import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest; import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import lombok.RequiredArgsConstructor; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; @@ -20,16 +19,16 @@ public class PersonalNotificationAspect { /** * 스케줄 생성시 알람 등록 * - * @param userInfo + * @param userResponse * @param personalScheduleRequest * @param personalScheduleResponse */ - @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.createSchedule(..)) && args(userInfo, personalScheduleRequest)", returning = "personalScheduleResponse", argNames = "userInfo,personalScheduleRequest,personalScheduleResponse") - public void registerNotification(UserInfo userInfo, PersonalScheduleRequest personalScheduleRequest, PersonalScheduleResponse personalScheduleResponse) { + @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.createSchedule(..)) && args(userResponse, personalScheduleRequest)", returning = "personalScheduleResponse", argNames = "userResponse,personalScheduleRequest,personalScheduleResponse") + public void registerNotification(UserResponse userResponse, PersonalScheduleRequest personalScheduleRequest, PersonalScheduleResponse personalScheduleResponse) { // 예약된 알림 등록 로직 // 1시간전 등록 - notificationHandler.registerScheduleBeforeOneHour(userInfo.getUserCode(), personalScheduleResponse); - notificationHandler.registerScheduleBeforeDay(userInfo.getUserCode(), personalScheduleResponse); + notificationHandler.registerScheduleBeforeOneHour(userResponse.getUserCode(), personalScheduleResponse); + notificationHandler.registerScheduleBeforeDay(userResponse.getUserCode(), personalScheduleResponse); } /** @@ -37,23 +36,23 @@ public void registerNotification(UserInfo userInfo, PersonalScheduleRequest pers * * @param scheduleId * @param personalScheduleRequest - * @param userInfo + * @param userResponse * @param personalScheduleResponse */ - @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.updateSchedule(..)) && args(scheduleId, personalScheduleRequest, userInfo)", returning = "personalScheduleResponse", argNames = "scheduleId,personalScheduleRequest,userInfo,personalScheduleResponse") - public void updateNotification(Long scheduleId, PersonalScheduleRequest personalScheduleRequest, UserInfo userInfo, PersonalScheduleResponse personalScheduleResponse) { + @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.updateSchedule(..)) && args(scheduleId, personalScheduleRequest, userResponse)", returning = "personalScheduleResponse", argNames = "scheduleId,personalScheduleRequest,userResponse,personalScheduleResponse") + public void updateNotification(Long scheduleId, PersonalScheduleRequest personalScheduleRequest, UserResponse userResponse, PersonalScheduleResponse personalScheduleResponse) { // 예약된 알림 등록 로직을 수정 - notificationHandler.updateScheduleBeforeOneHour(scheduleId, personalScheduleResponse, userInfo); + notificationHandler.updateScheduleBeforeOneHour(scheduleId, personalScheduleResponse, userResponse); } /** * 스케줄 삭제시 알람 삭제 * * @param scheduleId - * @param userInfo + * @param userResponse */ - @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.deleteSchedule(..)) && args(userInfo, scheduleId)", argNames = "scheduleId,userInfo") - public void deleteNotification(Long scheduleId, UserInfo userInfo) { + @AfterReturning(pointcut = "execution(* com.tukorea.planding.domain.schedule.service.PersonalScheduleService.deleteSchedule(..)) && args(userResponse, scheduleId)", argNames = "scheduleId,userResponse") + public void deleteNotification(Long scheduleId, UserResponse userResponse) { // 예약된 알림 삭제 notificationHandler.deleteScheduleBeforeOneHour(scheduleId); } diff --git a/src/main/java/com/tukorea/planding/global/config/CacheConfig.java b/src/main/java/com/tukorea/planding/global/config/CacheConfig.java index 8c7d937..a0bdec0 100644 --- a/src/main/java/com/tukorea/planding/global/config/CacheConfig.java +++ b/src/main/java/com/tukorea/planding/global/config/CacheConfig.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; -import com.tukorea.planding.domain.user.dto.UserInfo; import lombok.RequiredArgsConstructor; import org.springframework.cache.CacheManager; import org.springframework.context.annotation.Bean; @@ -15,8 +14,6 @@ import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.StringRedisSerializer; -import java.util.LinkedHashMap; - @Configuration @RequiredArgsConstructor public class CacheConfig { diff --git a/src/main/java/com/tukorea/planding/global/config/security/jwt/JwtAuthenticationFilter.java b/src/main/java/com/tukorea/planding/global/config/security/jwt/JwtAuthenticationFilter.java index 4b06c9d..a460136 100644 --- a/src/main/java/com/tukorea/planding/global/config/security/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/tukorea/planding/global/config/security/jwt/JwtAuthenticationFilter.java @@ -3,9 +3,7 @@ import com.tukorea.planding.domain.auth.repository.TokenInfoCacheRepository; import com.tukorea.planding.domain.auth.service.TokenService; -import com.tukorea.planding.domain.user.dto.UserInfo; -import com.tukorea.planding.domain.user.entity.User; -import com.tukorea.planding.domain.user.repository.UserRepository; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; @@ -20,7 +18,6 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; import org.springframework.util.AntPathMatcher; import org.springframework.web.filter.OncePerRequestFilter; @@ -66,8 +63,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse } - private Authentication getAuthentication(UserInfo userInfo) { - return new UsernamePasswordAuthenticationToken(userInfo, null, List.of(new SimpleGrantedAuthority(userInfo.getRole().getAuthority()))); + private Authentication getAuthentication(UserResponse userResponse) { + return new UsernamePasswordAuthenticationToken(userResponse, null, List.of(new SimpleGrantedAuthority(userResponse.getRole().getAuthority()))); } /** @@ -118,8 +115,8 @@ private void checkRefreshTokenAndReIssueAccessToken( jwtUtil.sendAccessAndRefreshToken(response, newAccessToken, refreshToken); } - private void saveAuthentication(UserInfo userInfo) { - Authentication authentication = getAuthentication(userInfo); + private void saveAuthentication(UserResponse userResponse) { + Authentication authentication = getAuthentication(userResponse); SecurityContextHolder.getContext().setAuthentication(authentication); } diff --git a/src/main/java/com/tukorea/planding/global/oauth/details/CustomUserDetailsService.java b/src/main/java/com/tukorea/planding/global/oauth/details/CustomUserDetailsService.java index 2a93b0c..5208743 100644 --- a/src/main/java/com/tukorea/planding/global/oauth/details/CustomUserDetailsService.java +++ b/src/main/java/com/tukorea/planding/global/oauth/details/CustomUserDetailsService.java @@ -1,7 +1,6 @@ package com.tukorea.planding.global.oauth.details; -import com.tukorea.planding.domain.user.repository.UserRepository; -import com.tukorea.planding.domain.user.entity.User; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.service.UserQueryService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,6 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor @@ -20,7 +18,7 @@ public class CustomUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String userCode) throws UsernameNotFoundException { - User user = userQueryService.getUserByUserCode(userCode); - return new CustomUser(user.getUsername(), user.getEmail() ,user.getRole()); + UserDomain user = userQueryService.getUserByUserCode(userCode); + return new CustomUser(user.getUsername(), user.getEmail(), user.getRole()); } } diff --git a/src/main/java/com/tukorea/planding/global/oauth/service/CustomOAuth2Service.java b/src/main/java/com/tukorea/planding/global/oauth/service/CustomOAuth2Service.java index 5d15da0..9f907b3 100644 --- a/src/main/java/com/tukorea/planding/global/oauth/service/CustomOAuth2Service.java +++ b/src/main/java/com/tukorea/planding/global/oauth/service/CustomOAuth2Service.java @@ -1,9 +1,10 @@ package com.tukorea.planding.global.oauth.service; -import com.tukorea.planding.domain.user.repository.UserRepository; +import com.tukorea.planding.domain.user.entity.UserDomain; import com.tukorea.planding.domain.user.entity.SocialType; import com.tukorea.planding.domain.user.entity.User; -import com.tukorea.planding.domain.user.service.UserService; +import com.tukorea.planding.domain.user.repository.UserRepository; +import com.tukorea.planding.domain.user.service.UserCodeGeneratorImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -23,7 +24,7 @@ public class CustomOAuth2Service implements OAuth2UserService { private final UserRepository userRepository; - private final UserService userService; + private final UserCodeGeneratorImpl userCodeGenerator; @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { @@ -39,7 +40,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic OAuthAttributes extractAttributes = OAuthAttributes.of(socialType, userNameAttributeName, attributes); - User createdUser = getUser(extractAttributes, socialType); + UserDomain createdUser = getUser(extractAttributes, socialType); log.info("[" + registrationId + "]:OAuth 객체 생성"); return new CustomOAuth2User( @@ -54,8 +55,8 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic } - private User getUser(OAuthAttributes attributes, SocialType socialType) { - User findUser = userRepository.findBySocialTypeAndSocialId(socialType, + private UserDomain getUser(OAuthAttributes attributes, SocialType socialType) { + UserDomain findUser = userRepository.findBySocialTypeAndSocialId(socialType, attributes.getOauth2UserInfo().getOAuth2Id()).orElse(null); if (findUser == null) { @@ -66,11 +67,11 @@ private User getUser(OAuthAttributes attributes, SocialType socialType) { return findUser; } - private User saveUser(OAuthAttributes attributes, SocialType socialType) { + private UserDomain saveUser(OAuthAttributes attributes, SocialType socialType) { log.info("신규 회원가입"); - String userCode = userService.generateUniqueUserCode(); + String userCode = userCodeGenerator.generateUniqueUserCode(); User createdUser = attributes.toEntity(socialType, attributes.getOauth2UserInfo(), userCode); - return userRepository.save(createdUser); + return userRepository.save(createdUser.toModel()); } } diff --git a/src/test/java/com/tukorea/planding/domain/group/service/GroupRoomServiceTest.java b/src/test/java/com/tukorea/planding/domain/group/service/GroupRoomServiceTest.java index 31452a3..8d2f215 100644 --- a/src/test/java/com/tukorea/planding/domain/group/service/GroupRoomServiceTest.java +++ b/src/test/java/com/tukorea/planding/domain/group/service/GroupRoomServiceTest.java @@ -5,7 +5,7 @@ import com.tukorea.planding.domain.group.entity.UserGroup; import com.tukorea.planding.domain.group.service.query.GroupQueryService; import com.tukorea.planding.domain.group.service.query.UserGroupQueryService; -import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.dto.UserResponse; import com.tukorea.planding.domain.user.entity.SocialType; import com.tukorea.planding.domain.user.entity.User; import com.tukorea.planding.global.oauth.details.Role; @@ -17,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; @Transactional class GroupRoomServiceTest { @@ -51,7 +50,7 @@ void setUp(){ when(groupQueryService.getGroupByCode("G-1234")).thenReturn(groupRoom); GroupInformationResponse response=groupRoomService.getGroupUsers( - UserInfo.builder() + UserResponse.builder() .userCode("#1234") .build(),"G-1234" ); diff --git a/src/test/java/com/tukorea/planding/domain/user/entity/UserDomainTest.java b/src/test/java/com/tukorea/planding/domain/user/entity/UserDomainTest.java new file mode 100644 index 0000000..bdf10e0 --- /dev/null +++ b/src/test/java/com/tukorea/planding/domain/user/entity/UserDomainTest.java @@ -0,0 +1,97 @@ +package com.tukorea.planding.domain.user.entity; + +import com.tukorea.planding.common.service.UserCodeHolder; +import com.tukorea.planding.domain.user.dto.AndroidLoginResponse; +import com.tukorea.planding.global.oauth.details.Role; +import com.tukorea.planding.mock.TestUserCodeHolder; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class UserDomainTest { + + @Test + void User를_생성_할_수_있다() { + UserCodeHolder userCodeHolder=new TestUserCodeHolder("1234"); + UserDomain userDomain = UserDomain.builder() + .id(1L) + .email("ksu9541@tukorea.ac.kr") + .username("ksu9541") + .socialId("1") + .socialType(SocialType.KAKAO) + .profileImage("https://naver.com") + .alarm(true) + .userCode(userCodeHolder.userCode()) + .role(Role.USER) + .build(); + + User user = User.fromModel(userDomain); + + assertThat(user.getEmail()).isEqualTo("ksu9541@tukorea.ac.kr"); + assertThat(user.getUsername()).isEqualTo("ksu9541"); + assertThat(user.getUserCode()).isEqualTo("1234"); + } + + @Test + void User는_fcmToken_필드를_업데이트_할_수_있다() { + UserDomain userDomain = UserDomain.builder() + .id(1L) + .email("ksu9541@tukorea.ac.kr") + .username("ksu9541") + .socialId("1") + .socialType(SocialType.KAKAO) + .profileImage("https://naver.com") + .alarm(true) + .role(Role.USER) + .fcmToken("aaaa-aaaa-aaaa-aaaa") + .build(); + + userDomain = userDomain.updateFcmToken("bbbb-bbbb-bbbb"); + + assertThat(userDomain.getFcmToken()).isEqualTo("bbbb-bbbb-bbbb"); + } + + @Test + void User는_alarm_필드를_업데이트_할_수_있다() { + UserDomain userDomain = UserDomain.builder() + .id(1L) + .email("ksu9541@tukorea.ac.kr") + .username("ksu9541") + .socialId("1") + .socialType(SocialType.KAKAO) + .profileImage("https://naver.com") + .alarm(true) + .role(Role.USER) + .fcmToken("aaaa-aaaa-aaaa-aaaa") + .build(); + + userDomain = userDomain.updateAlarm(false); + + assertThat(userDomain.isAlarm()).isEqualTo(false); + } + + + @Test + void User는_Android_객체로_수정할_수_있다() { + UserDomain userDomain = UserDomain.builder() + .id(1L) + .email("ksu9541@tukorea.ac.kr") + .username("ksu9541") + .socialId("1") + .socialType(SocialType.KAKAO) + .profileImage("https://naver.com") + .alarm(true) + .role(Role.USER) + .fcmToken("aaaa-aaaa-aaaa-aaaa") + .build(); + + String accessToken="accessToken"; + String refreshToken="refreshToken"; + + AndroidLoginResponse response=AndroidLoginResponse.toAndroidLoginResponse(userDomain,accessToken,refreshToken); + + assertThat(response.getAccessToken()).isEqualTo("accessToken"); + assertThat(response.getRefreshToken()).isEqualTo("refreshToken"); + } + +} \ No newline at end of file diff --git a/src/test/java/com/tukorea/planding/domain/user/service/UserServiceTest.java b/src/test/java/com/tukorea/planding/domain/user/service/UserServiceTest.java new file mode 100644 index 0000000..c362316 --- /dev/null +++ b/src/test/java/com/tukorea/planding/domain/user/service/UserServiceTest.java @@ -0,0 +1,82 @@ +package com.tukorea.planding.domain.user.service; + +import com.tukorea.planding.common.service.UserCodeHolder; +import com.tukorea.planding.domain.group.service.port.RedisGroupInviteService; +import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; +import com.tukorea.planding.domain.user.dto.ProfileResponse; +import com.tukorea.planding.domain.user.entity.UserDomain; +import com.tukorea.planding.domain.user.service.port.UserCodeGenerator; +import com.tukorea.planding.global.oauth.details.Role; +import com.tukorea.planding.mock.FakeRedisGroupInviteService; +import com.tukorea.planding.mock.FakeUserRepository; +import com.tukorea.planding.mock.TestUserCodeGenerator; +import com.tukorea.planding.mock.TestUserCodeHolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + + +class UserServiceTest { + + private UserService userService; + + @BeforeEach + void init() { + UserCodeHolder testUserCodeHolder = new TestUserCodeHolder("#1234"); // 유저 코드 생성 + UserCodeGenerator userCodeGenerator = new TestUserCodeGenerator(); // 유저코드 생성전 중복되지않는 유저코드 생성하는 역할 + FakeUserRepository fakeUserRepository = new FakeUserRepository(); + UserQueryService userQueryService = new UserQueryService(fakeUserRepository); + + + RedisGroupInviteService redisGroupInviteService = new FakeRedisGroupInviteService(); + this.userService = UserService.builder() + .userCodeGenerator(userCodeGenerator) + .redisGroupInviteService(redisGroupInviteService) + .userQueryService(userQueryService) + .build(); + + fakeUserRepository.save(UserDomain.builder() + .id(1L) + .email("ksu9541@tukorea.ac.kr") + .username("ksu9541") + .userCode(testUserCodeHolder.userCode()) + .fcmToken("aaaa-aaaa-aaaa-aaaa") + .alarm(true) + .role(Role.USER) + .build()); + } + + + @Test + void 안드로이드_유저를_생성할_수_있다() { + AndroidLoginRequest androidLoginRequest = AndroidLoginRequest.builder() + .accountEmail("test@naver.com") + .profileNickname("android") + .socialId("1111") + .profileImage("https://image") + .build(); + UserDomain result = userService.createAndroid(androidLoginRequest); + + assertThat(result).isNotNull(); + assertThat(result.getEmail()).isEqualTo("test@naver.com"); + assertThat(result.getUserCode()).isEqualTo("1"); + } + + @Test + void User의_프로필_을_조회할_수_있다() { + ProfileResponse profile = userService.getProfile(1L); + + assertThat(profile.userCode()).isEqualTo("#1234"); + assertThat(profile.email()).isEqualTo("ksu9541@tukorea.ac.kr"); + } + + @Test + void User코드를_통해_FCM_토큰을_조회할_수_있다() { + String fcmToken = userService.getFcmTokenByUserCode("#1234"); + + assertThat(fcmToken).isEqualTo("aaaa-aaaa-aaaa-aaaa"); + } + + +} \ No newline at end of file diff --git a/src/test/java/com/tukorea/planding/mock/FakeRedisGroupInviteService.java b/src/test/java/com/tukorea/planding/mock/FakeRedisGroupInviteService.java new file mode 100644 index 0000000..f78e80b --- /dev/null +++ b/src/test/java/com/tukorea/planding/mock/FakeRedisGroupInviteService.java @@ -0,0 +1,34 @@ +package com.tukorea.planding.mock; + +import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse; +import com.tukorea.planding.domain.group.service.port.RedisGroupInviteService; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FakeRedisGroupInviteService implements RedisGroupInviteService { + private final Map> invitations = new HashMap<>(); + + @Override + public void createInvitation(String userCode, GroupInviteMessageResponse inviteDTO) { + String inviteCode = inviteDTO.getInviteCode(); + invitations + .computeIfAbsent(userCode, k -> new HashMap<>()) + .put(inviteCode, inviteDTO); + } + + @Override + public List getAllInvitations(String userCode) { + return new ArrayList<>(invitations.getOrDefault(userCode, new HashMap<>()).values()); + } + + @Override + public void deleteInvitation(String userCode, String inviteCode) { + Map userInvitations = invitations.get(userCode); + if (userInvitations != null) { + userInvitations.remove(inviteCode); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/tukorea/planding/mock/FakeUserRepository.java b/src/test/java/com/tukorea/planding/mock/FakeUserRepository.java new file mode 100644 index 0000000..71effdd --- /dev/null +++ b/src/test/java/com/tukorea/planding/mock/FakeUserRepository.java @@ -0,0 +1,67 @@ +package com.tukorea.planding.mock; + +import com.tukorea.planding.domain.user.entity.SocialType; +import com.tukorea.planding.domain.user.entity.UserDomain; +import com.tukorea.planding.domain.user.repository.UserRepository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public class FakeUserRepository implements UserRepository { + private Long count = 0L; + private final List data = new ArrayList<>(); + + @Override + public Optional findByUserCode(String userCode) { + return data.stream().filter(item -> item.getUserCode().equals(userCode)).findAny(); + } + + @Override + public Optional findByEmail(String email) { + return data.stream().filter(item -> item.getEmail().equals(email)).findAny(); + } + + @Override + public Optional getUserById(Long userId) { + return data.stream().filter(item -> item.getId().equals(userId)).findAny(); + } + + @Override + public Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId) { + return data.stream() + .filter(user -> user.getSocialType().equals(socialType) && user.getSocialId().equals(socialId)) + .findFirst(); + } + + @Override + public boolean existsByUserCode(String userCode) { + return data.stream() + .anyMatch(user -> user.getUserCode().equals(userCode)); + } + + @Override + public UserDomain save(UserDomain userDomain) { + if (userDomain.getId() == null || userDomain.getId() == 0) { + UserDomain newUser = UserDomain.builder() + .id(count++) + .email(userDomain.getEmail()) + .userCode(userDomain.getUserCode()) + .username(userDomain.getUsername()) + .role(userDomain.getRole()) + .alarm(userDomain.isAlarm()) + .fcmToken(userDomain.getFcmToken()) + .profileImage(userDomain.getProfileImage()) + .socialId(userDomain.getSocialId()) + .socialType(userDomain.getSocialType()) + .build(); + data.add(newUser); + return newUser; + } else { + data.removeIf(item -> Objects.equals(item.getId(), userDomain.getId())); + data.add(userDomain); + return userDomain; + } + } +} diff --git a/src/test/java/com/tukorea/planding/mock/TestUserCodeGenerator.java b/src/test/java/com/tukorea/planding/mock/TestUserCodeGenerator.java new file mode 100644 index 0000000..f85a263 --- /dev/null +++ b/src/test/java/com/tukorea/planding/mock/TestUserCodeGenerator.java @@ -0,0 +1,13 @@ +package com.tukorea.planding.mock; + +import com.tukorea.planding.domain.user.service.port.UserCodeGenerator; + +public class TestUserCodeGenerator implements UserCodeGenerator { + + private int count = 1; + + @Override + public String generateUniqueUserCode() { + return String.valueOf(count++); + } +} diff --git a/src/test/java/com/tukorea/planding/mock/TestUserCodeHolder.java b/src/test/java/com/tukorea/planding/mock/TestUserCodeHolder.java new file mode 100644 index 0000000..6098561 --- /dev/null +++ b/src/test/java/com/tukorea/planding/mock/TestUserCodeHolder.java @@ -0,0 +1,16 @@ +package com.tukorea.planding.mock; + +import com.tukorea.planding.common.service.UserCodeHolder; +public class TestUserCodeHolder implements UserCodeHolder { + + private final String userCode; + + public TestUserCodeHolder(String userCode) { + this.userCode = userCode; + } + + @Override + public String userCode() { + return userCode; + } +}