Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public enum ErrorCode implements ResponseCode {
*/
ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, 100000, "존재하지 않는 ROOM 입니다."),
INVALID_ROOM_CREATE(HttpStatus.BAD_REQUEST, 100001, "유효하지 않은 ROOM 생성 요청 입니다."),
ROOM_PASSWORD_MISMATCH(HttpStatus.BAD_REQUEST, 100002, "비밀번호가 일치하지 않습니다."),
ROOM_PASSWORD_NOT_REQUIRED(HttpStatus.BAD_REQUEST, 100003, "공개방은 비밀번호가 필요하지 않습니다."),
ROOM_RECRUITMENT_PERIOD_EXPIRED(HttpStatus.BAD_REQUEST, 100004, "모집기간이 만료된 방입니다."),
INVALID_ROOM_SEARCH_SORT(HttpStatus.BAD_REQUEST, 100005, "방 검색 시 정렬 조건이 잘못되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public enum SwaggerResponseDescription {
))),
ROOM_PASSWORD_CHECK(new LinkedHashSet<>(Set.of(
ROOM_NOT_FOUND,
ROOM_PASSWORD_MISMATCH,
ROOM_RECRUITMENT_PERIOD_EXPIRED,
ROOM_PASSWORD_NOT_REQUIRED
))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public BaseResponse<RoomSearchResponse> searchRooms(
)
@ExceptionDescription(ROOM_PASSWORD_CHECK)
@PostMapping("/rooms/{roomId}/password")
public BaseResponse<Void> verifyRoomPassword(
public BaseResponse<RoomVerifyPasswordResponse> verifyRoomPassword(
@Parameter(description = "비밀번호 검증하려는 비공개 방 ID", example = "1") @PathVariable("roomId") final Long roomId,
@Valid @RequestBody final RoomVerifyPasswordRequest roomVerifyPasswordRequest
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package konkuk.thip.room.adapter.in.web.response;

public record RoomVerifyPasswordResponse(
boolean matched,
Long roomId
)
{
public static RoomVerifyPasswordResponse of(boolean matched,Long roomId) {
return new RoomVerifyPasswordResponse(matched,roomId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package konkuk.thip.room.application.port.in;

import konkuk.thip.room.adapter.in.web.response.RoomVerifyPasswordResponse;
import konkuk.thip.room.application.port.in.dto.RoomVerifyPasswordQuery;

public interface RoomVerifyPasswordUseCase {
Void verifyRoomPassword(RoomVerifyPasswordQuery query);
RoomVerifyPasswordResponse verifyRoomPassword(RoomVerifyPasswordQuery query);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package konkuk.thip.room.application.service;

import konkuk.thip.room.adapter.in.web.response.RoomVerifyPasswordResponse;
import konkuk.thip.room.application.port.in.RoomVerifyPasswordUseCase;
import konkuk.thip.room.application.port.in.dto.RoomVerifyPasswordQuery;
import konkuk.thip.room.application.port.out.RoomCommandPort;
Expand All @@ -17,13 +18,13 @@ public class RoomVerifyPasswordService implements RoomVerifyPasswordUseCase {

@Override
@Transactional(readOnly = true)
public Void verifyRoomPassword(RoomVerifyPasswordQuery query) {
public RoomVerifyPasswordResponse verifyRoomPassword(RoomVerifyPasswordQuery query) {

//방 검증
Room room = roomCommandPort.getByIdOrThrow(query.roomId());

//도메인에서 비밀번호 검증 로직 수행
room.verifyPassword(query.password());
return null;
boolean matched = room.verifyPassword(query.password());
return RoomVerifyPasswordResponse.of(matched, room.getId());
}
}
7 changes: 2 additions & 5 deletions src/main/java/konkuk/thip/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import konkuk.thip.common.entity.BaseDomainEntity;
import konkuk.thip.common.exception.InvalidStateException;
import konkuk.thip.common.entity.StatusType;
import konkuk.thip.common.exception.BusinessException;
import konkuk.thip.common.exception.code.ErrorCode;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -117,7 +116,7 @@ public boolean matchesPassword(String rawPassword) {
return PASSWORD_ENCODER.matches(rawPassword, this.hashedPassword);
}

public void verifyPassword(String rawPassword) {
public boolean verifyPassword(String rawPassword) {

validateRoomRecruitExpired();

Expand All @@ -127,9 +126,7 @@ public void verifyPassword(String rawPassword) {
}

//비밀번호 검증
if (!matchesPassword(rawPassword)) {
throw new BusinessException(ROOM_PASSWORD_MISMATCH);
}
return matchesPassword(rawPassword);
}

public void validateRoomRecruitExpired() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ void verifyRoomPassword_success() throws Exception {
.content(objectMapper.writeValueAsString(request))
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess").value(true));
.andExpect(jsonPath("$.isSuccess").value(true))
.andExpect(jsonPath("$.data.matched").value(true))
.andExpect(jsonPath("$.data.roomId").value(privateRoomId));
}

@Test
@DisplayName("모집기간이 만료되지 않은 비공개 방의 비밀번호 입력 검증 [실패]시 400 Bad Request 반환")
@DisplayName("모집기간이 만료되지 않은 비공개 방의 비밀번호 입력 검증 [실패]시 matched=false로 200 OK")
void verifyRoomPassword_mismatch() throws Exception {

// given
Expand All @@ -158,10 +160,10 @@ void verifyRoomPassword_mismatch() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
)
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.isSuccess").value(false))
.andExpect(jsonPath("$.code").value(ROOM_PASSWORD_MISMATCH.getCode()))
.andExpect(jsonPath("$.message" , containsString("비밀번호가 일치하지 않습니다.")));
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess").value(true))
.andExpect(jsonPath("$.data.matched").value(false))
.andExpect(jsonPath("$.data.roomId").value(privateRoomId));
}

@Test
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/konkuk/thip/room/domain/RoomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,23 @@ void verifyPassword_publicRoom() {
}

@Test
@DisplayName("verifyPassword: 비밀번호 불일치 시 BusinessException(ROOM_PASSWORD_MISMATCH) 발생")
@DisplayName("verifyPassword: 비밀번호 불일치 시 false 반환")
void verifyPassword_passwordMismatch() {
Room room = Room.withoutId(
"제목", "설명", false, "1234",
START, END, 5, 123L, validCategory
);
BusinessException ex = assertThrows(BusinessException.class,
() -> room.verifyPassword("0000"));
assertEquals(ErrorCode.ROOM_PASSWORD_MISMATCH, ex.getErrorCode());
assertFalse(room.verifyPassword("0000"));
}

@Test
@DisplayName("verifyPassword: 모집기간 내, 비공개방, 비밀번호 일치 시 예외 발생하지 않음")
@DisplayName("verifyPassword: 모집기간 내, 비공개방, 비밀번호 일치 시 true 반환")
void verifyPassword_success() {
Room room = Room.withoutId(
"제목", "설명", false, "1234",
START, END, 5, 123L, validCategory
);
assertDoesNotThrow(() -> room.verifyPassword("1234"));
assertTrue(room.verifyPassword("1234"));
}

@Test
Expand Down