Skip to content

Commit

Permalink
Merge pull request #138 from 1e5i-Shark/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
GiHoo authored Mar 18, 2024
2 parents 9ff61a4 + 2c4fd39 commit 61d8d78
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public void changeHostManually(

@Override
public void startCodingTest(String roomShortUuid, Long memberId) {
checkMemberIsHost(roomShortUuid, memberId);

RoomDetailResponseDto roomDetailResponseDto = roomService.startCodingTest(roomShortUuid);
Integer timeLimitMinute = roomDetailResponseDto.getTimeLimit();
messageService.sendMessage(
Expand All @@ -85,7 +87,13 @@ public void startCodingTest(String roomShortUuid, Long memberId) {

@Override
public void endCodingTest(String roomShortUuid, Long memberId) {
checkMemberIsHost(roomShortUuid, memberId);

roomService.completeSolveHistory(roomShortUuid);
messageService.sendMessage(roomShortUuid, MessageResponse.endCoding(memberId));
}

private void checkMemberIsHost(String roomShortUuid, Long memberId) {
roomMemberService.validateHost(roomShortUuid, memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public RoomDetailResponseDto createRoom(
}

@Override
@PatchMapping("/rooms/{roomId}")
public RoomResponseDto updateRoomById(@PathVariable(name = "roomId") Long roomId,
@PatchMapping("/rooms/{roomShortUuid}")
public RoomResponseDto updateRoomById(@PathVariable(name = "roomShortUuid") String roomShortUuid,
@RequestBody @Valid RoomUpdateRequestDto roomUpdateRequestDto) {
return roomService.updateRoomByRoomId(roomId, roomUpdateRequestDto);
return roomService.updateRoomByRoomId(roomShortUuid, roomUpdateRequestDto);
}

@Override
Expand Down
40 changes: 28 additions & 12 deletions src/main/java/ei/algobaroapi/domain/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,51 @@ public Room(RoomStatus roomStatus, String title, List<String> languages, LocalDa
}

public void update(RoomUpdateRequestDto roomUpdateRequestDto) {
if (roomUpdateRequestDto.getTitle() != null) {
if (roomUpdateRequestDto.getTitle() != null && !roomUpdateRequestDto.getTitle().isEmpty()) {
this.title = roomUpdateRequestDto.getTitle();
}
if (roomUpdateRequestDto.getLanguages() != null) {
this.languages = roomUpdateRequestDto.getLanguages();
}
if (roomUpdateRequestDto.getStartAt() != null) {

if (roomUpdateRequestDto.getStartAt() != null && roomUpdateRequestDto.getStartAt()
.isAfter(LocalDateTime.now())) {
this.startAt = roomUpdateRequestDto.getStartAt();
}

if (roomUpdateRequestDto.getLanguages() != null && !roomUpdateRequestDto.getLanguages()
.isEmpty()) {
this.languages = roomUpdateRequestDto.getLanguages();
}

if (roomUpdateRequestDto.getRoomAccessType() != null) {
this.roomAccessType = roomUpdateRequestDto.getRoomAccessType();
}
if (roomUpdateRequestDto.getProblemLink() != null) {

if (roomUpdateRequestDto.getProblemLink() != null && !roomUpdateRequestDto.getProblemLink()
.isEmpty()) {
this.problemLink = roomUpdateRequestDto.getProblemLink();
}
if (roomUpdateRequestDto.getProblemPlatform() != null) {

if (roomUpdateRequestDto.getProblemPlatform() != null
&& !roomUpdateRequestDto.getProblemPlatform().isEmpty()) {
this.problemPlatform = roomUpdateRequestDto.getProblemPlatform();
}
if (roomUpdateRequestDto.getPassword() != null) {

if (roomUpdateRequestDto.getPassword() != null && !roomUpdateRequestDto.getPassword()
.isEmpty()) {
this.password = roomUpdateRequestDto.getPassword();
}
if (roomUpdateRequestDto.getRoomLimit() > 0) {

if (roomUpdateRequestDto.getRoomLimit() != null
&& roomUpdateRequestDto.getRoomLimit() > 0) {
this.roomLimit = roomUpdateRequestDto.getRoomLimit();
}
if (roomUpdateRequestDto.getTags() != null) {

if (roomUpdateRequestDto.getTags() != null && !roomUpdateRequestDto.getTags().isEmpty()) {
this.tags = roomUpdateRequestDto.getTags();
}
if (roomUpdateRequestDto.getRoomLimit() != 0) {
this.roomLimit = roomUpdateRequestDto.getRoomLimit();

if (roomUpdateRequestDto.getTimeLimit() != null
&& roomUpdateRequestDto.getTimeLimit() > 0) {
this.timeLimit = roomUpdateRequestDto.getTimeLimit();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public interface RoomRepository extends JpaRepository<Room, Long>, RoomRepositoryQuery {

@Query("SELECT r FROM Room r WHERE r.roomUuid LIKE CONCAT(:roomShortUuid, '%')")
Optional<Room> findByRoomUuidStartingWith(String roomShortUuid); // TODO: 방 참여 기능 구현 후 쿼리 수정
Optional<Room> findByRoomUuidStartingWith(String roomShortUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface RoomService {

RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDto, Member member);

RoomResponseDto updateRoomByRoomId(Long roomId,
RoomResponseDto updateRoomByRoomId(String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto);

RoomDetailResponseDto getRoomDetailShortUuid(String roomShortUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDt

@Override
@Transactional
public RoomResponseDto updateRoomByRoomId(Long roomId,
public RoomResponseDto updateRoomByRoomId(String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto) {
Room room = roomRepository.findById(roomId)
.orElseThrow(() -> RoomNotFoundException.of(RoomErrorCode.ROOM_NOT_FOUND));
Room room = getRoomByShortUuid(roomShortUuid);

room.update(roomUpdateRequestDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public void markUnready() {
this.isReady = false;
}

public boolean isHost() {
return this.roomMemberRole == RoomMemberRole.HOST;
}

public boolean isParticipant() {
return this.roomMemberRole == RoomMemberRole.PARTICIPANT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ RoomHostAutoChangeResponseDto changeHostAutomatically(
List<RoomMember> getByRoomIdAllReady(Long roomId);

RoomExitResponse exitRoomByMemberId(Long memberId);

void validateHost(String roomShortUuid, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public RoomExitResponse exitRoomByMemberId(Long memberId) {
roomRepository.delete(findRoom);
} else {
// 방이 비지 않으면서 방장이 나갔을 경우 방장을 변경
if (roomMember.getRoomMemberRole() == RoomMemberRole.HOST) {
if (roomMember.isHost()) {
RoomHostAutoChangeResponseDto roomHostAutoChangeResponseDto = this.changeHostAutomatically(
HostAutoChangeRequestDto
.builder()
Expand All @@ -225,6 +225,21 @@ public RoomExitResponse exitRoomByMemberId(Long memberId) {
return RoomExitResponse.notChangedHost(findRoom.getId());
}

@Override
public void validateHost(String roomShortUuid, Long memberId) {
Room room = roomRepository.findByRoomUuidStartingWith(roomShortUuid)
.orElseThrow(() -> RoomNotFoundException.of(RoomErrorCode.ROOM_NOT_FOUND));

RoomMember roomMember = roomMemberRepository.findRoomMemberByRoomIdAndMemberId(room.getId(),
memberId)
.orElseThrow(() -> RoomMemberNotFoundException.of(
RoomMemberErrorCode.ROOM_MEMBER_ERROR_CODE));

if (!roomMember.isHost()) {
throw HostValidationException.of(RoomMemberErrorCode.ROOM_MEMBER_IS_NOT_HOST);
}
}

private void validateConditionToJoinRoom(Room room, String password) {
checkRoomIsRecruiting(room);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public SolveResultResponse getSolveResultInRoom(String roomShortUuid) {
}

@Override
@Transactional
public void setUpSolveHistory(Long memberId, String roomUuid, String problemLink) {
SolveHistory createSolveHistory = SolveHistory.builder()
.member(memberService.getMemberById(memberId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface RoomControllerDoc {
@Operation(summary = "방 수정", description = "방 정보를 수정합니다.")
@ApiResponse(responseCode = "200", description = "방 수정 성공")
@ApiResponse(responseCode = "E03301", description = "수정하려는 방 정보를 찾지 못했습니다.")
RoomResponseDto updateRoomById(Long roomId, RoomUpdateRequestDto roomUpdateRequestDto);
RoomResponseDto updateRoomById(String roomShortUuid, RoomUpdateRequestDto roomUpdateRequestDto);

@Operation(summary = "개별 방 정보 조회", description = "short UUID를 통해 방을 조회합니다.")
@ApiResponse(responseCode = "200", description = "방 정보 조회 성공")
Expand Down

0 comments on commit 61d8d78

Please sign in to comment.