Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: 방 조회 API 구현(#12) #19

Merged
merged 2 commits into from
Jul 16, 2024
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
29 changes: 29 additions & 0 deletions backend/src/main/java/corea/cotroller/RoomController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package corea.cotroller;

import corea.dto.RoomResponse;
import corea.dto.RoomResponses;
import corea.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RoomController {

private final RoomService roomService;

@GetMapping("/rooms/{id}")
public ResponseEntity<RoomResponse> room(@PathVariable final long id) {
final RoomResponse response = roomService.findOne(id);
return ResponseEntity.ok(response);
}

@GetMapping("/rooms")
public ResponseEntity<RoomResponses> rooms() {
final RoomResponses response = roomService.findAll();
return ResponseEntity.ok(response);
}
}
14 changes: 13 additions & 1 deletion backend/src/main/java/corea/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Room {

private String title;

private String content;

private long memberId;

@Column(length = 25000)
Expand All @@ -37,19 +39,29 @@ public class Room {

private String keyword;

private long currentParticipantsSize;

private long limitedParticipantsSize;

private LocalDateTime submissionDeadline;

private LocalDateTime reviewDeadline;

public Room(final String title,
final String content,
final long memberId,
final String repositoryLink,
final String thumbnailLink,
final int matchingSize,
final String keyword,
final long currentParticipantsSize,
final long limitedParticipantsSize,
final LocalDateTime submissionDeadline,
final LocalDateTime reviewDeadline) {
this(null, title, memberId, repositoryLink, thumbnailLink, matchingSize, keyword, submissionDeadline, reviewDeadline);
this(null, title, content,
memberId, repositoryLink, thumbnailLink,
matchingSize, keyword, currentParticipantsSize,
limitedParticipantsSize, submissionDeadline, reviewDeadline);
}
}

6 changes: 6 additions & 0 deletions backend/src/main/java/corea/dto/RoomCreateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@

public record RoomCreateRequest(
String title,
String content,
long memberId,
String repositoryLink,
String thumbnailLink,
int matchingSize,
String keyword,
long currentParticipantsSize,
long limitedParticipantsSize,
LocalDateTime submissionDeadline,
LocalDateTime reviewDeadline
) {

public Room toEntity() {
return new Room(
title,
content,
memberId,
repositoryLink,
thumbnailLink,
matchingSize,
keyword,
currentParticipantsSize,
limitedParticipantsSize,
submissionDeadline,
reviewDeadline
);
Expand Down
19 changes: 13 additions & 6 deletions backend/src/main/java/corea/dto/RoomResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
import corea.domain.Room;

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

public record RoomResponse(
long id,
String title,
String memberEmail,
String content,
String author,
String repositoryLink,
String thumbnailLink,
int matchingSize,
String keyword,
LocalDateTime submissionDeadline,
List<String> keywords,
long currentParticipants,
long limitedParticipants,
LocalDateTime recruitmentDeadline,
LocalDateTime reviewDeadline
) {

public static RoomResponse of(final Room room, final String memberEmail) {
public static RoomResponse of(final Room room, final String author) {
return new RoomResponse(
room.getId(),
room.getTitle(),
memberEmail,
room.getContent(),
author,
room.getRepositoryLink(),
room.getThumbnailLink(),
room.getMatchingSize(),
room.getKeyword(),
List.of(room.getKeyword()),
room.getCurrentParticipantsSize(),
room.getLimitedParticipantsSize(),
room.getSubmissionDeadline(),
room.getReviewDeadline()
);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/corea/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Member getMember(final long memberId) {
.orElseThrow(() -> new IllegalArgumentException(String.format("해당 Id의 멤버가 없습니다. 입력된 Id=%d", memberId)));
}

public Room getRoom(final long roomId) {
private Room getRoom(final long roomId) {
return roomRepository.findById(roomId)
.orElseThrow(() -> new IllegalArgumentException(String.format("해당 Id의 방이 없습니다. 입력된 Id=%d", roomId)));
}
Expand Down
6 changes: 6 additions & 0 deletions backend/src/test/java/corea/fixture/RoomFixture.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/src/test/java/corea/service/RoomServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void create() {
final RoomCreateRequest request = RoomFixture.ROOM_CREATE_REQUEST(member.getId());
final RoomResponse response = roomService.create(request);

assertThat(response.memberEmail()).isEqualTo("[email protected]");
assertThat(response.title()).isEqualTo("레이싱 카와 함께하는 TDD");
}

@Test
Expand Down
Loading