Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package konkuk.thip.record.adapter.in.web.response;

import konkuk.thip.record.application.port.in.dto.RecordCreateResult;

public record RecordCreateResponse(
Long recordId
Long recordId,
Long roomId
) {
public static RecordCreateResponse of(Long recordId) {
return new RecordCreateResponse(recordId);
public static RecordCreateResponse of(RecordCreateResult recordCreateResult) {
return new RecordCreateResponse(
recordCreateResult.recordId(),
recordCreateResult.roomId()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Builder
public record RecordSearchResponse(
List<PostDto> postList,
Long roomId,
String nextCursor,
Boolean isLast
){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package konkuk.thip.record.application.port.in;

import konkuk.thip.record.application.port.in.dto.RecordCreateCommand;
import konkuk.thip.record.application.port.in.dto.RecordCreateResult;

public interface RecordCreateUseCase {

Long createRecord(RecordCreateCommand command);
RecordCreateResult createRecord(RecordCreateCommand command);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package konkuk.thip.record.application.port.in.dto;

public record RecordCreateResult(
Long recordId,
Long roomId
) {
public static RecordCreateResult of(Long recordId, Long roomId) {
return new RecordCreateResult(recordId, roomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import konkuk.thip.common.exception.BusinessException;
import konkuk.thip.record.application.port.in.RecordCreateUseCase;
import konkuk.thip.record.application.port.in.dto.RecordCreateCommand;
import konkuk.thip.record.application.port.in.dto.RecordCreateResult;
import konkuk.thip.record.application.port.out.RecordCommandPort;
import konkuk.thip.record.domain.Record;
import konkuk.thip.room.application.port.out.RoomCommandPort;
import konkuk.thip.room.application.port.out.RoomParticipantCommandPort;
import konkuk.thip.room.application.service.validator.RoomParticipantValidator;
import konkuk.thip.room.domain.Room;
import konkuk.thip.room.domain.RoomParticipant;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,10 +30,14 @@ public class RecordCreateService implements RecordCreateUseCase {
private final BookCommandPort bookCommandPort;
private final RoomParticipantCommandPort roomParticipantCommandPort;

private final RoomParticipantValidator roomParticipantValidator;

@Transactional
@Override
//todo updateRoomPercentage 스케줄러로 책임을 분리할지 논의
public Long createRecord(RecordCreateCommand command) {
public RecordCreateResult createRecord(RecordCreateCommand command) {
roomParticipantValidator.validateUserIsRoomMember(command.userId(), command.roomId());

// 1. Record 생성
Record record = Record.withoutId(
command.content(),
Expand All @@ -48,14 +54,16 @@ public Long createRecord(RecordCreateCommand command) {

// 3. 유효성 검증
validateRoom(room);
validateUserRoom(roomParticipant);
validateRoomParticipant(roomParticipant);
validateRecord(record, book);

// 4. UserRoom의 currentPage, userPercentage 업데이트
updateRoomProgress(roomParticipant, record, book, room);

// 5. Record 저장
return recordCommandPort.saveRecord(record);
Long newRecordId = recordCommandPort.saveRecord(record);

return RecordCreateResult.of(newRecordId, command.roomId());
}

private void updateRoomProgress(RoomParticipant roomParticipant, Record record, Book book, Room room) {
Expand All @@ -69,7 +77,7 @@ private void updateRoomProgress(RoomParticipant roomParticipant, Record record,
}
}

private void validateUserRoom(RoomParticipant roomParticipant) {
private void validateRoomParticipant(RoomParticipant roomParticipant) {
// UserRoom의 총평 작성 가능 여부 검증
if (!roomParticipant.canWriteOverview()) {
String message = String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public RecordSearchResponse search(RecordSearchQuery recordSearchQuery) {

// RecordSearchResponse 생성
return RecordSearchResponse.builder()
.roomId(roomId)
.postList(postDtos)
.nextCursor(cursorBasedList.nextCursor())
.isLast(!cursorBasedList.hasNext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import konkuk.thip.common.swagger.annotation.ExceptionDescription;
import konkuk.thip.room.adapter.in.web.request.RoomCreateRequest;
import konkuk.thip.room.adapter.in.web.request.RoomJoinRequest;
import konkuk.thip.room.adapter.in.web.response.RoomRecruitCloseResponse;
import konkuk.thip.room.adapter.in.web.response.RoomJoinResponse;
import konkuk.thip.room.adapter.in.web.response.RoomCreateResponse;
import konkuk.thip.room.application.port.in.RoomCreateUseCase;
import konkuk.thip.room.application.port.in.RoomJoinUseCase;
import konkuk.thip.room.application.port.in.RoomRecruitCloseUsecase;
import konkuk.thip.room.application.port.in.RoomRecruitCloseUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -28,7 +30,7 @@ public class RoomCommandController {

private final RoomCreateUseCase roomCreateUseCase;
private final RoomJoinUseCase roomJoinUsecase;
private final RoomRecruitCloseUsecase roomRecruitCloseUsecase;
private final RoomRecruitCloseUseCase roomRecruitCloseUsecase;

/**
* 방 생성 요청
Expand Down Expand Up @@ -57,13 +59,14 @@ public BaseResponse<RoomCreateResponse> createRoom(
)
@ExceptionDescription(ROOM_JOIN_CANCEL)
@PostMapping("/rooms/{roomId}/join")
public BaseResponse<Void> joinRoom(
public BaseResponse<RoomJoinResponse> joinRoom(
@Valid @RequestBody final RoomJoinRequest request,
@Parameter(hidden = true) @UserId final Long userId,
@Parameter(description = "참여/취소하려는 방의 ID", example = "1") @PathVariable final Long roomId
) {
roomJoinUsecase.changeJoinState(request.toCommand(userId, roomId));
return BaseResponse.ok(null);
return BaseResponse.ok(
RoomJoinResponse.of(roomJoinUsecase.changeJoinState(request.toCommand(userId, roomId)))
);
}

/**
Expand All @@ -75,10 +78,11 @@ public BaseResponse<Void> joinRoom(
)
@ExceptionDescription(ROOM_RECRUIT_CLOSE)
@PostMapping("/rooms/{roomId}/close")
public BaseResponse<Void> closeRoomRecruit(
public BaseResponse<RoomRecruitCloseResponse> closeRoomRecruit(
@Parameter(hidden = true) @UserId final Long userId,
@Parameter(description = "모집을 마감할 방의 ID", example = "1") @PathVariable final Long roomId) {
roomRecruitCloseUsecase.closeRoomRecruit(userId, roomId);
return BaseResponse.ok(null);
return BaseResponse.ok(
RoomRecruitCloseResponse.of(roomRecruitCloseUsecase.closeRoomRecruit(userId, roomId))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public record RoomGetBookPageResponse(
int totalBookPage,
boolean isOverviewPossible
boolean isOverviewPossible,
Long roomId
) {
public static RoomGetBookPageResponse of(int totalBookPage, boolean isOverviewPossible) {
return new RoomGetBookPageResponse(totalBookPage, isOverviewPossible);
public static RoomGetBookPageResponse of(int totalBookPage, boolean isOverviewPossible, Long roomId) {
return new RoomGetBookPageResponse(totalBookPage, isOverviewPossible, roomId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package konkuk.thip.room.adapter.in.web.response;

import konkuk.thip.room.application.port.in.dto.RoomJoinResult;

public record RoomJoinResponse(
Long roomId,
String type
) {
public static RoomJoinResponse of(RoomJoinResult roomJoinResult) {
return new RoomJoinResponse(
roomJoinResult.roomId(),
roomJoinResult.type()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package konkuk.thip.room.adapter.in.web.response;

public record RoomRecruitCloseResponse(
Long roomId
) {
public static RoomRecruitCloseResponse of(Long roomId) {
return new RoomRecruitCloseResponse(roomId);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package konkuk.thip.room.application.port.in;

import konkuk.thip.room.application.port.in.dto.RoomJoinCommand;
import konkuk.thip.room.application.port.in.dto.RoomJoinResult;

public interface RoomJoinUseCase {

void changeJoinState(RoomJoinCommand roomJoinCommand);
RoomJoinResult changeJoinState(RoomJoinCommand roomJoinCommand);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package konkuk.thip.room.application.port.in;

public interface RoomRecruitCloseUseCase {
Long closeRoomRecruit(Long userId, Long roomId);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package konkuk.thip.room.application.port.in.dto;

public record RoomJoinResult(
Long roomId,
String type
) {
public static RoomJoinResult of(Long roomId, String type) {
return new RoomJoinResult(roomId, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public RoomGetBookPageResponse getBookPage(Long userId, Long roomId) {
Book book = bookCommandPort.findBookByRoomId(roomId);
RoomParticipant roomParticipant = roomParticipantCommandPort.getByUserIdAndRoomIdOrThrow(userId, roomId);

return RoomGetBookPageResponse.of(book.getPageCount(), roomParticipant.canWriteOverview());
return RoomGetBookPageResponse.of(book.getPageCount(), roomParticipant.canWriteOverview(), roomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import konkuk.thip.common.exception.code.ErrorCode;
import konkuk.thip.room.application.port.in.RoomJoinUseCase;
import konkuk.thip.room.application.port.in.dto.RoomJoinCommand;
import konkuk.thip.room.application.port.in.dto.RoomJoinResult;
import konkuk.thip.room.application.port.out.RoomCommandPort;
import konkuk.thip.room.application.port.out.RoomParticipantCommandPort;
import konkuk.thip.room.domain.Room;
Expand All @@ -26,7 +27,7 @@ public class RoomJoinService implements RoomJoinUseCase {

@Override
@Transactional
public void changeJoinState(RoomJoinCommand roomJoinCommand) {
public RoomJoinResult changeJoinState(RoomJoinCommand roomJoinCommand) {
RoomJoinType type = RoomJoinType.from(roomJoinCommand.type());

// 방이 존재하지 않거나 만료된 경우
Expand All @@ -49,6 +50,8 @@ public void changeJoinState(RoomJoinCommand roomJoinCommand) {

// 방의 상태 업데이트
roomCommandPort.update(room);

return RoomJoinResult.of(room.getId(), roomJoinCommand.type());
}

private void handleCancel(RoomJoinCommand roomJoinCommand, Optional<RoomParticipant> participantOptional, Optional<RoomParticipant> roomParticipantOptional, Room room) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import konkuk.thip.common.exception.BusinessException;
import konkuk.thip.common.exception.code.ErrorCode;
import konkuk.thip.room.application.port.in.RoomRecruitCloseUsecase;
import konkuk.thip.room.application.port.in.RoomRecruitCloseUseCase;
import konkuk.thip.room.application.port.out.RoomCommandPort;
import konkuk.thip.room.application.port.out.RoomParticipantCommandPort;
import konkuk.thip.room.domain.Room;
Expand All @@ -13,15 +13,15 @@

@Service
@RequiredArgsConstructor
public class RoomRecruitCloseService implements RoomRecruitCloseUsecase {
public class RoomRecruitCloseService implements RoomRecruitCloseUseCase {

private final RoomParticipantCommandPort roomParticipantCommandPort;
private final RoomCommandPort roomCommandPort;

//todo 모집 마감시 방 참여자들에게 모집 마감 알림 전송
@Override
@Transactional
public void closeRoomRecruit(Long userId, Long roomId) {
public Long closeRoomRecruit(Long userId, Long roomId) {
// 1. 방 참여자 조회
RoomParticipant roomParticipant = roomParticipantCommandPort.findByUserIdAndRoomIdOptional(userId, roomId)
.orElseThrow(() -> new BusinessException(ErrorCode.ROOM_RECRUIT_CANNOT_CLOSED,
Expand All @@ -36,6 +36,8 @@ public void closeRoomRecruit(Long userId, Long roomId) {

// 4. Room 테이블 업데이트
roomCommandPort.update(room);

return room.getId();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package konkuk.thip.vote.adapter.in.web.response;

import konkuk.thip.vote.application.port.in.dto.VoteCreateResult;

public record VoteCreateResponse(
Long voteId
Long voteId,
Long roomId
) {
public static VoteCreateResponse of(Long voteId) {
return new VoteCreateResponse(voteId);
public static VoteCreateResponse of(VoteCreateResult voteCreateResult) {
return new VoteCreateResponse(
voteCreateResult.voteId(),
voteCreateResult.roomId()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package konkuk.thip.vote.application.port.in;

import konkuk.thip.vote.application.port.in.dto.VoteCreateCommand;
import konkuk.thip.vote.application.port.in.dto.VoteCreateResult;

public interface VoteCreateUseCase {

Long createVote(VoteCreateCommand command);
VoteCreateResult createVote(VoteCreateCommand command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package konkuk.thip.vote.application.port.in.dto;

public record VoteCreateResult(
Long voteId,
Long roomId
) {
public static VoteCreateResult of(Long voteId, Long roomId) {
return new VoteCreateResult(voteId, roomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import konkuk.thip.room.domain.Room;
import konkuk.thip.vote.application.port.in.VoteCreateUseCase;
import konkuk.thip.vote.application.port.in.dto.VoteCreateCommand;
import konkuk.thip.vote.application.port.in.dto.VoteCreateResult;
import konkuk.thip.vote.application.port.out.VoteCommandPort;
import konkuk.thip.vote.domain.Vote;
import konkuk.thip.vote.domain.VoteItem;
Expand All @@ -28,7 +29,7 @@ public class VoteCreateService implements VoteCreateUseCase {
@Transactional
@Override
//todo UserRoom 업데이트 로직 추가 필요!!
public Long createVote(VoteCreateCommand command) {
public VoteCreateResult createVote(VoteCreateCommand command) {
// 1. validate
Vote vote = Vote.withoutId(
command.content(),
Expand All @@ -53,7 +54,7 @@ public Long createVote(VoteCreateCommand command) {
.toList();
voteCommandPort.saveAllVoteItems(voteItems);

return savedVoteId;
return VoteCreateResult.of(savedVoteId, command.roomId());
}

private void validateVote(Vote vote) {
Expand Down