Skip to content

Commit

Permalink
๐Ÿงช [Test] && ๐Ÿ› [Bug] ๋ฐฉ ์‹œ์ž‘ํ•˜๊ธฐ ๋ฐ ์ฐธ์—ฌํ•˜๊ธฐ์—์„œ ์‹œ์ž‘๋˜๋Š” ๋ถ€๋ถ„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ && ๋งˆ๊ฐ๋œ ๋ฐฉ && Finโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆish๋ฐฉ Intra์กฐํšŒ (#768)
  • Loading branch information
AreSain authored Mar 25, 2024
1 parent 61520af commit e3f3193
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class RoomStatusService {
@Transactional
public void finishStartedRooms() {
LocalDateTime twoHoursAgo = LocalDateTime.now().minusHours(2);
List<Room> startedRooms = roomRepository.findByStatus(RoomType.START, null);
List<Room> startedRooms = roomRepository.findByStatusAndStartDate(RoomType.START, twoHoursAgo);
for (Room room : startedRooms) {
room.updateRoomStatus(RoomType.FINISH);
roomRepository.save(room);
log.info("Room {} status updated to FINISH", room.getId());
log.info("{}๋ฒˆ ๋ฐฉ์ด ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", room.getId());
}
}

Expand All @@ -45,7 +45,7 @@ public void failOpenedRooms() {
if (room.getDueDate().isBefore(now)) {
room.updateRoomStatus(RoomType.FAIL);
roomRepository.save(room);
log.info("Room {} status updated to FAIL", room.getId());
log.info("{}๋ฒˆ ๋ฐฉ์ด ์‹œ๊ฐ„์ด ์ง€๋‚˜ Fail๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", room.getId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.transaction.Transactional;

Expand Down Expand Up @@ -44,9 +45,15 @@ public RoomListResDto findRoomList() {

List<Room> notStartedRooms = roomRepository.findByStatus(RoomType.OPEN, sortForNotStarted);
List<Room> startedRooms = roomRepository.findByStatus(RoomType.START, sortForStarted);
List<Room> finishRooms = roomRepository.findByStatus(RoomType.FINISH, sortForStarted);

notStartedRooms.addAll(startedRooms);
List<RoomResDto> roomListResDto = notStartedRooms.stream()
List<Room> limitedFinishRooms = finishRooms.stream().limit(10).collect(Collectors.toList());

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

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

Expand Down Expand Up @@ -126,7 +133,8 @@ public RoomDetailResDto findRoomDetail(Long userId, Long roomId) {
room.getHost().getId(), roomId);
String hostNickname = hostUserRoomOptional.get().getNickname();

if (room.getStatus() == RoomType.START && userRoomOptional.isPresent()) {
if ((room.getStatus() == RoomType.START || room.getStatus() == RoomType.FINISH)
&& userRoomOptional.isPresent()) {
List<CommentResDto> comments = commentRepository.findByRoomId(roomId).stream()
.map(comment -> new CommentResDto(comment, comment.getUser().getIntraId()))
.collect(Collectors.toList());
Expand All @@ -137,7 +145,7 @@ public RoomDetailResDto findRoomDetail(Long userId, Long roomId) {
userRoom.getUser().getImageUri()))
.collect(Collectors.toList());
return new RoomDetailResDto(room, myNickname, hostNickname, roomUsers, comments);
} else { // if ์ฐธ์—ฌ์ž && ์‹œ์ž‘ํ–ˆ์„๊ฒฝ์šฐ intraID || else intraId == null
} else { // if ์ฐธ์—ฌ์ž && Start or Finish ์ƒํƒœ์ธ ๊ฒฝ์šฐ intraID || else intraId == null
List<CommentResDto> comments = commentRepository.findByRoomId(roomId).stream()
.map(CommentResDto::new)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public LeaveRoomResDto modifyLeaveRoom(Long roomId, UserDto user) {
// ๋ฐฉ์žฅ ์ด๊ถŒ
if (user.getId().equals(targetRoom.getHost().getId())) {
List<User> existUser = userRoomRepository.findByIsExist(roomId);
targetRoom.updateHost(existUser.get(0));
if (existUser != null && !existUser.isEmpty()) {
targetRoom.updateHost(existUser.get(0));
} else {
targetRoom.updateHost(null);
}
}
userRoomRepository.save(targetUserRoom);
roomRepository.save(targetRoom);
Expand All @@ -127,14 +131,13 @@ public LeaveRoomResDto modifyLeaveRoom(Long roomId, UserDto user) {
/**
* ๋ฐฉ์„ ์‹œ์ž‘ ์ƒํƒœ๋กœ ๋ฐ”๊พผ๋‹ค
* ๋ฐฉ์˜ ์ƒํƒœ๋ฅผ ์‹œ์ž‘ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ.
*
* @param roomId, user
* @return ๋ฐฉ id
* @throws RoomNotFoundException ๋ฐฉ ์—†์Œ
* @throws RoomNotOpenException ๋ฐฉ์ด ์—ด๋ฆฌ์ง€ ์•Š์€ ์ƒํƒœ
* @throws RoomNotEnoughPeopleException ๋ฐฉ์— ์ถฉ๋ถ„ํ•œ ์ธ์›์ด ์—†์Œ
* @throws RoomNotParticipantException ๋ฐฉ์— ์ฐธ๊ฐ€ํ•˜์ง€ ์•Š์€ ์œ ์ €
* @throws UserNotHostException ๋ฐฉ์žฅ์ด ์•„๋‹Œ ๊ฒฝ์šฐ
* @throws RoomNotFoundException ๋ฐฉ ์—†์Œ - 404
* @throws RoomNotOpenException ๋ฐฉ์ด ์—ด๋ฆฌ์ง€ ์•Š์€ ์ƒํƒœ - 400
* @throws RoomNotEnoughPeopleException ๋ฐฉ์— ์ถฉ๋ถ„ํ•œ ์ธ์›์ด ์—†์Œ - 400
* @throws RoomNotParticipantException ๋ฐฉ์— ์ฐธ๊ฐ€ํ•˜์ง€ ์•Š์€ ์œ ์ € - 400
* @throws UserNotHostException ๋ฐฉ์žฅ์ด ์•„๋‹Œ ๊ฒฝ์šฐ - 403
*/
@Transactional
public RoomStartResDto modifyStartRoom(Long roomId, UserDto user) {
Expand Down
Loading

0 comments on commit e3f3193

Please sign in to comment.