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

YEL-193 [feat] 친구 쪽지 전체 조회하기 #421

Merged
merged 11 commits into from
Jan 30, 2024
72 changes: 24 additions & 48 deletions src/docs/asciidoc/find-friend-votes-v2.adoc
Original file line number Diff line number Diff line change
@@ -1,62 +1,24 @@
:reproducible:
== 친구 투표 전체 조회 (명세)
== 친구 투표 전체 조회 v2


=== 요청

[http]
include::{snippets}/api/v2/vote/friend/http-request.adoc[]

----
=== 요청 파라미터

GET /v2/vote/friend?page={}&type={} HTTP/1.1
Authorization: Bearer your-access-token
Content-Type: application-json
include::{snippets}/api/v2/vote/friend/request-parameters.adoc[]

----
=== 응답

include::{snippets}/api/v2/vote/friend/http-response.adoc[]

*업데이트 예정*
- "type": "send" | null

|===
|`+type+`| 조회할 쪽지 종류 (null -> 모든쪽지, send-> 보낸쪽지)
|===

=== 응답

[http, json]
----

{
"status" : 200,
"message" : "투표 조회에 성공했습니다.",
"data" : {
"totalCount" : 1,
"friendVotes" : [ {
"id" : 1,
"senderId" : 1,
"senderName" : "name1",
"senderGender" : "MALE",
"senderYelloId" : "MALE",
"senderProfileImage": "imageUrl",
"receiverId" : 2,
"receiverName" : "name2",
"receiverGender" : "MALE",
"receiverYelloId" : "MALE",
"receiverProfileImage" : "test image",
"vote" : {
"nameHead" : "나는",
"nameFoot" : "와",
"keywordHead" : "멋진",
"keyword" : "test",
"keywordFoot" : "에서 놀고싶어"
},
"isHintUsed" : false,
"createdAt" : "0초 전"
"isUserSenderVote" : true
} ]
}
}

----

*필드 타입*

Expand Down Expand Up @@ -86,13 +48,27 @@ Content-Type: application-json
* "keyword": String
* "keywordFoot": String


=== Excpetion

- 잘못된 type을 queryString에 보내는 경우

[http,json]
----
{
"status": 403,
"message": "[VoteForbiddenException] 잘못된 투표 유형입니다."
}
----

=== NOTE

- 모든 종류의 쪽지를 조회할 때 `/api/v1/vote/friend?page=0` 으로 요청해주세요
* `type=` 을 명시하지 마세요
- 모든 종류의 쪽지를 조회할 때 `/api/v1/vote/friend?page=0&type=null` 으로 요청해주세요
- 내가 보낸 쪽지를 조회할 때 `/api/v1/vote/friend?page=0&type=send` 으로 요청해주세요
- `senderGender` 필드가 다른 API와 일관되지 못한점 미안해요 ㅠ

=== CHANGELOG

- 2924.01.30 API 릴리즈
- 2024.01.26 필드 명세 업데이트
- 2024.01.09 `type` 명세 업데이트
2 changes: 1 addition & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

* link:find-friend-votes.html[친구 투표 전체 조회하기, 2024-01-09]

* ⬆️ link:find-friend-votes-v2.html[친구 투표 전체 조회하기 v2 (명세), 2024-01-26]
* ⬆️ link:find-friend-votes-v2.html[친구 투표 전체 조회하기 v2, 2024-01-30]

* link:get-unread-vote.html[읽지 않은 쪽지 개수 조회하기]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.yello.server.domain.vote.dto.response.VoteAvailableResponse;
import com.yello.server.domain.vote.dto.response.VoteCreateResponse;
import com.yello.server.domain.vote.dto.response.VoteDetailResponse;
import com.yello.server.domain.vote.dto.response.VoteFriendAndUserResponse;
import com.yello.server.domain.vote.dto.response.VoteFriendResponse;
import com.yello.server.domain.vote.dto.response.VoteListResponse;
import com.yello.server.domain.vote.dto.response.VoteUnreadCountResponse;
Expand All @@ -37,56 +38,69 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1/vote")
@RequestMapping("api")
@RequiredArgsConstructor
public class VoteController {

private final VoteService voteService;
private final NotificationService notificationService;

@GetMapping
public BaseResponse<VoteListResponse> findAllMyVotes(@RequestParam Integer page, @AccessTokenUser User user) {
@GetMapping("/v1/vote")
public BaseResponse<VoteListResponse> findAllMyVotes(@RequestParam Integer page,
@AccessTokenUser User user) {
val data = voteService.findAllVotes(user.getId(), createPageableLimitTen(page));
return BaseResponse.success(READ_VOTE_SUCCESS, data);
}

@GetMapping("/count")
@GetMapping("/v1/vote/count")
public BaseResponse<VoteUnreadCountResponse> getUnreadVoteCount(@AccessTokenUser User user) {
val data = voteService.getUnreadVoteCount(user.getId());
return BaseResponse.success(READ_VOTE_SUCCESS, data);
}

@GetMapping("/friend")
public BaseResponse<VoteFriendResponse> findAllFriendVotes(@RequestParam Integer page, @AccessTokenUser User user) {
@GetMapping("/v1/vote/friend")
public BaseResponse<VoteFriendResponse> findAllFriendVotes(@RequestParam Integer page,
@AccessTokenUser User user) {
val data = voteService.findAllFriendVotes(user.getId(), createPageableLimitTen(page));
return BaseResponse.success(READ_VOTE_SUCCESS, data);
}

@GetMapping("/{voteId}")
public BaseResponse<VoteDetailResponse> findVote(@PathVariable Long voteId, @AccessTokenUser User user) {
@GetMapping("/v1/vote/{voteId}")
public BaseResponse<VoteDetailResponse> findVote(@PathVariable Long voteId,
@AccessTokenUser User user) {
val data = voteService.findVoteById(voteId, user.getId());
return BaseResponse.success(READ_VOTE_SUCCESS, data);
}

@PatchMapping("/{voteId}/keyword")
public BaseResponse<KeywordCheckResponse> checkKeyword(@PathVariable Long voteId, @AccessTokenUser User user) {
@GetMapping("/v2/vote/friend")
public BaseResponse<VoteFriendAndUserResponse> findAllFriendVotesWithType(
@RequestParam("page") Integer page, @RequestParam("type") String type,
Copy link
Member

Choose a reason for hiding this comment

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

아래와 같이 type을 Nullable하게 만들고,

@RequestParam(value = "type", required = false) String type

https://github.com/team-yello/YELLO-Server/blob/feat/YEL-187/src/main/java/com/yello/server/domain/admin/controller/AdminController.java#L156
을 참조해서 ENUM 처리를 해주세요

@AccessTokenUser User user) {
val data = voteService.findAllFriendVotesWithType(user.getId(), createPageableLimitTen(page), type);
return BaseResponse.success(READ_VOTE_SUCCESS, data);
}

@PatchMapping("/v1/vote/{voteId}/keyword")
public BaseResponse<KeywordCheckResponse> checkKeyword(@PathVariable Long voteId,
@AccessTokenUser User user) {
val keywordCheckResponse = voteService.checkKeyword(user.getId(), voteId);
return BaseResponse.success(CHECK_KEYWORD_SUCCESS, keywordCheckResponse);
}

@GetMapping("/question")
public BaseResponse<List<QuestionForVoteResponse>> findVoteQuestions(@AccessTokenUser User user) {
@GetMapping("/v1/vote/question")
public BaseResponse<List<QuestionForVoteResponse>> findVoteQuestions(
@AccessTokenUser User user) {
val data = voteService.findVoteQuestionList(user.getId());
return BaseResponse.success(READ_YELLO_VOTE_SUCCESS, data);
}

@GetMapping("/available")
@GetMapping("/v1/vote/available")
public BaseResponse<VoteAvailableResponse> checkVoteAvailable(@AccessTokenUser User user) {
val data = voteService.checkVoteAvailable(user.getId());
return BaseResponse.success(READ_YELLO_START_SUCCESS, data);
}

@PostMapping
@PostMapping("/v1/vote")
public BaseResponse<VoteCreateResponse> createVote(
@AccessTokenUser User user,
@RequestBody CreateVoteRequest request
Expand All @@ -98,14 +112,16 @@ public BaseResponse<VoteCreateResponse> createVote(
return BaseResponse.success(CREATE_VOTE_SUCCESS, response);
}

@PatchMapping("/{voteId}/name")
public BaseResponse<RevealNameResponse> revealNameHint(@AccessTokenUser User user, @PathVariable Long voteId) {
@PatchMapping("/v1/vote/{voteId}/name")
public BaseResponse<RevealNameResponse> revealNameHint(@AccessTokenUser User user,
@PathVariable Long voteId) {
val data = voteService.revealNameHint(user.getId(), voteId);
return BaseResponse.success(SuccessCode.REVEAL_NAME_HINT_SUCCESS, data);
}

@PatchMapping("/{voteId}/fullname")
public BaseResponse<RevealFullNameResponse> revealFullName(@AccessTokenUser User user, @PathVariable Long voteId) {
@PatchMapping("/v1/vote/{voteId}/fullname")
public BaseResponse<RevealFullNameResponse> revealFullName(@AccessTokenUser User user,
@PathVariable Long voteId) {
val data = voteService.revealFullName(user.getId(), voteId);
return BaseResponse.success(SuccessCode.REVEAL_NAME_SUCCESS, data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yello.server.domain.vote.dto.response;

import java.util.List;
import lombok.Builder;

@Builder
public record VoteFriendAndUserResponse(
Long totalCount,
List<VoteFriendAndUserVO> friendVotes

) {

public static VoteFriendAndUserResponse of(Long totalCount, List<VoteFriendAndUserVO> friendVotes) {
return VoteFriendAndUserResponse.builder()
.totalCount(totalCount)
.friendVotes(friendVotes)
.build();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.yello.server.domain.vote.dto.response;

import static com.yello.server.global.common.factory.TimeFactory.toFormattedString;

import com.yello.server.domain.vote.entity.Vote;
import lombok.Builder;

@Builder
public record VoteFriendAndUserVO(
Long id,
Long senderId,
String senderName,
String senderGender,
String senderYelloId,
String senderProfileImage,
Long receiverId,
String receiverName,
String receiverGender,
String receiverYelloId,
String receiverProfileImage,
VoteContentVO vote,
Boolean isHintUsed,
String createdAt,
Boolean isUserSenderVote
) {

public static VoteFriendAndUserVO of(Vote vote, Boolean isUserSenderVote) {
return VoteFriendAndUserVO.builder()
.id(vote.getId())
.senderId(vote.getSender().getId())
.senderName(vote.getSender().getName())
.senderGender(vote.getSender().getGender().name())
Copy link
Member

Choose a reason for hiding this comment

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

차후 ENUM 점검할 때 getInitial()로 변경할 수 있도록 합시다

Copy link
Member Author

Choose a reason for hiding this comment

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

좋습니다

.senderYelloId(vote.getSender().getYelloId())
.senderProfileImage(vote.getSender().getProfileImage())
.receiverId(vote.getReceiver().getId())
.receiverGender(vote.getReceiver().getGender().name())
.receiverName(vote.getReceiver().getName())
.receiverYelloId(vote.getReceiver().getYelloId())
.receiverProfileImage(vote.getReceiver().getProfileImage())
.vote(VoteContentVO.of(vote))
.isHintUsed(vote.getIsAnswerRevealed())
.createdAt(toFormattedString(vote.getCreatedAt()))
.isUserSenderVote(isUserSenderVote)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ public interface VoteRepository {
Integer countOpenNameByReceiverUserId(Long userId);

Integer countOpenFullNameByReceiverUserId(Long userId);

List<Vote> findUserSendReceivedByFriends(Long userId, Pageable pageable);

Long countUserSendReceivedByFriends(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.yello.server.domain.vote.repository;

import static com.yello.server.domain.friend.entity.QFriend.friend;
import static com.yello.server.domain.vote.entity.QVote.vote;
import static com.yello.server.global.common.ErrorCode.NOT_FOUND_VOTE_EXCEPTION;

import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.yello.server.domain.vote.entity.Vote;
import com.yello.server.domain.vote.exception.VoteNotFoundException;
import java.util.List;
Expand All @@ -17,6 +21,7 @@
public class VoteRepositoryImpl implements VoteRepository {

private final VoteJpaRepository voteJpaRepository;
private final JPAQueryFactory jpaQueryFactory;

@Override
public Vote save(Vote vote) {
Expand Down Expand Up @@ -83,4 +88,40 @@ public Integer countOpenNameByReceiverUserId(Long userId) {
public Integer countOpenFullNameByReceiverUserId(Long userId) {
return voteJpaRepository.countOpenFullNameByReceiverUserId(userId);
}

@Override
public List<Vote> findUserSendReceivedByFriends(Long userId, Pageable pageable) {
return jpaQueryFactory.selectFrom(vote)
.where(vote.sender.id.eq(userId)
.and(vote.receiver.id.in(
JPAExpressions
.select(friend.target.id)
.from(friend)
.where(friend.user.id.eq(userId)
.and(friend.deletedAt.isNull())
)))
.and(vote.sender.deletedAt.isNull())
.and(vote.receiver.deletedAt.isNull()))
.orderBy(vote.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
}

@Override
public Long countUserSendReceivedByFriends(Long userId) {
return jpaQueryFactory.select(vote.count())
.from(vote)
.where(vote.sender.id.eq(userId)
.and(vote.receiver.id.in(
JPAExpressions
.select(friend.target.id)
.from(friend)
.where(friend.user.id.eq(userId)
.and(friend.deletedAt.isNull())
)))
.and(vote.sender.deletedAt.isNull())
.and(vote.receiver.deletedAt.isNull()))
.fetchOne();
}
}
Loading
Loading