Skip to content

Commit

Permalink
Merge pull request #16 from mujik-tigers/dev
Browse files Browse the repository at this point in the history
fix: API 응답 명세서 수정
  • Loading branch information
ghkdgus29 authored Apr 4, 2024
2 parents 03024f9 + e6c1485 commit f26d7d4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/site/youtogether/room/dto/RoomList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class RoomList {
private boolean hasPrevious;
private boolean hasNext;

private List<RoomDetail> rooms;
private List<RoomListDetail> rooms;

@Builder
public RoomList(int pageNumber, int pageSize, int totalData, int totalPage, boolean hasPrevious, boolean hasNext, List<RoomDetail> rooms) {
public RoomList(int pageNumber, int pageSize, int totalData, int totalPage, boolean hasPrevious, boolean hasNext, List<RoomListDetail> rooms) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.totalData = totalData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
import lombok.Getter;

@Getter
public class RoomDetail {
public class RoomListDetail {

private String roomCode;
private String roomTitle;
private String videoTitle;
private String videoThumbnail;
private int capacity;
private int currentParticipant;
private boolean passwordExist;

@Builder
public RoomDetail(String roomCode, String roomTitle, String videoTitle, String videoThumbnail, int capacity, int currentParticipant) {
public RoomListDetail(String roomCode, String roomTitle, String videoTitle, String videoThumbnail, int capacity, int currentParticipant,
boolean passwordExist) {
this.roomCode = roomCode;
this.roomTitle = roomTitle;
this.videoTitle = videoTitle;
this.videoThumbnail = videoThumbnail;
this.capacity = capacity;
this.currentParticipant = currentParticipant;
this.passwordExist = passwordExist;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,6 +25,7 @@
import site.youtogether.room.dto.CreatedRoomInfo;
import site.youtogether.room.dto.RoomList;
import site.youtogether.room.dto.RoomSettings;
import site.youtogether.user.application.UserService;
import site.youtogether.util.RandomUtil;
import site.youtogether.util.api.ApiResponse;
import site.youtogether.util.api.ResponseResult;
Expand All @@ -36,12 +36,13 @@ public class RoomController {

private final CookieProperties cookieProperties;
private final RoomService roomService;
private final UserService userService;

@PostMapping("/rooms")
public ResponseEntity<ApiResponse<CreatedRoomInfo>> createRoom(@CookieValue(value = SESSION_COOKIE_NAME, required = false) Cookie sessionCookie,
public ResponseEntity<ApiResponse<CreatedRoomInfo>> createRoom(@CookieValue(value = SESSION_COOKIE_NAME, required = false) String sessionCode,
@Address String address, @Valid @RequestBody RoomSettings roomSettings, HttpServletResponse response) {
// Check if a session cookie already exists.
if (sessionCookie != null) {
if (sessionCode != null && userService.isValidSession(sessionCode)) {
throw new SingleRoomParticipationViolationException();
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/site/youtogether/user/application/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package site.youtogether.user.application;

import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import site.youtogether.user.infrastructure.UserStorage;

@Service
@RequiredArgsConstructor
public class UserService {

private final UserStorage userStorage;

public boolean isValidSession(String sessionCode) {
return userStorage.existsById(sessionCode);
}

}
4 changes: 4 additions & 0 deletions src/test/java/site/youtogether/RestDocsSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import site.youtogether.config.property.CookieProperties;
import site.youtogether.room.application.RoomService;
import site.youtogether.room.presentation.RoomController;
import site.youtogether.user.application.UserService;

@WebMvcTest(controllers = {
RoomController.class
Expand All @@ -33,4 +34,7 @@ public abstract class RestDocsSupport {
@MockBean
protected RoomService roomService;

@MockBean
protected UserService userService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import site.youtogether.RestDocsSupport;
import site.youtogether.exception.room.SingleRoomParticipationViolationException;
import site.youtogether.room.dto.CreatedRoomInfo;
import site.youtogether.room.dto.RoomDetail;
import site.youtogether.room.dto.RoomList;
import site.youtogether.room.dto.RoomListDetail;
import site.youtogether.room.dto.RoomSettings;
import site.youtogether.util.api.ResponseResult;

Expand Down Expand Up @@ -93,7 +93,7 @@ void createRoomSuccess() throws Exception {
fieldWithPath("data.hostNickname").type(JsonFieldType.STRING).description("호스트 닉네임"),
fieldWithPath("data.capacity").type(JsonFieldType.NUMBER).description("정원"),
fieldWithPath("data.currentParticipant").type(JsonFieldType.NUMBER).description("현재 참가자 수"),
fieldWithPath("data.passwordExist").type(JsonFieldType.BOOLEAN).description("현재 참가자 수")
fieldWithPath("data.passwordExist").type(JsonFieldType.BOOLEAN).description("비밀번호 존재 여부")
)
));
}
Expand Down Expand Up @@ -151,6 +151,8 @@ void createRoomFail_SingleRoomParticipantViolation() throws Exception {
.title("재밌는 쇼츠 같이 보기")
.password(null)
.build();
given(userService.isValidSession(anyString()))
.willReturn(true);

// when / then
mockMvc.perform(post("/rooms")
Expand Down Expand Up @@ -225,6 +227,7 @@ void fetchRoomListSuccess() throws Exception {
.andExpect(jsonPath("$.data.rooms[0].videoThumbnail").value(roomList.getRooms().get(0).getVideoThumbnail()))
.andExpect(jsonPath("$.data.rooms[0].capacity").value(roomList.getRooms().get(0).getCapacity()))
.andExpect(jsonPath("$.data.rooms[0].currentParticipant").value(roomList.getRooms().get(0).getCurrentParticipant()))
.andExpect(jsonPath("$.data.rooms[0].passwordExist").value(roomList.getRooms().get(0).isPasswordExist()))
.andDo(document("fetch-room-list-success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
Expand All @@ -245,21 +248,23 @@ void fetchRoomListSuccess() throws Exception {
fieldWithPath("data.rooms[].videoTitle").type(JsonFieldType.STRING).description("영상 제목"),
fieldWithPath("data.rooms[].videoThumbnail").type(JsonFieldType.STRING).description("영상 썸네일 URL"),
fieldWithPath("data.rooms[].capacity").type(JsonFieldType.NUMBER).description("정원"),
fieldWithPath("data.rooms[].currentParticipant").type(JsonFieldType.NUMBER).description("현재 참여자 수")
fieldWithPath("data.rooms[].currentParticipant").type(JsonFieldType.NUMBER).description("현재 참여자 수"),
fieldWithPath("data.rooms[].passwordExist").type(JsonFieldType.BOOLEAN).description("비밀번호 존재 여부")
)
));
}

private List<RoomDetail> generateRoomDetails(int count) {
private List<RoomListDetail> generateRoomDetails(int count) {
return IntStream.rangeClosed(1, count)
.mapToObj(number -> RoomDetail.builder()
.mapToObj(number -> RoomListDetail.builder()
.roomCode("1e7050f7d" + number)
.roomTitle("2023년 침착맨 정주행 " + number)
.videoTitle("궤도 '연애의 과학' 특강 " + number)
.videoThumbnail(
"https://i.ytimg.com/vi/sl7ih5rLfYM/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDbjCXvhBJSBKs9bX_XMy_EfUtvSw")
.capacity(10)
.currentParticipant(6)
.passwordExist(false)
.build())
.toList();
}
Expand Down

0 comments on commit f26d7d4

Please sign in to comment.