Skip to content

Commit

Permalink
Merge pull request #167 from Gamegoo-repo/feat/163
Browse files Browse the repository at this point in the history
[Feat/163] λ§€λ„ˆ 정보 및 λ§€λ„ˆ ν‚€μ›Œλ“œ 개수 쑰회 API 뢄리
  • Loading branch information
Eunjin3395 authored Jan 17, 2025
2 parents fab8e6b + c1e77c3 commit 9257322
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerUpdateResponse;
Expand Down Expand Up @@ -79,11 +80,18 @@ public ApiResponse<MannerRatingResponse> getNegativeMannerRatingInfo(
return ApiResponse.ok(mannerFacadeService.getMannerRating(member, targetMemberId, false));
}

@Operation(summary = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 정보 쑰회 API", description = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 정보λ₯Ό μ‘°νšŒν•˜λŠ” API μž…λ‹ˆλ‹€.")
@Operation(summary = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 레벨 정보 쑰회 API", description = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 레벨 정보λ₯Ό μ‘°νšŒν•˜λŠ” API μž…λ‹ˆλ‹€.")
@Parameter(name = "memberId", description = "λŒ€μƒ νšŒμ›μ˜ id μž…λ‹ˆλ‹€.")
@GetMapping("/{memberId}")
public ApiResponse<MannerResponse> getMannerInfo(@PathVariable(name = "memberId") Long memberId) {
return ApiResponse.ok(mannerFacadeService.getMannerInfo(memberId));
@GetMapping("/level/{memberId}")
public ApiResponse<MannerResponse> getMannerLevelInfo(@PathVariable(name = "memberId") Long memberId) {
return ApiResponse.ok(mannerFacadeService.getMannerLevelInfo(memberId));
}

@Operation(summary = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ ν‚€μ›Œλ“œ 정보 쑰회 API", description = "νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ ν‚€μ›Œλ“œ 정보λ₯Ό μ‘°νšŒν•˜λŠ” API μž…λ‹ˆλ‹€.")
@Parameter(name = "memberId", description = "λŒ€μƒ νšŒμ›μ˜ id μž…λ‹ˆλ‹€.")
@GetMapping("/keyword/{memberId}")
public ApiResponse<MannerKeywordListResponse> getMannerKeywordInfo(@PathVariable(name = "memberId") Long memberId) {
return ApiResponse.ok(mannerFacadeService.getMannerKeywordInfo(memberId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.gamegoo.gamegoo_v2.social.manner.dto.response;

import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class MannerKeywordListResponse {

List<MannerKeywordResponse> mannerKeywords;

public static MannerKeywordListResponse of(List<MannerKeywordResponse> mannerKeywords) {
return MannerKeywordListResponse.builder()
.mannerKeywords(mannerKeywords)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class MannerResponse {

int mannerLevel;
Double mannerRank;
int mannerRatingCount;
List<MannerKeywordResponse> mannerKeywords;

public static MannerResponse of(int mannerLevel, Double mannerRank, int mannerRatingCount,
List<MannerKeywordResponse> mannerKeywords) {
public static MannerResponse of(int mannerLevel, Double mannerRank, int mannerRatingCount) {
return MannerResponse.builder()
.mannerLevel(mannerLevel)
.mannerRank(mannerRank)
.mannerRatingCount(mannerRatingCount)
.mannerKeywords(mannerKeywords)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
Expand Down Expand Up @@ -119,14 +120,14 @@ public MannerRatingResponse getMannerRating(Member member, Long targetMemberId,
}

/**
* ν•΄λ‹Ή νšŒμ›μ˜ λ§€λ„ˆ 정보 쑰회 facade λ©”μ†Œλ“œ
* ν•΄λ‹Ή νšŒμ›μ˜ λ§€λ„ˆ 레벨 정보 쑰회 facade λ©”μ†Œλ“œ
*
* @param memberId νšŒμ› id
* @return MannerResponse
*/
public MannerResponse getMannerInfo(Long memberId) {
public MannerResponse getMannerLevelInfo(Long memberId) {
Member member = memberService.findMemberById(memberId);

// λ§€λ„ˆ 레벨 쑰회
int mannerLevel = member.getMannerLevel();

Expand All @@ -136,14 +137,26 @@ public MannerResponse getMannerInfo(Long memberId) {
// λ§€λ„ˆ 평가 개수 쑰회
int mannerRatingCount = mannerService.countMannerRatingByMember(member, true);

return MannerResponse.of(mannerLevel, mannerRank, mannerRatingCount);
}

/**
* ν•΄λ‹Ή νšŒμ›μ˜ λ§€λ„ˆ ν‚€μ›Œλ“œλ³„ 받은 개수 정보 쑰회 facade λ©”μ†Œλ“œ
*
* @param memberId νšŒμ› id
* @return MannerKewordListResponse
*/
public MannerKeywordListResponse getMannerKeywordInfo(Long memberId) {
Member member = memberService.findMemberById(memberId);

// λ§€λ„ˆ ν‚€μ›Œλ“œλ³„ 받은 개수 쑰회
Map<Long, Integer> mannerKeywordMap = mannerService.countMannerKeyword(member);

List<MannerKeywordResponse> mannerKeywordResponses = mannerKeywordMap.entrySet().stream()
.map(entry -> MannerKeywordResponse.of(entry.getKey(), entry.getValue()))
.toList();

return MannerResponse.of(mannerLevel, mannerRank, mannerRatingCount, mannerKeywordResponses);
return MannerKeywordListResponse.of(mannerKeywordResponses);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerUpdateResponse;
Expand Down Expand Up @@ -353,21 +354,37 @@ void getNegativeMannerRatingInfoSucceeds() throws Exception {
.andExpect(jsonPath("$.data.mannerKeywordIdList").isArray());
}

@DisplayName("νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 정보 쑰회")
@DisplayName("νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ 레벨 정보 쑰회")
@Test
void getMannerInfoSucceeds() throws Exception {
void getMannerLevelInfoSucceeds() throws Exception {
// given
MannerResponse response = MannerResponse.of(1, 50.0, 2, List.of());
MannerResponse response = MannerResponse.of(1, 50.0, 2);

given(mannerFacadeService.getMannerInfo(TARGET_MEMBER_ID)).willReturn(response);
given(mannerFacadeService.getMannerLevelInfo(TARGET_MEMBER_ID)).willReturn(response);

// when // then
mockMvc.perform(get(API_URL_PREFIX + "/{memberId}", TARGET_MEMBER_ID))
mockMvc.perform(get(API_URL_PREFIX + "/level/{memberId}", TARGET_MEMBER_ID))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("OK"))
.andExpect(jsonPath("$.data.mannerLevel").value(1))
.andExpect(jsonPath("$.data.mannerRank").value(50.0))
.andExpect(jsonPath("$.data.mannerRatingCount").value(2))
.andExpect(jsonPath("$.data.mannerRatingCount").value(2));
}

@DisplayName("νŠΉμ • νšŒμ›μ˜ λ§€λ„ˆ ν‚€μ›Œλ“œ 정보 쑰회")
@Test
void getMannerKeywordInfoSucceeds() throws Exception {
// given
MannerKeywordListResponse response = MannerKeywordListResponse.builder()
.mannerKeywords(List.of())
.build();

given(mannerFacadeService.getMannerKeywordInfo(TARGET_MEMBER_ID)).willReturn(response);

// when // then
mockMvc.perform(get(API_URL_PREFIX + "/keyword/{memberId}", TARGET_MEMBER_ID))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("OK"))
.andExpect(jsonPath("$.data.mannerKeywords").isArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerUpdateResponse;
Expand Down Expand Up @@ -443,6 +444,7 @@ void insertNegativeMannerRatingSucceedsWhenMannerLevelDown() {
eq(NotificationTypeTitle.MANNER_LEVEL_DOWN), any(Member.class), eq(1));
});
}

}

@Nested
Expand Down Expand Up @@ -806,6 +808,7 @@ void updateMannerRatingSucceedsWhenNegativeKeyword() {
verify(notificationService, times(0)).createMannerLevelNotification(any(), any(Member.class), any());
});
}

}

@Nested
Expand Down Expand Up @@ -884,17 +887,18 @@ void getMannerRatingSucceedsWhenNegativeNotExist() {
assertThat(response.getMannerRatingId()).isNull();
assertThat(response.getMannerKeywordIdList()).isEmpty();
}

}

@Nested
@DisplayName("νšŒμ› λ§€λ„ˆ 정보 쑰회")
class GetMannerInfoTest {
@DisplayName("νšŒμ› λ§€λ„ˆ 레벨 정보 쑰회")
class GetMannerLevelInfoTest {

@DisplayName("μ‹€νŒ¨: λŒ€μƒ νšŒμ›μ„ 찾을 수 μ—†λŠ” 경우 μ˜ˆμ™Έκ°€ λ°œμƒν•œλ‹€.")
@Test
void getMannerInfo_shouldThrownWhenMemberNotFound() {
// when // then
assertThatThrownBy(() -> mannerFacadeService.getMannerInfo(1000L))
assertThatThrownBy(() -> mannerFacadeService.getMannerLevelInfo(1000L))
.isInstanceOf(MemberException.class)
.hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage());
}
Expand All @@ -903,16 +907,12 @@ void getMannerInfo_shouldThrownWhenMemberNotFound() {
@Test
void getMannerInfoSucceedsWhenNoMannerRating() {
// when
MannerResponse response = mannerFacadeService.getMannerInfo(member.getId());
MannerResponse response = mannerFacadeService.getMannerLevelInfo(member.getId());

// then
assertThat(response.getMannerLevel()).isEqualTo(1);
assertThat(response.getMannerRank()).isNull();
assertThat(response.getMannerRatingCount()).isEqualTo(0);
assertThat(response.getMannerKeywords())
.isNotNull()
.hasSize(12)
.allSatisfy(mannerKeywordResponse -> assertThat(mannerKeywordResponse.getCount()).isEqualTo(0));
}

@DisplayName("성곡: 받은 λ§€λ„ˆ 평가가 μžˆλŠ” 경우")
Expand All @@ -932,13 +932,63 @@ void getMannerInfoSucceeds() {
memberRepository.save(member);

// when
MannerResponse response = mannerFacadeService.getMannerInfo(member.getId());
MannerResponse response = mannerFacadeService.getMannerLevelInfo(member.getId());

// then
assertThat(response.getMannerLevel()).isEqualTo(1);
assertThat(response.getMannerRank()).isEqualTo(50.0);
assertThat(response.getMannerRatingCount()).isEqualTo(2);
}

}

@Nested
@DisplayName("νšŒμ› λ§€λ„ˆ ν‚€μ›Œλ“œ 정보 쑰회")
class GetMannerKeywordInfoTest {

@DisplayName("μ‹€νŒ¨: λŒ€μƒ νšŒμ›μ„ 찾을 수 μ—†λŠ” 경우 μ˜ˆμ™Έκ°€ λ°œμƒν•œλ‹€.")
@Test
void getMannerKeywordInfo_shouldThrownWhenMemberNotFound() {
// when // then
assertThatThrownBy(() -> mannerFacadeService.getMannerKeywordInfo(1000L))
.isInstanceOf(MemberException.class)
.hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage());
}

@DisplayName("성곡: 받은 λ§€λ„ˆ 평가가 μ—†λŠ” 경우")
@Test
void getMannerKeywordInfoSucceedsWhenNoMannerRating() {
// when
MannerKeywordListResponse response = mannerFacadeService.getMannerKeywordInfo(member.getId());

// then
assertThat(response.getMannerKeywords())
.isNotNull()
.hasSize(12)
.allSatisfy(mannerKeywordResponse ->
assertThat(mannerKeywordResponse.getCount()).isEqualTo(0));
}

@DisplayName("성곡: 받은 λ§€λ„ˆ 평가가 μžˆλŠ” 경우")
@Test
void getMannerKeywordInfoSucceeds() {
// given
Member targetMember1 = createMember("[email protected]", "targetMember1");
Member targetMember2 = createMember("[email protected]", "targetMember2");
Member targetMember3 = createMember("[email protected]", "targetMember3");

createMannerRating(List.of(1L, 2L, 3L, 4L, 5L, 6L), targetMember1, member, true);
createMannerRating(List.of(1L, 2L, 3L), targetMember2, member, true);
createMannerRating(List.of(7L, 8L), targetMember3, member, false);

member.updateMannerScore(5);
member.updateMannerRank(50.0);
memberRepository.save(member);

// when
MannerKeywordListResponse response = mannerFacadeService.getMannerKeywordInfo(member.getId());

// then
Map<Long, Integer> assertMap = new HashMap<>();
assertMap.put(1L, 2);
assertMap.put(2L, 2);
Expand Down

0 comments on commit 9257322

Please sign in to comment.