Skip to content

Commit

Permalink
refactor: redirection -> boolean으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkim97 committed Nov 27, 2023
1 parent afbb2f8 commit 2322e55
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.moabam.api.domain.room.RoomType.*;
import static com.moabam.global.error.model.ErrorMessage.*;

import java.time.LocalDate;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -148,12 +147,12 @@ public void deportParticipant(Long managerId, Long roomId, Long memberId) {
member.exitRoom(room.getRoomType());
}

public String checkIfParticipant(Long memberId, Long roomId) {
public boolean checkIfParticipant(Long memberId, Long roomId) {
try {
getParticipant(memberId, roomId);
return String.format("https://dev-api.moabam.com/%d/%s", roomId, LocalDate.now());
return true;
} catch (NotFoundException e) {
return String.format("https://dev-api.moabam.com/%d/un-joined", roomId);
return false;
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/moabam/api/presentation/RoomController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.moabam.api.presentation;

import java.io.IOException;
import java.time.LocalDate;
import java.util.List;

Expand Down Expand Up @@ -37,7 +36,6 @@
import com.moabam.global.auth.annotation.Auth;
import com.moabam.global.auth.model.AuthMember;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -91,11 +89,9 @@ public void exitRoom(@Auth AuthMember authMember, @PathVariable("roomId") Long r
}

@GetMapping("/{roomId}/check")
@ResponseStatus(HttpStatus.FOUND)
public void checkIfParticipant(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId,
HttpServletResponse response) throws IOException {
String urlToRedirect = roomService.checkIfParticipant(authMember.id(), roomId);
response.sendRedirect(urlToRedirect);
@ResponseStatus(HttpStatus.OK)
public boolean checkIfParticipant(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId) {
return roomService.checkIfParticipant(authMember.id(), roomId);
}

@GetMapping("/{roomId}/un-joined")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ void get_join_history_success() throws Exception {
.andDo(print());
}

@DisplayName("참여중이지 않은 방에 대한 리다이렉션 반환 성공")
@DisplayName("참여중이지 않은 방에 대한 확인 성공")
@WithMember
@Test
void check_if_participant_false_success() throws Exception {
Expand All @@ -981,8 +981,7 @@ void check_if_participant_false_success() throws Exception {

// expected
mockMvc.perform(get("/rooms/" + savedRoom.getId() + "/check"))
.andExpect(status().isFound())
.andExpect(redirectedUrl(String.format("https://dev-api.moabam.com/%d/un-joined", savedRoom.getId())))
.andExpect(status().isOk())
.andDo(print());
}

Expand Down Expand Up @@ -1021,7 +1020,7 @@ void get_un_joined_room_details() throws Exception {
.andDo(print());
}

@DisplayName("참여중인 방에 대한 리다이렉션 반환 성공")
@DisplayName("참여중인 방에 대한 확인 성공")
@WithMember
@Test
void check_if_participant_true_success() throws Exception {
Expand All @@ -1034,9 +1033,7 @@ void check_if_participant_true_success() throws Exception {

// expected
mockMvc.perform(get("/rooms/" + savedRoom.getId() + "/check"))
.andExpect(status().isFound())
.andExpect(
redirectedUrl(String.format("https://dev-api.moabam.com/%d/%s", savedRoom.getId(), LocalDate.now())))
.andExpect(status().isOk())
.andDo(print());
}

Expand Down

0 comments on commit 2322e55

Please sign in to comment.