Skip to content

Commit

Permalink
Merge pull request #22 from 2024-Hanium-PlanDing/UserTest
Browse files Browse the repository at this point in the history
refactor: ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์„ค๊ณ„ ์œ ์—ฐ์„ฑ ๊ฐœ์„  (Userํ…Œ์ŠคํŠธ)
  • Loading branch information
SangWoon123 authored Nov 7, 2024
2 parents ceac2d6 + 2d21a80 commit deb120f
Show file tree
Hide file tree
Showing 71 changed files with 1,140 additions and 454 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/tukorea/planding/common/JsonConverter.java
Original file line number Diff line number Diff line change
@@ -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> T convertJsonToObject(String json, Class<T> clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tukorea.planding.common.service;

public interface UserCodeHolder {
String userCode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -28,15 +22,15 @@ public class ChatController {
private final ChatService chatService;

@PostMapping("/{groupCode}")
public CommonResponse<MessageResponse> sendMessage(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @RequestBody MessageRequest request) {
MessageResponse messageResponse = chatService.sendMessage(userInfo.getUserCode(), request, groupCode);
public CommonResponse<MessageResponse> 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<List<MessageResponse>> getMessages(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) {
List<MessageResponse> responses = chatService.getMessages(userInfo, groupCode);
public CommonResponse<List<MessageResponse>> getMessages(@AuthenticationPrincipal UserResponse userResponse, @PathVariable String groupCode) {
List<MessageResponse> responses = chatService.getMessages(userResponse, groupCode);
return CommonUtils.success(responses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand All @@ -53,8 +54,8 @@ public MessageResponse sendMessage(String sender, MessageRequest messageDTO, Str
return response;
}

public List<MessageResponse> getMessages(UserInfo userInfo, String groupCode) {
if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode())) {
public List<MessageResponse> getMessages(UserResponse userResponse, String groupCode) {
if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userResponse.getUserCode())) {
throw new BusinessException(ErrorCode.ACCESS_DENIED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,21 +24,21 @@ public class GroupFavoriteController {

@Operation(summary = "์ฆ๊ฒจ์ฐพ๊ธฐ ๊ทธ๋ฃน ์กฐํšŒ")
@GetMapping()
public CommonResponse<List<GroupResponse>> searchFavorite(@AuthenticationPrincipal UserInfo userInfo) {
return CommonUtils.success(groupFavoriteService.findFavoriteGroupsByUser(userInfo));
public CommonResponse<List<GroupResponse>> searchFavorite(@AuthenticationPrincipal UserResponse userResponse) {
return CommonUtils.success(groupFavoriteService.findFavoriteGroupsByUser(userResponse));
}

@Operation(summary = "๊ทธ๋ฃน ์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ”๊ฐ€")
@PostMapping("/{groupCode}")
public CommonResponse<GroupFavoriteResponse> addFavorite(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) {
GroupFavoriteResponse response = groupFavoriteService.addFavorite(userInfo, groupCode);
public CommonResponse<GroupFavoriteResponse> 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("์ฆ๊ฒจ์ฐพ๊ธฐ ํ•ด์ œ ์™„๋ฃŒ.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,28 +24,28 @@ public class GroupInviteController {

@Operation(summary = "์œ ์ €์—๊ฒŒ ์ดˆ๋Œ€๋ฅผ ๋ณด๋‚ธ๋‹ค")
@PostMapping()
public CommonResponse<GroupInviteMessageResponse> invite(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupInviteRequest groupInviteRequest) {
return CommonUtils.success(groupInviteService.inviteGroupRoom(userInfo, groupInviteRequest));
public CommonResponse<GroupInviteMessageResponse> invite(@AuthenticationPrincipal UserResponse userResponse, @RequestBody GroupInviteRequest groupInviteRequest) {
return CommonUtils.success(groupInviteService.inviteGroupRoom(userResponse, groupInviteRequest));
}

@Operation(summary = "์ดˆ๋Œ€๋ฅผ ์ˆ˜๋ฝํ•œ๋‹ค")
@GetMapping("/accept/{groupCode}/{inviteCode}")
public CommonResponse<GroupInviteAcceptResponse> accept(@AuthenticationPrincipal UserInfo userInfo, @PathVariable(name = "groupCode") String groupCode, @PathVariable(name = "inviteCode") String code) {
GroupInviteAcceptResponse response = groupInviteService.acceptInvitation(userInfo, code, groupCode);
public CommonResponse<GroupInviteAcceptResponse> 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<List<GroupInviteMessageResponse>> getInvitations(@AuthenticationPrincipal UserInfo userInfo) {
List<GroupInviteMessageResponse> groupInviteResponse = groupInviteService.getInvitations(userInfo);
public CommonResponse<List<GroupInviteMessageResponse>> getInvitations(@AuthenticationPrincipal UserResponse userResponse) {
List<GroupInviteMessageResponse> 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("๊ฑฐ์ ˆํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -30,49 +29,49 @@ public class GroupRoomController {

@Operation(summary = "๋ฉ”์ธํŽ˜์ด์ง€ API", description = "๋‚ด ๊ทธ๋ฃน ๊ฐ€์ ธ์˜ค๊ธฐ")
@GetMapping("/paging")
public CommonResponse<List<GroupResponse>> getAllGroupRoomByUser(@AuthenticationPrincipal UserInfo userInfo,
public CommonResponse<List<GroupResponse>> getAllGroupRoomByUser(@AuthenticationPrincipal UserResponse userResponse,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "11") int size) {

PageRequest pageRequest = PageRequest.of(page, size);
List<GroupResponse> groupResponses = groupRoomService.getAllGroupRoomByUser(userInfo, pageRequest);
List<GroupResponse> groupResponses = groupRoomService.getAllGroupRoomByUser(userResponse, pageRequest);
return CommonUtils.success(groupResponses);
}

@Operation(summary = "๊ทธ๋ฃน ์ •๋ณด ์กฐํšŒ")
@GetMapping("/{groupCode}")
public CommonResponse<GroupInformationResponse> getUserByGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode) {
GroupInformationResponse responses = groupRoomService.getGroupUsers(userInfo, groupCode);
public CommonResponse<GroupInformationResponse> 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<GroupResponse> createGroupRoom(@AuthenticationPrincipal UserInfo userInfo,
public CommonResponse<GroupResponse> 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<GroupResponse> updateGroupNameOrDescription(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupUpdateRequest groupUpdateRequest) {
GroupResponse groupResponses = groupRoomService.updateGroupNameOrDescription(userInfo, groupUpdateRequest);
public CommonResponse<GroupResponse> 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("๊ทธ๋ฃน ๋‚˜๊ฐ€๊ธฐ ์™„๋ฃŒ.");
}
}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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<UserGroupDomain> userGroups = new HashSet<>();

private final List<GroupSchedule> groupSchedules = new ArrayList<>();

private final List<GroupFavoriteDomain> groupFavorites = new ArrayList<>();

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit deb120f

Please sign in to comment.