Skip to content

Commit

Permalink
fix: 방의 인증 시간에는 입장하지 못하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkim97 committed Dec 2, 2023
1 parent 4e69376 commit b9ff50b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/moabam/api/application/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.moabam.api.domain.room.RoomType.*;
import static com.moabam.global.error.model.ErrorMessage.*;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

Expand Down Expand Up @@ -199,6 +200,7 @@ private void validateManagerAuthorization(Participant participant) {

private void validateRoomEnter(Long memberId, String requestPassword, Room room) {
validateEnteredRoomCount(memberId, room.getRoomType());
validateCertifyTime(room);

if (!StringUtils.isEmpty(requestPassword) && !room.getPassword().equals(requestPassword)) {
throw new BadRequestException(WRONG_ROOM_PASSWORD);
Expand All @@ -219,6 +221,18 @@ private void validateEnteredRoomCount(Long memberId, RoomType roomType) {
}
}

private void validateCertifyTime(Room room) {
LocalDateTime now = clockHolder.times();
LocalTime targetTime = LocalTime.of(room.getCertifyTime(), 0);
LocalDateTime targetDateTime = LocalDateTime.of(now.toLocalDate(), targetTime);

LocalDateTime plusTenMinutes = targetDateTime.plusMinutes(10);

if (now.isAfter(targetDateTime) && now.isBefore(plusTenMinutes)) {
throw new BadRequestException(ROOM_ENTER_FAILED);
}
}

private void validateRoomExit(Participant participant, Room room) {
if (participant.isManager() && room.getCurrentUserCount() != 1) {
throw new BadRequestException(ROOM_EXIT_MANAGER_FAIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ErrorMessage {
IMAGE_CONVERT_FAIL("이미지 변환을 실패했습니다."),
UNAVAILABLE_TO_CHANGE_CERTIFY_TIME("이미 한명 이상이 인증을 하면 인증 시간을 바꿀 수 없습니다."),
CERTIFIED_ROOM_EXIT_FAILED("오늘 인증한 방은 나갈 수 없습니다."),
ROOM_ENTER_FAILED("해당 방의 인증 시간에는 입장할 수 없습니다."),

LOGIN_FAILED("로그인에 실패했습니다."),
LOGIN_FAILED_ADMIN_KEY("어드민키가 달라요"),
Expand Down

0 comments on commit b9ff50b

Please sign in to comment.