Skip to content

Commit

Permalink
feat: 새로운 DTO 로 방 생성 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsu5582 committed Nov 27, 2024
1 parent 8e8d839 commit 95a0e7b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import corea.member.domain.MemberRole;
import corea.participation.repository.ParticipationRepository;
import corea.room.domain.Room;
import corea.room.dto.RoomRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
Expand All @@ -19,6 +20,10 @@ public class ParticipationWriter {

private final ParticipationRepository participationRepository;

public Participation create(Room room, Member member, RoomRequest.ManagerParticipationRequest request) {
return create(room, member, request.memberRole(), ParticipationStatus.MANAGER, request.matchingSize());
}

public Participation create(Room room, Member member, MemberRole memberRole, ParticipationStatus participationStatus) {
return create(room, member, memberRole, participationStatus, room.getMatchingSize());
}
Expand Down
7 changes: 7 additions & 0 deletions backend/src/main/java/corea/room/domain/RoomWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import corea.member.domain.Member;
import corea.participation.domain.ParticipationWriter;
import corea.room.dto.RoomCreateRequest;
import corea.room.dto.RoomRequest;
import corea.room.dto.RoomUpdateRequest;
import corea.room.repository.RoomRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,6 +23,12 @@ public class RoomWriter {
private final ParticipationWriter participationWriter;

// TODO 서비스 용 DTO 만들어야함
public Room create(Member manager, RoomRequest request) {
Room room = roomRepository.save(request.toEntity(manager));
log.info("방을 생성했습니다. 방 생성자 id={}, 요청한 사용자 id={}", room.getId(), room.getManagerId());
return room;
}

public Room create(Member manager, RoomCreateRequest request) {
Room room = roomRepository.save(request.toEntity(manager));
log.info("방을 생성했습니다. 방 생성자 id={}, 요청한 사용자 id={}", room.getId(), room.getManagerId());
Expand Down
17 changes: 17 additions & 0 deletions backend/src/main/java/corea/room/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ public class RoomService {
private final ParticipationWriter participationWriter;
private final ParticipationReader participationReader;

@Transactional
public RefactorRoomResponse create(long memberId, RoomRequest request) {
Member manager = memberReader.findOne(memberId);
Room room = roomWriter.create(manager, request);

RoomMatchInfo roomMatchInfo = roomMatchInfoWriter.create(room, request.isPublic());
Participation participation = participationWriter.create(room, manager, request.managerParticipationRequest());

roomAutomaticService.createAutomatic(room);
return new RefactorRoomResponse(
RefactorRoomResponse.RoomInfoResponse.from(room),
RefactorRoomResponse.DeadlineResponse.from(room),
RefactorRoomResponse.RepositoryResponse.from(room, roomMatchInfo),
RefactorRoomResponse.ParticipationResponse.from(participation)
);
}

@Transactional
public RoomResponse create(long memberId, RoomCreateRequest request) {
Member manager = memberReader.findOne(memberId);
Expand Down
21 changes: 21 additions & 0 deletions backend/src/test/java/corea/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package corea.fixture;

import corea.member.domain.Member;
import corea.member.domain.MemberRole;
import corea.room.domain.Room;
import corea.room.domain.RoomClassification;
import corea.room.domain.RoomDeadline;
import corea.room.domain.RoomStatus;
import corea.room.dto.RoomCreateRequest;
import corea.room.dto.RoomRequest;
import corea.room.dto.RoomUpdateRequest;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -177,6 +179,25 @@ public static RoomCreateRequest ROOM_CREATE_REQUEST_WITH_REVIEW_DEADLINE(LocalDa
return ROOM_CREATE_REQUEST(LocalDateTime.now().plusHours(2), reviewDeadline);
}

public static RoomRequest ROOM_REQUEST() {
return new RoomRequest(
new RoomRequest.RoomInfoRequest(
"Room", "Content", "https://gongu.copyright.or.kr/gongu/wrt",
3,List.of("JAVA","TDD"),200
),
new RoomRequest.DeadlineRequest(
LocalDateTime.now().plusHours(2),
LocalDateTime.now().plusHours(4)
),
new RoomRequest.RepositoryRequest(
"https://github.com/example/java-racingcar",
RoomClassification.BACKEND,
true
),
new RoomRequest.ManagerParticipationRequest(MemberRole.REVIEWER,3)
);
}

public static RoomCreateRequest ROOM_CREATE_REQUEST(LocalDateTime recruitmentDeadline, LocalDateTime reviewDeadline) {
return new RoomCreateRequest(
"Test Room",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@
import corea.member.domain.Member;
import corea.member.repository.MemberRepository;
import corea.participation.domain.ParticipationStatus;
import corea.room.dto.RoomCreateRequest;
import corea.room.dto.RoomResponse;
import corea.room.dto.RoomResponses;
import corea.room.dto.*;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

@ControllerTest
@ActiveProfiles("test")
Expand All @@ -48,13 +42,13 @@ void setUp() {
@DisplayName("방 하나를 조회할 수 있다.")
class RoomReader {

private RoomResponse response;
private RefactorRoomResponse response;
private String accessToken;

@BeforeEach
void setUp() {
accessToken = tokenService.createAccessToken(member);
RoomCreateRequest request = RoomFixture.ROOM_CREATE_REQUEST();
RoomRequest request = RoomFixture.ROOM_REQUEST();

// 방 생성
response = RestAssured.given().log().all()
Expand All @@ -64,7 +58,7 @@ void setUp() {
.when().post("/rooms")
.then().log().all()
.statusCode(201)
.extract().as(RoomResponse.class);
.extract().as(RefactorRoomResponse.class);
}

@AfterEach
Expand Down

0 comments on commit 95a0e7b

Please sign in to comment.