diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/admin/Admin.java b/src/main/java/com/jasik/momsnaggingapi/domain/admin/Admin.java index 4b8b962..94fb031 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/admin/Admin.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/admin/Admin.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import org.springframework.data.domain.Page; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; @@ -40,4 +41,28 @@ public static class DashBoardResponse { private ServiceData service; private GradeData grade; } + + @Schema(description = "문의 조회 시 응답 클래스") + @Getter @Setter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class QuestionResponse { + + @Schema(description = "문의사항 id", defaultValue = "1") + private Long id; + + @Schema(description = "문의 제목", defaultValue = "문의있습니다") + private String title; + + @Schema(description = "문의 내용", defaultValue = "있었는데 없습니다.") + private String context; + + @Schema(description = "사용자 id", defaultValue = "") + private String userId; + + @Schema(description = "문의 작성 일시", defaultValue = "2022-05-08 12:00:00") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private LocalDateTime createdAt; + } } diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/admin/controller/AdminController.java b/src/main/java/com/jasik/momsnaggingapi/domain/admin/controller/AdminController.java index e774518..f7145ed 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/admin/controller/AdminController.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/admin/controller/AdminController.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.data.repository.query.Param; import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -59,22 +60,38 @@ public ResponseEntity getAdmin() { @GetMapping("/users") @Operation(summary = "회원 정보 전체 가져오기", description = "관리자에서 보여줄 유저 리스트를 조회합니다.") public ResponseEntity> getAllUsers( - @PageableDefault(size=10, sort="id", direction = Sort.Direction.ASC) Pageable pageable + @Parameter(description = "페이지 정보 \n\n page - 페이지 번호. 0부터 시작 \n\n " + + "size - default 10으로 설정. 다를 경우에만 전송 \n\n " + + "sort - 해당 칼럼 오름차순 정렬. default id 이므로 다를 경우에만 전송" + + "(ex. a 칼럼으로 오름차순 정렬 - [\"a\"], 내림차순 정렬 - [\"a,DESC\"]") + @PageableDefault(size=10, sort="id", direction = Sort.Direction.ASC) Pageable pageable, + @Parameter(required = false, description = "검색할 아이디") + @RequestParam(value = "search", required = false) String search ) { - return ResponseEntity.ok().body(adminService.getUsers(pageable)); + return ResponseEntity.ok().body(adminService.getUsers(pageable, search)); } @GetMapping("/questions") @Operation(summary = "문의사항 전체 가져오기", description = "관리자에서 보여줄 문의사항 리스트를 조회합니다.") - public ResponseEntity> getAllQuestions( - @PageableDefault(size=10, sort="id", direction = Sort.Direction.ASC) Pageable pageable + public ResponseEntity> getAllQuestions( + @Parameter(description = "페이지 정보 \n\n page - 페이지 번호. 0부터 시작 \n\n " + + "size - default 10으로 설정. 다를 경우에만 전송 \n\n " + + "sort - 해당 칼럼 오름차순 정렬. default id 이므로 다를 경우에만 전송" + + "(ex. a 칼럼으로 오름차순 정렬 - [\"a\"], 내림차순 정렬 - [\"a,DESC\"]") + @PageableDefault(size=10, sort="id", direction = Sort.Direction.ASC) Pageable pageable, + @Parameter(required = false, description = "검색할 아이디") + @RequestParam(value = "search", required = false) String search ) { - return ResponseEntity.ok().body(adminService.getQuestions(pageable)); + return ResponseEntity.ok().body(adminService.getQuestions(pageable, search)); } @GetMapping("/sign-out") @Operation(summary = "탈퇴사유 전체 가져오기", description = "관리자에서 보여줄 탈퇴사유 리스트를 조회합니다.") public ResponseEntity> getAllSignOutReasons( + @Parameter(description = "페이지 정보 \n\n page - 페이지 번호. 0부터 시작 \n\n " + + "size - default 10으로 설정. 다를 경우에만 전송 \n\n " + + "sort - 해당 칼럼 오름차순 정렬. default id 이므로 다를 경우에만 전송 " + + "(ex. a 칼럼으로 오름차순 정렬 - [\"a\"], 내림차순 정렬 - [\"a,DESC\"])") @PageableDefault(size=10, sort="id", direction = Sort.Direction.ASC) Pageable pageable ) { return ResponseEntity.ok().body(adminService.getSignOutReasons(pageable)); diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/admin/service/AdminService.java b/src/main/java/com/jasik/momsnaggingapi/domain/admin/service/AdminService.java index 262307e..a5c5215 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/admin/service/AdminService.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/admin/service/AdminService.java @@ -7,6 +7,7 @@ import com.jasik.momsnaggingapi.domain.push.Push; import com.jasik.momsnaggingapi.domain.push.Push.PushType; import com.jasik.momsnaggingapi.domain.push.service.PushService; +import com.jasik.momsnaggingapi.domain.question.Interface.QuestionUserInterface; import com.jasik.momsnaggingapi.domain.question.Question; import com.jasik.momsnaggingapi.domain.question.service.QuestionService; import com.jasik.momsnaggingapi.domain.schedule.Interface.ScheduleNaggingInterface; @@ -66,8 +67,8 @@ public Admin.GradeData getGradeData() { return gradeData; } - public Page getUsers(Pageable pageable) { - Page userPage = userService.findAllUsers(pageable); + public Page getUsers(Pageable pageable, String search) { + Page userPage = userService.findAllUsers(pageable, search); Page userDataList = userPage.map(m -> User.AdminResponse.builder() .id(m.getId()) .provider(m.getProvider()) @@ -90,14 +91,15 @@ public Page getSignOutReasons(Pageable pageable) .build()); } - public Page getQuestions(Pageable pageable) { - Page questionPage = questionService.findAllQuestions(pageable); - return questionPage.map(q -> Question.QuestionResponse.builder() - .id(q.getId()) - .title(q.getTitle()) - .context(q.getContext()) - .createdAt(q.getCreatedAt()) - .userId(q.getUserId()) // TODO: userId -> personalId 값으로 변경 + public Page getQuestions(Pageable pageable, String search) { + Page questionPage = questionService.findAllQuestions(pageable, search); + + return questionPage.map(q -> Admin.QuestionResponse.builder() + .id(q.getQuestion().getId()) + .title(q.getQuestion().getTitle()) + .context(q.getQuestion().getContext()) + .createdAt(q.getQuestion().getCreatedAt()) + .userId(q.getUser().getPersonalId()) .build()); } diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/question/Interface/QuestionUserInterface.java b/src/main/java/com/jasik/momsnaggingapi/domain/question/Interface/QuestionUserInterface.java new file mode 100644 index 0000000..ba5bfda --- /dev/null +++ b/src/main/java/com/jasik/momsnaggingapi/domain/question/Interface/QuestionUserInterface.java @@ -0,0 +1,9 @@ +package com.jasik.momsnaggingapi.domain.question.Interface; + +import com.jasik.momsnaggingapi.domain.question.Question; +import com.jasik.momsnaggingapi.domain.user.User; + +public interface QuestionUserInterface { + Question getQuestion(); + User getUser(); +} diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/question/repository/QuestionRepository.java b/src/main/java/com/jasik/momsnaggingapi/domain/question/repository/QuestionRepository.java index 36abe2f..dea55e9 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/question/repository/QuestionRepository.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/question/repository/QuestionRepository.java @@ -1,13 +1,23 @@ package com.jasik.momsnaggingapi.domain.question.repository; +import com.jasik.momsnaggingapi.domain.question.Interface.QuestionUserInterface; import com.jasik.momsnaggingapi.domain.question.Question; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; import java.util.List; public interface QuestionRepository extends JpaRepository { + @Transactional + @Query("select q as question, u as user from Question q inner join User u " + + "on q.userId = u.id " + + "where (:personalId is null or u.personalId LIKE %:personalId%) and q.isQ = :isQ") + Page findAllQuestions(@Param("personalId") String personalId, @Param("isQ") boolean isQ, Pageable pageable); + Page findAllByIsQ(boolean isQ, Pageable pageable); Long countByIsQ(boolean isQ); diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/question/service/QuestionService.java b/src/main/java/com/jasik/momsnaggingapi/domain/question/service/QuestionService.java index b0d224b..2bead31 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/question/service/QuestionService.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/question/service/QuestionService.java @@ -1,19 +1,10 @@ package com.jasik.momsnaggingapi.domain.question.service; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.jasik.momsnaggingapi.domain.diary.Diary; -import com.jasik.momsnaggingapi.domain.diary.Diary.DiaryResponse; +import com.jasik.momsnaggingapi.domain.question.Interface.QuestionUserInterface; import com.jasik.momsnaggingapi.domain.question.Question; -import com.jasik.momsnaggingapi.domain.question.Question.QuestionResponse; import com.jasik.momsnaggingapi.domain.question.repository.QuestionRepository; -import com.jasik.momsnaggingapi.domain.schedule.Schedule; -import java.time.LocalDate; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import com.jasik.momsnaggingapi.domain.user.User; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.modelmapper.ModelMapper; @@ -59,8 +50,8 @@ public Long countAllQuestions() { } @Transactional - public Page findAllQuestions(Pageable pageable) { - return questionRepository.findAllByIsQ(true, pageable); + public Page findAllQuestions(Pageable pageable, String search) { + return questionRepository.findAllQuestions(search, true, pageable); } @Transactional diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/user/repository/UserRepository.java b/src/main/java/com/jasik/momsnaggingapi/domain/user/repository/UserRepository.java index 978eec6..e0e37b5 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/user/repository/UserRepository.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/user/repository/UserRepository.java @@ -1,13 +1,15 @@ package com.jasik.momsnaggingapi.domain.user.repository; import com.jasik.momsnaggingapi.domain.user.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import java.awt.print.Pageable; import java.util.Optional; public interface UserRepository extends JpaRepository { Optional findByPersonalId(String personalId); Optional findByProviderCode(String ProviderCode); Optional findByProviderCodeAndProvider(String providerCode, String provider); + Page findByPersonalIdContainingIgnoreCase(String personalId, Pageable pageable); } diff --git a/src/main/java/com/jasik/momsnaggingapi/domain/user/service/UserService.java b/src/main/java/com/jasik/momsnaggingapi/domain/user/service/UserService.java index 0d6a167..15b8132 100644 --- a/src/main/java/com/jasik/momsnaggingapi/domain/user/service/UserService.java +++ b/src/main/java/com/jasik/momsnaggingapi/domain/user/service/UserService.java @@ -38,8 +38,8 @@ public User.UserResponse findUser(Long id) { return modelMapper.map(user, User.UserResponse.class); } - public Page findAllUsers(Pageable pageable) { - return userRepository.findAll(pageable); + public Page findAllUsers(Pageable pageable, String search) { + return userRepository.findByPersonalIdContainingIgnoreCase(search, pageable); } @Transactional