Skip to content

Commit

Permalink
πŸ› [Bug] [Refactoring] 6κΈ° Party μ„œλΉ„μŠ€ 전체 λ¦¬νŒ©ν† λ§ 쀑 찾은 버그듀 μˆ˜μ • (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Mar 27, 2024
1 parent b72317a commit 7c2d9d0
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class CategoryListResDto {
private List<CategoryResDto> categoryList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class CommentResDto {
private Long commentId;
private String nickname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class LeaveRoomResDto {
private String nickname;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomCreateResDto {
private Long roomId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomDetailResDto {
private Long roomId;
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomJoinResDto {
private Long roomId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomListResDto {
private List<RoomResDto> roomList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomResDto {
private Long roomId;
private String categoryName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class RoomStartResDto {
private Long roomId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class UserRoomResDto {
private Long roomUserId;
private String nickname;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package gg.party.api.user.room.service;

import java.util.Collections;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.transaction.Transactional;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.data.party.Room;
import gg.data.party.UserRoom;
Expand Down Expand Up @@ -38,18 +36,28 @@ public class RoomFindService {
* μ‹œμž‘ν•˜μ§€ μ•Šμ€ λ°©κ³Ό μ‹œμž‘ν•œ 방을 λͺ¨λ‘ μ‘°νšŒν•œλ‹€
* @return μ‹œμž‘ν•˜μ§€ μ•Šμ€ λ°© (μ΅œμ‹ μˆœ) + μ‹œμž‘ν•œ λ°©(λλ‚˜λŠ” μ‹œκ°„μ΄ λΉ λ₯Έ 순) 전체 List
*/
@Transactional
@Transactional(readOnly = true)
public RoomListResDto findRoomList() {
Sort sortForNotStarted = Sort.by("createdAt").descending();
Sort sortForStarted = Sort.by("startDate").descending();
List<RoomType> statuses = Arrays.asList(RoomType.OPEN, RoomType.START, RoomType.FINISH);
List<Room> rooms = roomRepository.findByStatusIn(statuses);

List<Room> notStartedRooms = roomRepository.findByStatus(RoomType.OPEN, sortForNotStarted);
List<Room> startedRooms = roomRepository.findByStatus(RoomType.START, sortForStarted);
List<Room> finishRooms = roomRepository.findByStatus(RoomType.FINISH, sortForStarted);
List<Room> openRooms = rooms.stream()
.filter(room -> room.getStatus() == RoomType.OPEN)
.sorted(Comparator.comparing(Room::getCreatedAt).reversed())
.collect(Collectors.toList());

List<Room> limitedFinishRooms = finishRooms.stream().limit(10).collect(Collectors.toList());
List<Room> startRooms = rooms.stream()
.filter(room -> room.getStatus() == RoomType.START)
.sorted(Comparator.comparing(Room::getStartDate).reversed())
.collect(Collectors.toList());

List<Room> finishRooms = rooms.stream()
.filter(room -> room.getStatus() == RoomType.FINISH)
.sorted(Comparator.comparing(Room::getStartDate).reversed())
.limit(10)
.collect(Collectors.toList());

List<Room> combinedRooms = Stream.of(notStartedRooms, startedRooms, limitedFinishRooms)
List<Room> combinedRooms = Stream.of(openRooms, startRooms, finishRooms)
.flatMap(List::stream)
.collect(Collectors.toList());

Expand All @@ -62,43 +70,48 @@ public RoomListResDto findRoomList() {

/**
* ν˜„μž¬ 참여쀑인 방을 λͺ¨λ‘ μ‘°νšŒν•œλ‹€(λ§Œλ“  λ°© 포함)
* μ‹œμž‘ν•œ λ°© 뒀에 μ‹œμž‘ν•˜μ§€ μ•Šμ€ 방이 였게 μž‘μ„±
* @param userId μžμ‹ μ˜ id
* @return μ°Έμ—¬ν•œ λ°© 전체 List
*/
@Transactional
@Transactional(readOnly = true)
public RoomListResDto findJoinedRoomList(Long userId) {
List<UserRoom> userRooms = userRoomRepository.findByUserId(userId);
List<Room> joinedRooms = userRooms.stream()
.map(UserRoom::getRoom)
.collect(Collectors.toList());

Collections.sort(joinedRooms, Comparator.comparing(Room::getDueDate));
List<Room> openRoom = joinedRooms.stream()
.filter(room -> room.getStatus() == RoomType.OPEN)
.sorted(Comparator.comparing(Room::getDueDate))
.collect(Collectors.toList());

List<Room> playingRoom = joinedRooms.stream()
.filter(room -> room.getStatus() == RoomType.OPEN || room.getStatus() == RoomType.START)
List<Room> startRoom = joinedRooms.stream()
.filter(room -> room.getStatus() == RoomType.START)
.sorted(Comparator.comparing(Room::getStartDate))
.collect(Collectors.toList());

Collections.sort(playingRoom, Comparator.comparing(Room::getDueDate));
startRoom.addAll(openRoom);

List<RoomResDto> roomListResDto = playingRoom.stream()
List<RoomResDto> roomListResDto = openRoom.stream()
.map(RoomResDto::new)
.collect(Collectors.toList());

return new RoomListResDto(roomListResDto);
}

/**
* μ‹œκ°„μ΄ μ§€λ‚˜ 보이지 μ•Šκ²Œ 된 λ‚΄κ°€ ν”Œλ ˆμ΄ν•œ(μ‹œμž‘ν•œ) 방을 λͺ¨λ‘ μ‘°νšŒν•œλ‹€
* μ‹œκ°„μ΄ μ§€λ‚˜ 보이지 μ•Šκ²Œ 된 λ‚΄κ°€ ν”Œλ ˆμ΄ν•œ(FINISH) 방을 λͺ¨λ‘ μ‘°νšŒν•œλ‹€
* @param userId μžμ‹ μ˜ id
* user_room dbμ—μ„œ μžμ‹ μ˜ id와 isExist이 true(λ‚˜κ°€μ§€ μ•Šμ•˜μŒ)
* μ΄λ©΄μ„œ statusκ°€ FINISH인 경우λ₯Ό λ§ˆκ°κΈ°ν•œ μ΅œμ‹ μˆœμœΌλ‘œ μ •λ ¬
* @return λλ‚œ λ°© 전체 List
* isExist이 true(λ‚˜κ°€μ§€ μ•Šμ•˜μŒ)μ΄λ©΄μ„œ statusκ°€ FINISH인 경우
* @return μ‹œμž‘μ‹œκ°„μœΌλ‘œ μ •λ ¬λœ λλ‚œ λ°© 전체 List
*/
@Transactional
@Transactional(readOnly = true)
public RoomListResDto findMyHistoryRoomList(Long userId) {
List<Room> finishRooms = userRoomRepository.findFinishRoomsByUserId(userId, RoomType.FINISH);
List<Room> finishRooms = userRoomRepository.findByUserIdAndStatusAndIsExistTrue(userId, RoomType.FINISH);

List<RoomResDto> roomListResDto = finishRooms.stream()
.sorted(Comparator.comparing(Room::getStartDate))
.map(RoomResDto::new)
.collect(Collectors.toList());

Expand All @@ -110,11 +123,11 @@ public RoomListResDto findMyHistoryRoomList(Long userId) {
* @param userId μžμ‹ μ˜ id
* @param roomId λ°© id
* @return λ°© 상세정보 dto
* @throws RoomNotFoundException μœ νš¨ν•˜μ§€ μ•Šμ€ λ°© μž…λ ₯
* @throws RoomReportedException μ‹ κ³  받은 λ°© 처리 | μ‹œμž‘ν•œ 방도 λ³Ό 수 있게 ν•΄μ•Όν•˜λ―€λ‘œ λ³„λ„μ²˜λ¦¬
* @throws RoomNotFoundException μœ νš¨ν•˜μ§€ μ•Šμ€ λ°© μž…λ ₯ - 404
* @throws RoomReportedException μ‹ κ³  받은 λ°© 처리 - 403
* 읡λͺ…성을 지킀기 μœ„ν•΄ nickname을 리턴
*/
@Transactional
@Transactional(readOnly = true)
public RoomDetailResDto findRoomDetail(Long userId, Long roomId) {
Room room = roomRepository.findById(roomId).orElseThrow(RoomNotFoundException::new);
if (room.getStatus() == RoomType.HIDDEN) {
Expand All @@ -125,37 +138,37 @@ public RoomDetailResDto findRoomDetail(Long userId, Long roomId) {

String myNickname = null;
if (userRoomOptional.isPresent()) {
UserRoom userRoom = userRoomOptional.get();
myNickname = userRoom.getNickname();
myNickname = userRoomOptional.get().getNickname();
}

Optional<UserRoom> hostUserRoomOptional = userRoomRepository.findByUserIdAndRoomIdAndIsExistTrue(
room.getHost().getId(), roomId);
String hostNickname = hostUserRoomOptional.get().getNickname();
Optional<UserRoom> hostUserRoom = userRoomRepository.findByUserIdAndRoomIdAndIsExistTrue(room.getHost().getId(),
roomId);
String hostNickname = hostUserRoom.get().getNickname();

if ((room.getStatus() == RoomType.START || room.getStatus() == RoomType.FINISH)
&& userRoomOptional.isPresent()) {
List<UserRoomResDto> roomUsers = userRoomRepository.findByRoomIdAndIsExistTrue(roomId).stream()
.map(userRoom -> new UserRoomResDto(userRoom, userRoom.getUser().getIntraId(),
userRoom.getUser().getImageUri()))
.collect(Collectors.toList());

List<CommentResDto> comments = commentRepository.findAllWithCommentFetchJoin(roomId).stream()
.filter(comment -> !comment.isHidden())
.map(comment -> new CommentResDto(comment, comment.getUser().getIntraId()))
.collect(Collectors.toList());

List<UserRoomResDto> roomUsers = userRoomRepository.findByRoomId(roomId).stream()
.filter(UserRoom::getIsExist)
.map(userRoom -> new UserRoomResDto(userRoom, userRoom.getUser().getIntraId(),
userRoom.getUser().getImageUri()))
.collect(Collectors.toList());
return new RoomDetailResDto(room, myNickname, hostNickname, roomUsers, comments);
} else { // if μ°Έμ—¬μž && Start or Finish μƒνƒœμΈ 경우 intraID || else intraId == null
} else { // if μ°Έμ—¬μž && Start or Finish μƒνƒœμΈ 경우 intraID 제곡 || else intraId == null
List<UserRoomResDto> roomUsers = userRoomRepository.findByRoomIdAndIsExistTrue(roomId).stream()
.map(UserRoomResDto::new)
.collect(Collectors.toList());

List<CommentResDto> comments = commentRepository.findAllWithCommentFetchJoin(roomId).stream()
.filter(comment -> !comment.isHidden())
.map(CommentResDto::new)
.collect(Collectors.toList());

List<UserRoomResDto> roomUsers = userRoomRepository.findByRoomId(roomId).stream()
.filter(UserRoom::getIsExist)
.map(UserRoomResDto::new)
.collect(Collectors.toList());
return new RoomDetailResDto(room, myNickname, hostNickname, roomUsers, comments);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ public LeaveRoomResDto modifyLeaveRoom(Long roomId, UserDto user) {
UserRoom targetUserRoom = userRoomRepository.findByUserAndRoom(userRepository.findById(user.getId()).get(),
targetRoom).orElseThrow(RoomNotParticipantException::new);

// λͺ¨λ‘ λ‚˜κ°ˆ λ•Œ λ°© fail처리
if (targetRoom.getCurrentPeople() == 1) {
targetRoom.updateCurrentPeople(0);
targetRoom.updateRoomStatus(RoomType.FAIL);
targetUserRoom.updateIsExist(false);
roomRepository.save(targetRoom);
userRoomRepository.save(targetUserRoom);
return new LeaveRoomResDto(targetUserRoom.getNickname());
}

targetRoom.updateCurrentPeople(targetRoom.getCurrentPeople() - 1);
targetUserRoom.updateIsExist(false);

Expand All @@ -124,8 +114,17 @@ public LeaveRoomResDto modifyLeaveRoom(Long roomId, UserDto user) {
targetRoom.updateHost(null);
}
}
userRoomRepository.save(targetUserRoom);

// λͺ¨λ‘ λ‚˜κ°ˆ λ•Œ λ°© fail처리
if (targetRoom.getCurrentPeople() == 0) {
targetRoom.updateRoomStatus(RoomType.FAIL);
roomRepository.save(targetRoom);
userRoomRepository.save(targetUserRoom);
return new LeaveRoomResDto(targetUserRoom.getNickname());
}

roomRepository.save(targetRoom);
userRoomRepository.save(targetUserRoom);

return new LeaveRoomResDto(targetUserRoom.getNickname());
}
Expand All @@ -136,27 +135,27 @@ public LeaveRoomResDto modifyLeaveRoom(Long roomId, UserDto user) {
* @param roomId, user
* @return λ°© id
* @throws RoomNotFoundException λ°© μ—†μŒ - 404
* @throws RoomNotOpenException 방이 열리지 μ•Šμ€ μƒνƒœ - 400
* @throws RoomNotEnoughPeopleException 방에 μΆ©λΆ„ν•œ 인원이 μ—†μŒ - 400
* @throws RoomNotParticipantException 방에 μ°Έκ°€ν•˜μ§€ μ•Šμ€ μœ μ € - 400
* @throws UserNotHostException λ°©μž₯이 μ•„λ‹Œ 경우 - 403
* @throws RoomNotOpenException 방이 열리지 μ•Šμ€ μƒνƒœ - 400
* @throws RoomNotEnoughPeopleException 방에 μΆ©λΆ„ν•œ 인원이 μ—†μŒ - 400
*/
@Transactional
public RoomStartResDto modifyStartRoom(Long roomId, UserDto user) {
Room targetRoom = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);
if (!targetRoom.getStatus().equals(RoomType.OPEN)) {
throw new RoomNotOpenException();
}
if (targetRoom.getMinPeople() > targetRoom.getCurrentPeople()
|| targetRoom.getMaxPeople() < targetRoom.getCurrentPeople()) {
throw new RoomNotEnoughPeopleException();
}
UserRoom targetUserRoom = userRoomRepository.findByUserAndRoom(userRepository.findById(user.getId()).get(),
targetRoom).orElseThrow(RoomNotParticipantException::new);
if (targetRoom.getHost() != targetUserRoom.getUser()) {
throw new UserNotHostException();
}
if (!targetRoom.getStatus().equals(RoomType.OPEN)) {
throw new RoomNotOpenException();
}
if (targetRoom.getMinPeople() > targetRoom.getCurrentPeople()) {
throw new RoomNotEnoughPeopleException();
}

targetRoom.updateRoomStatus(RoomType.START);
List<User> users = userRoomRepository.findByIsExist(roomId);
targetRoom.startRoom(LocalDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import java.util.Random;

/*
* 읡λͺ… λ‹‰λ„€μž„μ„ λ§Œλ“œλŠ” ν΄λž˜μŠ€μž…λ‹ˆλ‹€.
* PREFIX와 SUFFIX λ°°μ—΄μ—μ„œ 랜덀으둜 단어λ₯Ό μ„ νƒν•˜μ—¬ μ‘°ν•©ν•©λ‹ˆλ‹€.
* λ‘˜ 쀑 μ€‘λ³΅λ˜λŠ” μš”μ†Œλ„ κ°€λŠ₯ν•˜κ²Œ μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€. ex) μš©κ°ν•œ int, μš©κ°ν•œ string이 곡쑴할 수 μžˆμŠ΅λ‹ˆλ‹€.
* μ΅œλŒ€ 4κΈ€μž || 7κΈ€μžλ‘œ μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€.
*/
public class GenerateRandomNickname {
private String nickname;

private static final String[] PREFIX = {"μš©κ°ν•œ", "λŒ€λ‹΄ν•œ", "밝은", "λ›°μ–΄λ‚œ", "μΎŒν™œν•œ", "μ˜λ¦¬ν•œ", "λ„λ§κ°€λŠ”",
private static final String[] PREFIX = {"μš©κ°ν•œ", "λŒ€λ‹΄ν•œ", "밝은", "λ›°μ–΄λ‚œ", "μΎŒν™œν•œ", "μ˜λ¦¬ν•œ", "λ„λ§κ°€λŠ”", "λ“ λ“ ν•œ",
"λŒ€λ‹΄ν•œ", "열심인", "힘찬", "λΆˆκ°™μ€", "μ‹ μ„ ν•œ", "κ΄€λŒ€ν•œ", "μœ μΎŒν•œ", "ν–‰λ³΅ν•œ", "희망찬", "λͺ…λž‘ν•œ", "μΉœμ ˆν•œ", "ν™œκΈ°μ°¬",
"μ°©ν•œ", "μ΄μƒν•œ", "μžλž‘μŠ€λŸ¬μš΄", "λΉ λ₯Έ", "μ•ˆλ„ν•˜λŠ”", "μˆ˜μ€μ€", "어리석은", "κ°•ν•œ", "κ°μ‚¬ν•˜λŠ”", "νž˜λ“ ", "μš©κ°ν•œ", "열정적인",
"μ°©ν•œ", "μ΄μƒν•œ", "λΉ λ₯Έ", "μ•ˆλ„ν•˜λŠ”", "μˆ˜μ€μ€", "어리석은", "κ°•ν•œ", "κ°μ‚¬ν•˜λŠ”", "νž˜λ“ ", "μš©κ°ν•œ", "열정적인", "μ‘Έλ¦°",
"λ˜‘λ˜‘ν•œ", "즐거운", "ꡉμž₯ν•œ", "고수", "μ—„μ²­λ‚œ", "λœ¬κΈˆμ—†λŠ”", "좩무곡", "μ œλ„ˆλŸ΄", "μ— νŽ˜λŸ¬", "λ§ˆμ œμŠ€ν‹°", "νŒνƒ€μŠ€ν‹±", "λ ˆμ „λ”λ¦¬",
"λ¨ΌμΉ˜ν‚¨", "λ‹€ν¬ν˜ΈμŠ€", "μŠˆνΌλ£¨ν‚€", "μ—˜λ¦¬νŠΈ", "정점", "μ „κ΅νšŒμž₯", "λ² ν…Œλž‘"};
"λ¨ΌμΉ˜ν‚¨", "λ‹€ν¬ν˜ΈμŠ€", "μŠˆνΌλ£¨ν‚€", "μ—˜λ¦¬νŠΈ", "정점", "μ „κ΅νšŒμž₯", "λ² ν…Œλž‘", "ν‚Ή", "ν€Έ", "μ±”ν”Όμ–Έ"};

private static final String[] SUFFIX = {"list", "vector", "string", "boolean", "number", "object", "array",
"set", "map", "date", "function", "null", "undefined", "buffer", "json", "error", "stack", "queue", "deque",
"tree", "graph", "pair", "int", "char", "float", "double", "long", "longlong", "size_t", "short", "struct"};
private static final String[] SUFFIX = {"list", "vector", "string", "bool", "number", "object", "array",
"set", "map", "date", "null", "buffer", "json", "error", "stack", "queue", "deque", "struct", "tree",
"graph", "pair", "int", "char", "float", "double", "long", "size_t", "short", "byte", "bit", "pointer"};

public static String generateRandomNickname() {
Random random = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class TemplateController {
private final TemplateService templateService;

/**
* νƒ¬ν”Œλ¦Ώ λͺ©λ‘μ„ μ‘°νšŒν•œλ‹€
* @return νƒ¬ν”Œλ¦Ώ 전체 List
* ν…œν”Œλ¦Ώ 전체 쑰회
* @return ν…œν”Œλ¦Ώ 전체 리슀트 (κ°€λ‚˜λ‹€ 순으둜 μ •λ ¬) 200
*/
@GetMapping
public ResponseEntity<TemplateListResDto> templateList() {
Expand Down
Loading

0 comments on commit 7c2d9d0

Please sign in to comment.