-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 기록,투표 수정하기 api 개발 #275
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11976f2
[feat] 기록/투표 수정하기 api 핸들러 정의 (#274)
buzz0331 07e1848
[feat] 기록/투표 수정하기 api 필요한 dto 선언 (#274)
buzz0331 8b81867
[feat] 기록/투표 수정하기 api 도메인 레벨 규칙 적용(#274)
buzz0331 245edf8
[rename] 기록 업데이트 이름 수정 (#274)
buzz0331 ceddd74
[rename] 기록 업데이트 이름 수정 (#274)
buzz0331 4b5c275
[feat] 기록/투표 수정 api 서비스 로직 구현 (#274)
buzz0331 489b990
[docs] 기록/투표 수정 api 명세 (#274)
buzz0331 004c666
[test] 기록/투표 수정 api 테스트 (#274)
buzz0331 211fe91
[test] 테스트 케이스 수정 (#274)
buzz0331 85211f4
[docs] api 명세 수정 (#274)
buzz0331 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/konkuk/thip/roompost/adapter/in/web/request/RecordUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) { | ||
| public RecordUpdateCommand toCommand(Long userId, Long roomId, Long recordId) { | ||
| return new RecordUpdateCommand( | ||
| roomId, | ||
| recordId, | ||
| userId, | ||
| this.content | ||
| ); | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/main/java/konkuk/thip/roompost/adapter/in/web/request/VoteUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/roompost/adapter/in/web/response/RecordUpdateResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/roompost/adapter/in/web/response/VoteUpdateResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/roompost/application/port/in/RoomPostUpdateUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/roompost/application/port/in/dto/record/RecordUpdateCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) { | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/roompost/application/port/in/dto/vote/VoteUpdateCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/konkuk/thip/roompost/application/service/RoomPostUpdateService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
|
||
| public void validateDeletable(Long userId,Long roomId) { | ||
| validateRoomId(roomId); | ||
| validateCreator(userId); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
|
||
| public void validateDeletable(Long userId,Long roomId) { | ||
| validateRoomId(roomId); | ||
| validateCreator(userId); | ||
|
|
@@ -105,4 +111,5 @@ private void validateRoomId(Long roomId) { | |
| throw new InvalidStateException(VOTE_ACCESS_FORBIDDEN, new IllegalArgumentException("투표가 해당 방에 속하지 않습니다.")); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM