-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 투표하기 api 구현 #127
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
[feat] 투표하기 api 구현 #127
Changes from all commits
0ce8cb3
8ee2d04
b699c7e
64b566c
004b46e
dd8378b
f1d4c4f
4feb22a
f29e10b
8ed13d6
1bb9be7
8e9e926
f27eb64
364189b
924186c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,16 +10,22 @@ | |
|
|
||
| public interface RoomParticipantJpaRepository extends JpaRepository<RoomParticipantJpaEntity, Long>, RoomParticipantQueryRepository{ | ||
|
|
||
| @Query(value = "SELECT * FROM room_participants WHERE user_id = :userId AND room_id = :roomId AND status = 'ACTIVE'", nativeQuery = true) | ||
| @Query("SELECT rp FROM RoomParticipantJpaEntity rp " + | ||
| "WHERE rp.userJpaEntity.userId = :userId " + | ||
| "AND rp.roomJpaEntity.roomId = :roomId " + | ||
| "AND rp.status = 'ACTIVE'") | ||
|
Comment on lines
+13
to
+16
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. 굳굳 |
||
| Optional<RoomParticipantJpaEntity> findByUserIdAndRoomId(@Param("userId") Long userId, @Param("roomId") Long roomId); | ||
|
|
||
| @Query(value = "SELECT * FROM room_participants WHERE room_id = :roomId AND status = 'ACTIVE'", nativeQuery = true) | ||
| @Query("SELECT rp FROM RoomParticipantJpaEntity rp " + | ||
| "WHERE rp.roomJpaEntity.roomId = :roomId " + | ||
| "AND rp.status = 'ACTIVE'") | ||
| List<RoomParticipantJpaEntity> findAllByRoomId(@Param("roomId") Long roomId); | ||
|
|
||
| @Query( | ||
| value = "SELECT EXISTS (SELECT 1 FROM room_participants rp WHERE rp.user_id = :userId AND rp.room_id = :roomId AND rp.status = 'ACTIVE')", | ||
| nativeQuery = true | ||
| ) | ||
| boolean existByUserIdAndRoomId(@Param("userId") Long userId, @Param("roomId") Long roomId); | ||
| @Query("SELECT CASE WHEN COUNT(rp) > 0 THEN true ELSE false END " + | ||
| "FROM RoomParticipantJpaEntity rp " + | ||
| "WHERE rp.userJpaEntity.userId = :userId " + | ||
| "AND rp.roomJpaEntity.roomId = :roomId " + | ||
| "AND rp.status = 'ACTIVE'") | ||
| boolean existsByUserIdAndRoomId(@Param("userId") Long userId, @Param("roomId") Long roomId); | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ public class RoomParticipantValidator{ | |
|
|
||
| // 사용자가 방에 속해있는지 검증 | ||
| public void validateUserIsRoomMember(Long roomId, Long userId) { | ||
| if (!participantPort.existByUserIdAndRoomId(roomId, userId)) { | ||
| if (!participantPort.existByUserIdAndRoomId(userId, roomId)) { | ||
|
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. 허허 뭐죠,, 아마 테스트 코드에서는 유저, 방 모두 id = 1 이니 문제가 없었던게 아닐까 싶네요 |
||
| throw new InvalidStateException(ROOM_ACCESS_FORBIDDEN, | ||
| new IllegalArgumentException("사용자가 이 방의 참가자가 아닙니다. roomId=" + roomId + ", userId=" + userId)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package konkuk.thip.vote.adapter.in.web.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import konkuk.thip.vote.application.port.in.dto.VoteCommand; | ||
|
|
||
| @Schema( | ||
| description = "투표하기 요청 DTO 정보" | ||
| ) | ||
| public record VoteRequest( | ||
| @Schema( | ||
| description = "투표하려는 투표 항목 ID", | ||
| example = "1" | ||
| ) | ||
| @NotNull(message = "voteItemId는 필수입니다.") | ||
| Long voteItemId, | ||
| @Schema( | ||
| description = "투표 유형 (true: 투표하기, false: 투표 취소하기)", | ||
| example = "true" | ||
| ) | ||
| @NotNull(message = "type은 필수입니다.") | ||
| Boolean type | ||
| ) { | ||
| public VoteCommand toCommand(Long userId, Long roomId, Long voteId) { | ||
| return new VoteCommand(userId, roomId, voteId, voteItemId, type); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package konkuk.thip.vote.adapter.in.web.response; | ||
|
|
||
| import konkuk.thip.vote.application.port.in.dto.VoteResult; | ||
|
|
||
| public record VoteResponse( | ||
| Long voteItemId, | ||
| Long roomId, | ||
| Boolean type | ||
| ) { | ||
| public static VoteResponse of(VoteResult voteResult) { | ||
| return new VoteResponse(voteResult.voteItemId(), voteResult.roomId(), voteResult.type()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,9 @@ public class VoteParticipantJpaEntity extends BaseJpaEntity { | |
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "vote_item_id") | ||
| private VoteItemJpaEntity voteItemJpaEntity; | ||
|
|
||
| public VoteParticipantJpaEntity updateVoteItem(VoteItemJpaEntity voteItemJpaEntity) { | ||
| this.voteItemJpaEntity = voteItemJpaEntity; | ||
| return this; | ||
| } | ||
buzz0331 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+30
to
+33
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. 굳굳 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package konkuk.thip.vote.adapter.out.persistence.repository; | ||
|
|
||
| import konkuk.thip.vote.adapter.out.jpa.VoteParticipantJpaEntity; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface VoteParticipantQueryRepository { | ||
|
|
||
| Optional<VoteParticipantJpaEntity> findVoteParticipantByUserIdAndVoteId(Long userId, Long voteId); | ||
| } |
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.
굳굳 FE 배포 url을 명시하는 것을 고민했었는데, yml에 숨기는것도 좋은거같습니다