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

Tht server 236 차단/신고/탈퇴 회원 목록 리스트 조회 api #251

Merged
merged 9 commits into from
Jul 30, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.tht.thtadmin.ui.user;

import com.tht.thtadmin.ui.user.response.UserDetailResponse;
import com.tht.thtadmin.ui.user.response.UserSimpleListResponse;
import com.tht.thtadmin.ui.user.response.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -31,4 +30,25 @@ public ResponseEntity<UserDetailResponse> getUser(@PathVariable(value = "user-uu
return ResponseEntity.ok(userManageUseCase.getUserDetail(userUuid));
}

@GetMapping("/users/block")
public ResponseEntity<Page<UserBlockResponse>> getBlockList(@PageableDefault(size = 100) Pageable pageable) {

final Page<UserBlockResponse> responses = userManageUseCase.getBlockUserList(pageable);
return ResponseEntity.ok(responses);
}

@GetMapping("/users/report")
public ResponseEntity<Page<UserReportResponse>> getUserReport(@PageableDefault(size = 100) Pageable pageable) {

final Page<UserReportResponse> responses = userManageUseCase.getReportUserList(pageable);
return ResponseEntity.ok(responses);
}

@GetMapping("/users/withdraw")
public ResponseEntity<Page<WithDrawUserResponse>> getWithDrawUser(@PageableDefault(size = 100) Pageable pageable) {

final Page<WithDrawUserResponse> responses = userManageUseCase.getWithDrawList(pageable);
return ResponseEntity.ok(responses);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.tht.thtadmin.ui.user;

import com.tht.domain.entity.block.UserBlockService;
import com.tht.domain.entity.block.dto.UserBlockDto;
import com.tht.domain.entity.report.dto.UserReportDto;
import com.tht.domain.entity.user.User;
import com.tht.domain.entity.user.service.UserDetailDto;
import com.tht.domain.entity.user.service.dto.UserDetailDto;
import com.tht.domain.entity.report.UserReportService;
import com.tht.domain.entity.user.service.UserService;
import com.tht.thtadmin.ui.user.response.UserDetailResponse;
import com.tht.thtadmin.ui.user.response.UserSimpleListResponse;
import com.tht.domain.entity.user.service.dto.WithDrawUserDto;
import com.tht.thtadmin.ui.user.response.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
Expand All @@ -20,6 +24,8 @@
public class UserManageUseCase {

private final UserService userService;
private final UserBlockService userBlockService;
private final UserReportService userReportService;

public Page<UserSimpleListResponse> getUserList(final String search, final Pageable pageable) {

Expand All @@ -44,4 +50,27 @@ public UserDetailResponse getUserDetail(final String userUuid) {
return UserDetailResponse.toResponse(dto);
}

public Page<UserBlockResponse> getBlockUserList(final Pageable pageable) {
final Page<UserBlockDto> blockList = userBlockService.getBlockList(pageable);
final List<UserBlockResponse> responses = blockList.getContent().stream().map(UserBlockResponse::ofDto).toList();

return new PageImpl<>(responses, pageable, blockList.getTotalElements());
}

public Page<UserReportResponse> getReportUserList(final Pageable pageable) {

final Page<UserReportDto> reportList = userReportService.getReportList(pageable);
final List<UserReportResponse> responses = reportList.getContent().stream().map(UserReportResponse::ofDto).toList();

return new PageImpl<>(responses, pageable, reportList.getTotalElements());
}

public Page<WithDrawUserResponse> getWithDrawList(final Pageable pageable) {

final Page<WithDrawUserDto> reportList = userService.getWithDrawUserLog(pageable);
final List<WithDrawUserResponse> responses = reportList.getContent().stream().map(WithDrawUserResponse::ofDto).toList();

return new PageImpl<>(responses, pageable, reportList.getTotalElements());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tht.thtadmin.ui.user.response;

import com.tht.domain.entity.block.dto.UserBlockDto;
import com.tht.enums.EntityState;
import com.tht.enums.user.Gender;

public record UserBlockResponse(
String userUuid,
String username,
Gender gender,
EntityState userStatus,
String currentBlockDate,
String blockedUserName
) {
public static UserBlockResponse ofDto(final UserBlockDto dto) {
return new UserBlockResponse(
dto.userUuid(),
dto.username(),
dto.gender(),
dto.userStatus(),
dto.currentBlockDate(),
dto.blockedUserName()
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.tht.domain.entity.user.UserAgreement;
import com.tht.domain.entity.user.UserProfilePhoto;
import com.tht.domain.entity.user.service.UserDetailDto;
import com.tht.domain.entity.user.service.dto.UserDetailDto;
import com.tht.enums.agreement.AgreementCategory;
import com.tht.enums.user.Gender;
import com.tht.enums.user.SNSType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.tht.thtadmin.ui.user.response;

import com.tht.domain.entity.report.dto.UserReportDto;
import com.tht.enums.EntityState;
import com.tht.enums.user.Gender;

public record UserReportResponse(
String userUuid,
String username,
Gender gender,
Gender preferGender,
String reportDate,
EntityState userStatus,
String reportedUserName,
String reason
) {
public static UserReportResponse ofDto(final UserReportDto dto) {
return new UserReportResponse(
dto.userUuid(),
dto.username(),
dto.gender(),
dto.preferGender(),
dto.reportDate(),
dto.userStatus(),
dto.reportedUserName(),
dto.reason()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tht.thtadmin.ui.user.response;

import com.tht.domain.entity.user.service.dto.WithDrawUserDto;
import com.tht.enums.EntityState;

public record WithDrawUserResponse(
String userUuid,
String username,
String reason,
String feedBack,
EntityState userStatus,
String requestDate
) {
public static WithDrawUserResponse ofDto(final WithDrawUserDto dto) {
return new WithDrawUserResponse(
dto.userUuid(),
dto.username(),
dto.reason(),
dto.feedBack(),
dto.userStatus(),
dto.requestDate()
);
}
}
172 changes: 147 additions & 25 deletions tht-admin/src/test/java/com/tht/thtadmin/docs/UserManageDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import com.tht.enums.user.UserReligion;
import com.tht.thtadmin.docs.config.ControllerTestConfig;
import com.tht.thtadmin.docs.config.WithCustomMockUser;
import com.tht.thtadmin.fixture.user.WithDrawUserResponseFixture;
import com.tht.thtadmin.fixture.user.UserBlockResponseFixture;
import com.tht.thtadmin.fixture.user.UserDetailResponseFixture;
import com.tht.thtadmin.fixture.user.UserReportResponseFixture;
import com.tht.thtadmin.fixture.user.UserSimpleListResponseFixture;
import com.tht.thtadmin.ui.user.UserManageController;
import com.tht.thtadmin.ui.user.UserManageUseCase;
import com.tht.thtadmin.ui.user.response.UserDetailResponse;
import com.tht.thtadmin.ui.user.response.UserSimpleListResponse;
import com.tht.thtadmin.ui.user.response.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -29,6 +31,7 @@

import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document;
import static com.epages.restdocs.apispec.ResourceDocumentation.resource;
import static com.tht.thtadmin.docs.config.DocsConst.getPagingFieldDescriptors;
import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
Expand Down Expand Up @@ -70,29 +73,12 @@ void getUsers() throws Exception {
parameterWithName("direction").optional().ignored().description("정렬 방식")
)
.responseFields(
fieldWithPath("content[].username").type(JsonFieldType.STRING).description("유저 이름"),
fieldWithPath("content[].userUuid").type(JsonFieldType.STRING).description("유저 고유 번호"),
fieldWithPath("content[].createdAt").type(JsonFieldType.STRING).description("생성 시간"),
fieldWithPath("content[].userSate").type(JsonFieldType.STRING).description("유저 활동 상태"),
fieldWithPath("pageable.sort.empty").description("정렬이 비어있는지 여부"),
fieldWithPath("pageable.sort.sorted").description("내용이 정렬되었는지 여부"),
fieldWithPath("pageable.sort.unsorted").description("내용이 정렬되지 않았는지 여부"),
fieldWithPath("pageable.offset").description("현재 페이지의 오프셋"),
fieldWithPath("pageable.pageNumber").description("현재 페이지 번호"),
fieldWithPath("pageable.pageSize").description("페이지당 항목 수"),
fieldWithPath("pageable.paged").description("페이지 매김이 활성화되었는지 여부"),
fieldWithPath("pageable.unpaged").description("페이지 매김이 비활성화되었는지 여부"),
fieldWithPath("last").description("마지막 페이지인지 여부"),
fieldWithPath("totalElements").description("전체 요소 수"),
fieldWithPath("totalPages").description("전체 페이지 수"),
fieldWithPath("first").description("첫 번째 페이지인지 여부"),
fieldWithPath("size").description("페이지 크기"),
fieldWithPath("number").description("현재 페이지 번호"),
fieldWithPath("sort.empty").description("정렬이 비어있는지 여부"),
fieldWithPath("sort.sorted").description("내용이 정렬되었는지 여부"),
fieldWithPath("sort.unsorted").description("내용이 정렬되지 않았는지 여부"),
fieldWithPath("numberOfElements").description("현재 페이지의 요소 수"),
fieldWithPath("empty").description("현재 페이지가 비어 있는지 여부")
getPagingFieldDescriptors(List.of(
fieldWithPath("content[].username").type(JsonFieldType.STRING).description("유저 이름"),
fieldWithPath("content[].userUuid").type(JsonFieldType.STRING).description("유저 고유 번호"),
fieldWithPath("content[].createdAt").type(JsonFieldType.STRING).description("생성 시간"),
fieldWithPath("content[].userSate").type(JsonFieldType.STRING).description("유저 활동 상태")
))
)
.responseSchema(Schema.schema("UserSimpleListResponse"))
.build())
Expand Down Expand Up @@ -158,4 +144,140 @@ void getUser() throws Exception {
)
);
}

@Test
@DisplayName("회원 차단 목록 리스트")
@WithCustomMockUser
void blockUsers() throws Exception {

UserBlockResponse response = UserBlockResponseFixture.make();
PageImpl<UserBlockResponse> page = new PageImpl<>(List.of(response), PageRequest.of(0, 10), 1);

when(userManageUseCase.getBlockUserList(any())).thenReturn(page);

//then
ResultActions resultActions = mockMvc.perform(
get("/users/block")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer {ACCESS_TOKEN}")
).andDo(document("회원 차단 목록 리스트",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.tag("회원 관리")
.description("회원 차단 목록 리스트")
.queryParameters(
parameterWithName("size").optional().description("페이지 사이즈"),
parameterWithName("page").optional().description("검색할 페이지"),
parameterWithName("sort").optional().ignored().description("정렬 타입"),
parameterWithName("direction").optional().ignored().description("정렬 방식")
)
.responseFields(
getPagingFieldDescriptors(List.of(
fieldWithPath("content[].username").type(JsonFieldType.STRING).description("유저 이름"),
fieldWithPath("content[].userUuid").type(JsonFieldType.STRING).description("유저 고유 번호"),
fieldWithPath("content[].currentBlockDate").type(JsonFieldType.STRING).description("가장 최근 차단 시간"),
fieldWithPath("content[].userStatus").type(JsonFieldType.STRING).description("유저 활동 상태"),
fieldWithPath("content[].gender").type(JsonFieldType.STRING).description("유저 성별"),
fieldWithPath("content[].blockedUserName").type(JsonFieldType.STRING).description("신고한 유저 이름")
))
)
.responseSchema(Schema.schema("UserBlockResponse"))
.build())
));

resultActions.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
@DisplayName("회원 신고 목록 리스트")
@WithCustomMockUser
void reportUsers() throws Exception {

UserReportResponse response = UserReportResponseFixture.make();
PageImpl<UserReportResponse> page = new PageImpl<>(List.of(response), PageRequest.of(0, 10), 1);

when(userManageUseCase.getReportUserList(any())).thenReturn(page);

//then
ResultActions resultActions = mockMvc.perform(
get("/users/report")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer {ACCESS_TOKEN}")
).andDo(document("회원 신고 목록 리스트",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.tag("회원 관리")
.description("회원 신고 목록 리스트")
.queryParameters(
parameterWithName("size").optional().description("페이지 사이즈"),
parameterWithName("page").optional().description("검색할 페이지"),
parameterWithName("sort").optional().ignored().description("정렬 타입"),
parameterWithName("direction").optional().ignored().description("정렬 방식")
)
.responseFields(getPagingFieldDescriptors(List.of(
fieldWithPath("content[].username").type(JsonFieldType.STRING).description("유저 이름"),
fieldWithPath("content[].userUuid").type(JsonFieldType.STRING).description("유저 고유 번호"),
fieldWithPath("content[].reportDate").type(JsonFieldType.STRING).description("가장 최근 신고당한 시간"),
fieldWithPath("content[].userStatus").type(JsonFieldType.STRING).description("유저 활동 상태"),
fieldWithPath("content[].gender").type(JsonFieldType.STRING).description("유저 성별"),
fieldWithPath("content[].preferGender").type(JsonFieldType.STRING).description("선호 성별"),
fieldWithPath("content[].reportedUserName").type(JsonFieldType.STRING).description("신고한 유저 이름"),
fieldWithPath("content[].reason").type(JsonFieldType.STRING).description("신고한 이유")
)))
.responseSchema(Schema.schema("UserBlockResponse"))
.build())
));

resultActions.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
@DisplayName("탈퇴 회원 목록 리스트")
@WithCustomMockUser
void getWithDrawUsers() throws Exception {

WithDrawUserResponse response = WithDrawUserResponseFixture.make();
PageImpl<WithDrawUserResponse> page = new PageImpl<>(List.of(response), PageRequest.of(0, 10), 1);

when(userManageUseCase.getWithDrawList(any())).thenReturn(page);

//then
ResultActions resultActions = mockMvc.perform(
get("/users/withdraw")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer {ACCESS_TOKEN}")
).andDo(document("탈퇴 요청 회원 목록 리스트",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.tag("회원 관리")
.description("회원 신고 목록 리스트")
.queryParameters(
parameterWithName("size").optional().description("페이지 사이즈"),
parameterWithName("page").optional().description("검색할 페이지"),
parameterWithName("sort").optional().ignored().description("정렬 타입"),
parameterWithName("direction").optional().ignored().description("정렬 방식")
)
.responseFields(getPagingFieldDescriptors(List.of(
fieldWithPath("content[].username").type(JsonFieldType.STRING).description("유저 이름"),
fieldWithPath("content[].userUuid").type(JsonFieldType.STRING).description("유저 고유 번호"),
fieldWithPath("content[].requestDate").type(JsonFieldType.STRING).description("탈퇴 요청 시간"),
fieldWithPath("content[].userStatus").type(JsonFieldType.STRING).description("유저 활동 상태"),
fieldWithPath("content[].feedBack").type(JsonFieldType.STRING).description("피드백"),
fieldWithPath("content[].reason").type(JsonFieldType.STRING).description("탈퇴 이유")
)))
.responseSchema(Schema.schema("UserBlockResponse"))
.build())
));

resultActions.andExpect(MockMvcResultMatchers.status().isOk());
}



}
Loading
Loading