Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public enum SwaggerResponseDescription {
RECORD_NOT_FOUND,
RECORD_ACCESS_FORBIDDEN
))),
RECORD_UPDATE(new LinkedHashSet<>(Set.of(
ROOM_ACCESS_FORBIDDEN,
RECORD_NOT_FOUND,
RECORD_ACCESS_FORBIDDEN
))),

// Vote
VOTE_CREATE(new LinkedHashSet<>(Set.of(
Expand All @@ -172,6 +177,11 @@ public enum SwaggerResponseDescription {
VOTE_NOT_FOUND,
VOTE_ACCESS_FORBIDDEN
))),
VOTE_UPDATE(new LinkedHashSet<>(Set.of(
ROOM_ACCESS_FORBIDDEN,
VOTE_NOT_FOUND,
VOTE_ACCESS_FORBIDDEN
))),


// FEED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import konkuk.thip.common.dto.BaseResponse;
import konkuk.thip.common.security.annotation.UserId;
import konkuk.thip.common.swagger.annotation.ExceptionDescription;
import konkuk.thip.roompost.adapter.in.web.request.AttendanceCheckCreateRequest;
import konkuk.thip.roompost.adapter.in.web.response.AttendanceCheckCreateResponse;
import konkuk.thip.roompost.application.port.in.AttendanceCheckCreateUseCase;
import konkuk.thip.roompost.adapter.in.web.request.RecordCreateRequest;
import konkuk.thip.roompost.adapter.in.web.request.VoteCreateRequest;
import konkuk.thip.roompost.adapter.in.web.request.VoteRequest;
import konkuk.thip.roompost.adapter.in.web.request.*;
import konkuk.thip.roompost.adapter.in.web.response.*;
import konkuk.thip.roompost.application.port.in.*;
import konkuk.thip.roompost.application.port.in.dto.record.RecordDeleteCommand;
Expand All @@ -29,6 +24,7 @@
public class RoomPostCommandController {
private final RecordCreateUseCase recordCreateUseCase;
private final RecordDeleteUseCase recordDeleteUseCase;
private final RoomPostUpdateUseCase roomPostUpdateUseCase;

private final VoteCreateUseCase voteCreateUseCase;
private final VoteDeleteUseCase voteDeleteUseCase;
Expand Down Expand Up @@ -133,4 +129,38 @@ public BaseResponse<AttendanceCheckCreateResponse> createFeed(
attendanceCheckCreateUseCase.create(request.toCommand(userId, roomId))
));
}

@Operation(
summary = "기록 수정",
description = "사용자가 방 기록을 수정합니다. (기록 내용만 수정 가능)"
)
@PatchMapping("/rooms/{roomId}/records/{recordId}")
@ExceptionDescription(RECORD_UPDATE)
public BaseResponse<RecordUpdateResponse> updateRecord(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(description = "수정할 방 ID", example = "1") @PathVariable Long roomId,
@Parameter(description = "수정할 기록 ID", example = "1") @PathVariable Long recordId,
@RequestBody @Valid final RecordUpdateRequest request
) {
return BaseResponse.ok(RecordUpdateResponse.of(
roomPostUpdateUseCase.updateRecord(request.toCommand(userId, roomId, recordId))
));
}

@Operation(
summary = "투표 수정",
description = "사용자가 방 투표를 수정합니다. (투표 내용만 수정 가능)"
)
@PatchMapping("/rooms/{roomId}/votes/{voteId}")
@ExceptionDescription(VOTE_UPDATE)
public BaseResponse<VoteUpdateResponse> updateVote(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(description = "수정할 방 ID", example = "1") @PathVariable Long roomId,
@Parameter(description = "수정할 투표 ID", example = "1") @PathVariable Long voteId,
@RequestBody @Valid final VoteUpdateRequest request
) {
return BaseResponse.ok(VoteUpdateResponse.of(
roomPostUpdateUseCase.updateVote(request.toCommand(userId, roomId, voteId))
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package konkuk.thip.roompost.adapter.in.web.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import konkuk.thip.roompost.application.port.in.dto.record.RecordUpdateCommand;

public record RecordUpdateRequest(
@Schema(description = "기록 내용", example = "띱은 최고의 서비스인가?")
@NotBlank(message = "기록 내용은 필수입니다.")
@Size(max = 500, message = "기록 내용은 최대 500자 입니다.")
String content
Comment on lines +9 to +12
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

) {
public RecordUpdateCommand toCommand(Long userId, Long roomId, Long recordId) {
return new RecordUpdateCommand(
roomId,
recordId,
userId,
this.content
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package konkuk.thip.roompost.adapter.in.web.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import konkuk.thip.roompost.application.port.in.dto.vote.VoteUpdateCommand;

public record VoteUpdateRequest(
@Schema(description = "투표 내용", example = "띱은 최고의 서비스인가?")
@NotBlank(message = "투표 내용은 필수입니다.")
@Size(max = 20, message = "투표 내용은 최대 20자 입니다.")
String content
) {
public VoteUpdateCommand toCommand(Long userId, Long roomId, Long voteId) {
return new VoteUpdateCommand(
roomId,
voteId,
userId,
this.content
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package konkuk.thip.roompost.adapter.in.web.response;

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

public record VoteUpdateResponse(
Long roomId
) {
public static VoteUpdateResponse of(Long roomId) {
return new VoteUpdateResponse(roomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RecordCommandPersistenceAdapter implements RecordCommandPort {
private final RecordMapper recordMapper;

@Override
public Long saveRecord(Record record) {
public Long save(Record record) {
UserJpaEntity userJpaEntity = userJpaRepository.findById(record.getCreatorId()).orElseThrow(
() -> new EntityNotFoundException(USER_NOT_FOUND)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package konkuk.thip.roompost.application.port.in;

import konkuk.thip.roompost.application.port.in.dto.record.RecordUpdateCommand;
import konkuk.thip.roompost.application.port.in.dto.vote.VoteUpdateCommand;

public interface RoomPostUpdateUseCase {
Long updateRecord(RecordUpdateCommand command);
Long updateVote(VoteUpdateCommand command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package konkuk.thip.roompost.application.port.in.dto.record;

public record RecordUpdateCommand(
Long roomId,
Long postId,
Long userId,
String content
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package konkuk.thip.roompost.application.port.in.dto.vote;

public record VoteUpdateCommand(
Long roomId,
Long postId,
Long userId,
String content
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface RecordCommandPort {

Long saveRecord(Record record);
Long save(Record record);

void update(Record record);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public RecordCreateResult createRecord(RecordCreateCommand command) {
validateRecord(record, book);

// 4. 문제없는 경우 Record 저장
Long newRecordId = recordCommandPort.saveRecord(record);
Long newRecordId = recordCommandPort.save(record);

// 5. RoomParticipant, Room progress 정보 update
roomProgressManager.updateUserAndRoomProgress(roomParticipant, room, book, record.getPage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package konkuk.thip.roompost.application.service;

import konkuk.thip.room.application.service.validator.RoomParticipantValidator;
import konkuk.thip.roompost.application.port.in.RoomPostUpdateUseCase;
import konkuk.thip.roompost.application.port.in.dto.record.RecordUpdateCommand;
import konkuk.thip.roompost.application.port.in.dto.vote.VoteUpdateCommand;
import konkuk.thip.roompost.application.port.out.RecordCommandPort;
import konkuk.thip.roompost.application.port.out.VoteCommandPort;
import konkuk.thip.roompost.domain.Record;
import konkuk.thip.roompost.domain.Vote;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class RoomPostUpdateService implements RoomPostUpdateUseCase {

private final RoomParticipantValidator roomParticipantValidator;
private final RecordCommandPort recordCommandPort;
private final VoteCommandPort voteCommandPort;

@Override
public Long updateRecord(RecordUpdateCommand command) {
// 1. 사용자가 방의 참가자인지 검증
roomParticipantValidator.validateUserIsRoomMember(command.roomId(), command.userId());

// 2. Record 조회
Record record = recordCommandPort.getByIdOrThrow(command.postId());

// 3. Record 수정
record.updateRecord(command.userId(), command.roomId(), command.content());

// 4. Record 업데이트
recordCommandPort.update(record);
return command.roomId();
}

@Override
public Long updateVote(VoteUpdateCommand command) {
// 1. 사용자가 방의 참가자인지 검증
roomParticipantValidator.validateUserIsRoomMember(command.roomId(), command.userId());

// 2. Vote 조회
Vote vote = voteCommandPort.getByIdOrThrow(command.postId());

// 3. Vote 수정
vote.updateVote(command.userId(), command.roomId(), command.content());

// 4. Vote 업데이트
voteCommandPort.updateVote(vote);
return command.roomId();
}
}
6 changes: 6 additions & 0 deletions src/main/java/konkuk/thip/roompost/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ private void validateCreator(Long userId) {
}
}

public void updateRecord(Long userId, Long roomId, String content) {
validateRoomId(roomId);
validateCreator(userId);
this.content = content;
}
Comment on lines +104 to +108
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


public void validateDeletable(Long userId,Long roomId) {
validateRoomId(roomId);
validateCreator(userId);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/konkuk/thip/roompost/domain/Vote.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ private void validateCreator(Long userId) {
}
}

public void updateVote(Long userId, Long roomId, String content) {
validateRoomId(roomId);
validateCreator(userId);
this.content = content;
}
Comment on lines +98 to +102
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


public void validateDeletable(Long userId,Long roomId) {
validateRoomId(roomId);
validateCreator(userId);
Expand All @@ -105,4 +111,5 @@ private void validateRoomId(Long roomId) {
throw new InvalidStateException(VOTE_ACCESS_FORBIDDEN, new IllegalArgumentException("투표가 해당 방에 속하지 않습니다."));
}
}

}
Loading