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
70 changes: 23 additions & 47 deletions src/docs/asciidoc/find-friend-votes-v2.adoc
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
: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 +47,28 @@ 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=` 을 명시하지 마세요
* type을 명시하지 마세요
- 내가 보낸 쪽지를 조회할 때 `/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 @@ -57,7 +57,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,9 +16,11 @@
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;
import com.yello.server.domain.vote.entity.VoteType;
import com.yello.server.domain.vote.service.VoteService;
import com.yello.server.global.common.SuccessCode;
import com.yello.server.global.common.annotation.AccessTokenUser;
Expand All @@ -37,56 +39,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(value = "type", required = false) String type,
@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 +113,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();
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/yello/server/domain/vote/entity/VoteType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yello.server.domain.vote.entity;

import java.text.MessageFormat;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum VoteType {
SEND("send");

private final String intial;

public static VoteType fromCode(String dbData) {
return Arrays.stream(VoteType.values())
.filter(v -> v.getIntial().equals(dbData))
.findAny()
.orElseThrow(() -> new IllegalArgumentException(
MessageFormat.format("존재하지 않는 투표 타입입니다. {0}", dbData)));
}

public String intial() {
return intial;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.yello.server.domain.vote.entity;

import com.yello.server.domain.user.entity.Social;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import lombok.extern.log4j.Log4j2;

@Converter
@Log4j2
public class VoteTypeConverter implements AttributeConverter<VoteType, String> {

@Override
public String convertToDatabaseColumn(VoteType voteType) {
if (voteType == null) {
return null;
}
return voteType.getIntial();
}

@Override
public VoteType convertToEntityAttribute(String dbData) {
if (dbData == null) {
return null;
}
try {
return VoteType.fromCode(dbData);
} catch (IllegalArgumentException exception) {
log.error("failure to convert cause unexpected code" + dbData + exception);
throw exception;
}
}
}
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);
}
Loading
Loading