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] 방 생성 때 방장도 참여 정할수 있게 변경 & DTO 리팩토링(#785) #786

Merged
merged 12 commits into from
Dec 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import corea.auth.annotation.AccessedMember;
import corea.auth.annotation.LoginMember;
import corea.auth.domain.AuthInfo;
import corea.room.dto.RoomCreateRequest;
import corea.room.dto.RoomParticipantResponses;
import corea.room.dto.RoomResponse;
import corea.room.dto.RoomUpdateRequest;
import corea.room.dto.*;
import corea.room.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -22,8 +19,8 @@ public class RoomController implements RoomControllerSpecification {
private final RoomService roomService;

@PostMapping
public ResponseEntity<RoomResponse> create(@LoginMember AuthInfo authInfo, @RequestBody RoomCreateRequest request) {
RoomResponse response = roomService.create(authInfo.getId(), request);
public ResponseEntity<RefactorRoomResponse> create(@LoginMember AuthInfo authInfo, @RequestBody RoomRequest request) {
RefactorRoomResponse response = roomService.create(authInfo.getId(), request);

return ResponseEntity.created(URI.create(String.format("/rooms/%d", response.id())))
.body(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import corea.auth.domain.AuthInfo;
import corea.exception.ExceptionType;
import corea.global.annotation.ApiErrorResponses;
import corea.room.dto.RoomCreateRequest;
import corea.room.dto.RoomParticipantResponses;
import corea.room.dto.RoomResponse;
import corea.room.dto.RoomUpdateRequest;
import corea.room.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -23,7 +20,7 @@ public interface RoomControllerSpecification {
"<br><br>**참고:** 이 API를 사용하기 위해서는 유효한 JWT 토큰이 필요하며, " +
"토큰이 없거나 유효하지 않은 경우 인증 오류가 발생합니다.")
@ApiErrorResponses(value = ExceptionType.MEMBER_NOT_FOUND)
ResponseEntity<RoomResponse> create(AuthInfo authInfo, RoomCreateRequest request);
ResponseEntity<RefactorRoomResponse> create(AuthInfo authInfo, RoomRequest request);

@Operation(summary = "새로운 방을 수정합니다.",
description = "상호 리뷰 인원을 모을 수 있는 방을 수정합니다. <br>" +
Expand Down
6 changes: 5 additions & 1 deletion backend/src/main/java/corea/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ public long getManagerId() {
return manager.getId();
}

public String getRoomStatus() {
public String getRoomStatusString() {
return status.getStatus();
}

public RoomStatus getRoomStatus() {
return status.get();
}

public String getManagerName() {
return manager.getUsername();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RoomMatchInfoWriter {

private final RoomMatchInfoRepository roomMatchInfoRepository;

public RoomMatchInfo create(Room room, boolean isPrivate) {
return roomMatchInfoRepository.save(new RoomMatchInfo(room.getId(), isPrivate));
public RoomMatchInfo create(Room room, boolean isPublic) {
return roomMatchInfoRepository.save(new RoomMatchInfo(room.getId(), isPublic));
}
}
4 changes: 4 additions & 0 deletions backend/src/main/java/corea/room/domain/RoomStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public boolean isNotProgress() {
public String getStatus() {
return this.name();
}

public RoomStatus get() {
return this;
}
}
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
141 changes: 141 additions & 0 deletions backend/src/main/java/corea/room/dto/RefactorRoomResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package corea.room.dto;

import corea.member.domain.MemberRole;
import corea.participation.domain.Participation;
import corea.participation.domain.ParticipationStatus;
import corea.room.domain.Room;
import corea.room.domain.RoomClassification;
import corea.room.domain.RoomMatchInfo;
import corea.room.domain.RoomStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

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

public record RefactorRoomResponse(
RoomInfoResponse roomInfoResponse,
DeadlineResponse deadlineResponse,
RepositoryResponse repositoryResponse,
ParticipationResponse participationResponse
) {
public record RoomInfoResponse(
@Schema(description = "방 아이디", example = "1")
long roomId,

@Schema(description = "방 제목", example = "MVC를 아시나요?")
@NotBlank
String title,

@Schema(description = "방 내용", example = "MVC 패턴을 아시나요?")
String content,

@Schema(description = "썸네일 링크", example = "https://gongu.copyright.or.kr/gongu/wrt/cmmn/wrtFileImageView.do?wrtSn=13301655&filePath=L2Rpc2sxL25ld2RhdGEvMjAyMS8yMS9DTFMxMDAwNC8xMzMwMTY1NV9XUlRfMjFfQ0xTMTAwMDRfMjAyMTEyMTNfMQ==&thumbAt=Y&thumbSe=b_tbumb&wrtTy=10004")
String thumbnailLink,

@Schema(description = "상호 리뷰 인원", example = "2")
@NotNull
int matchingSize,

@Schema(description = "중심으로 리뷰하면 좋은 키워드", example = "[\"TDD\", \"클린코드\"]")
List<String> keywords,

@Schema(description = "제한 참여 인원", example = "200")
@NotNull
int limitedParticipants,

@Schema(description = "리뷰어 참여 수", example = "10")
@NotNull
int reviewerCount,

@Schema(description = "일반 참여 수", example = "123")
@NotNull
int bothCount,

@Schema(description = "방장 이름", example = "최진실")
String manager,

@Schema(description = "방 상태", example = "OPEN")
RoomStatus roomStatus,

@Schema(description = "매칭 실패 원인 메세지 제공", example = "참여 인원이 부족하여 매칭을 진행할 수 없습니다.")
String message
) {
public static RoomInfoResponse from(Room room) {
return new RoomInfoResponse(
room.getId(),
room.getTitle(),
room.getContent(),
room.getThumbnailLink(),
room.getMatchingSize(),
room.getKeyword(),
room.getLimitedParticipantsSize(),
room.getReviewerCount(),
room.getBothCount(),
room.getManagerName(),
room.getRoomStatus(),
""
);
}
}

public record DeadlineResponse(
@Schema(description = "모집 마감일", example = "2024-11-28T11:10:00")
LocalDateTime recruitmentDeadline,

@Schema(description = "리뷰 마감일", example = "2024-11-28T11:20:00")
LocalDateTime reviewDeadline
) {
public static DeadlineResponse from(Room room) {
return new DeadlineResponse(
room.getRecruitmentDeadline(),
room.getReviewDeadline()
);
}
}

public record RepositoryResponse(
@Schema(description = "repository 링크", example = "https://github.com/example/java-racingcar")
@NotBlank
String repositoryLink,

@Schema(description = "방이 속하는 분야", example = "BE")
@NotNull
RoomClassification classification,

@Schema(description = "어떤 저장소에서 확인하는지", example = "true")
boolean isPublic
) {
public static RepositoryResponse from(Room room, RoomMatchInfo roomMatchInfo) {
return new RepositoryResponse(
room.getRepositoryLink(),
room.getClassification(),
roomMatchInfo.isPublic()
);
}
}

public record ParticipationResponse(
@Schema(description = "조회한 유저가 방에 참여하고 있는 상태", example = "PARTICIPATED")
ParticipationStatus participationStatus,

@Schema(description = "조회한 유저가 방에 참여한 역할", example = "BOTH")
MemberRole memberRole,

@Schema(description = "참여자가 원하는 매칭 인원 수", example = "3")
int matchingSize
) {
public static ParticipationResponse from(Participation participation) {
return new ParticipationResponse(
participation.getStatus(),
participation.getMemberRole(),
participation.getMatchingSize()
);
}
}

public long id(){
return roomInfoResponse().roomId();
}
}
105 changes: 105 additions & 0 deletions backend/src/main/java/corea/room/dto/RoomRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package corea.room.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import corea.member.domain.Member;
import corea.member.domain.MemberRole;
import corea.room.domain.Room;
import corea.room.domain.RoomClassification;
import corea.room.domain.RoomStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

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

@Schema(description = "방 생성 요청")
public record RoomRequest(
RoomInfoRequest roomInfoRequest,
DeadlineRequest deadlineRequest,
RepositoryRequest repositoryRequest,
ManagerParticipationRequest managerParticipationRequest
) {
public record RoomInfoRequest(
@Schema(description = "방 제목", example = "MVC를 아시나요?")
@NotBlank
String title,

@Schema(description = "방 내용", example = "MVC 패턴을 아시나요?")
String content,

@Schema(description = "썸네일 링크", example = "https://gongu.copyright.or.kr/gongu/wrt/cmmn/wrtFileImageView.do?wrtSn=13301655&filePath=L2Rpc2sxL25ld2RhdGEvMjAyMS8yMS9DTFMxMDAwNC8xMzMwMTY1NV9XUlRfMjFfQ0xTMTAwMDRfMjAyMTEyMTNfMQ==&thumbAt=Y&thumbSe=b_tbumb&wrtTy=10004")
String thumbnailLink,

@Schema(description = "상호 리뷰 인원", example = "2")
@NotNull
int matchingSize,

@Schema(description = "중심으로 리뷰하면 좋은 키워드", example = "[\"TDD\", \"클린코드\"]")
List<String> keywords,

@Schema(description = "제한 참여 인원", example = "200")
@NotNull
int limitedParticipants
) {
}

public record DeadlineRequest(
@Schema(description = "모집 마감일", example = "2024-07-30 15:00")
@NotNull
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
LocalDateTime recruitmentDeadline,

@Schema(description = "리뷰 마감일", example = "2024-08-10 23:59")
@NotNull
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
LocalDateTime reviewDeadline
) {
}

public record RepositoryRequest(
@Schema(description = "repository 링크", example = "https://github.com/example/java-racingcar")
@NotBlank
String repositoryLink,

@Schema(description = "방이 속하는 분야", example = "BACKEND")
@NotNull
RoomClassification classification,

@Schema(description = "어떤 저장소에서 확인하는지", example = "true")
boolean isPublic
) {
}

public record ManagerParticipationRequest(
@Schema(description = "참여자 역할", example = "REVIEWER")
MemberRole memberRole,

@Schema(description = "참여자가 원하는 매칭 인원 수", example = "3")
int matchingSize
) {
}

private static final int INITIAL_REVIEWER_COUNT = 0;
private static final int INITIAL_BOTH_COUNT = 0;
private static final RoomStatus INITIAL_ROOM_STATUS = RoomStatus.OPEN;

public Room toEntity(Member manager) {
return new Room(
roomInfoRequest.title(), roomInfoRequest.content(), roomInfoRequest.matchingSize(),
repositoryRequest.repositoryLink(),
roomInfoRequest.thumbnailLink(), roomInfoRequest.keywords(),
INITIAL_REVIEWER_COUNT, INITIAL_BOTH_COUNT,
roomInfoRequest.limitedParticipants(), manager,
deadlineRequest.recruitmentDeadline(), deadlineRequest.reviewDeadline(),
repositoryRequest.classification(),
INITIAL_ROOM_STATUS
);
}

@JsonIgnore
public boolean isPublic() {
return repositoryRequest().isPublic();
}
}
6 changes: 3 additions & 3 deletions backend/src/main/java/corea/room/dto/RoomResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static RoomResponse of(Room room, MemberRole role, ParticipationStatus pa
room.getReviewDeadline(),
participationStatus,
role,
room.getRoomStatus(),
room.getRoomStatusString(),
room.getClassification(),
DEFAULT_MESSAGE,
isPublic
Expand All @@ -118,7 +118,7 @@ public static RoomResponse of(Room room, Participation participation, boolean is
room.getReviewDeadline(),
participation.getStatus(),
participation.getMemberRole(),
room.getRoomStatus(),
room.getRoomStatusString(),
room.getClassification(),
DEFAULT_MESSAGE,
isPublic
Expand All @@ -142,7 +142,7 @@ public static RoomResponse of(Room room, Participation participation, FailedMatc
room.getReviewDeadline(),
participation.getStatus(),
participation.getMemberRole(),
room.getRoomStatus(),
room.getRoomStatusString(),
room.getClassification(),
failedMatching.getMatchingFailedReason(),
isPublic
Expand Down
Loading
Loading