Skip to content

Commit

Permalink
refactor : 프론트 요청에 따른 알림 내역 API Slice -> Page 객체로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LHS-11 committed Jan 1, 2024
1 parent b826168 commit 7d771b6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.cmc.zenefitserver.domain.policy.api;

import com.cmc.zenefitserver.domain.policy.application.PolicyLogoClassifier;
import com.cmc.zenefitserver.domain.policy.application.PolicyMethodClassifier;
import com.cmc.zenefitserver.domain.policy.application.PolicyService;
import com.cmc.zenefitserver.domain.policy.application.PolicySupportContentClassifier;
import com.cmc.zenefitserver.domain.policy.domain.enums.SearchDateType;
import com.cmc.zenefitserver.domain.policy.dto.*;
import com.cmc.zenefitserver.domain.user.domain.User;
Expand All @@ -27,6 +30,9 @@
public class PolicyController {

private final PolicyService policyService;
private final PolicyLogoClassifier policyLogoClassifier;
private final PolicySupportContentClassifier supportContentClassifier;
private final PolicyMethodClassifier policyMethodClassifier;

// 정책 리스트 조회 API
@PostMapping
Expand Down Expand Up @@ -81,4 +87,48 @@ public CommonResponse<PolicyCountResponseDto> getRecommend(@AuthUser User user)
PolicyCountResponseDto result = policyService.getRecommendCountAndNickname(user);
return CommonResponse.success(result);
}

@GetMapping("/test")
public void go() {

policyLogoClassifier.saveLogo();
// try {
// policyDateClassifier.go();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }

}

@GetMapping("/test1")
public void go1() {
supportContentClassifier.getSupportContent();
// System.setProperty("python.import.site", "false");
// pythonInterpreter = new PythonInterpreter();
// pythonInterpreter.execfile("/Users/supsup/Downloads/1. content/predict_content2.py");
// pythonInterpreter.exec("print(predict_content)");
// PyFunction pyFunction = pythonInterpreter.get("predict_content", PyFunction.class);
// PyObject pyObject = pyFunction.__call__(new PyString("전문강사 1:1 컨설팅\n" +
// "AI/VR 체험권\n" +
// "이미지메이킹\n" +
// "(퍼스널컬러진단)\n" +
// "면접정장대여"));
// System.out.println("pyObject = " + pyObject.toString());
}

@GetMapping("/test2")
public void go2() {
policyMethodClassifier.classify();
// System.setProperty("python.import.site", "false");
// pythonInterpreter = new PythonInterpreter();
// pythonInterpreter.execfile("/Users/supsup/Downloads/1. content/predict_content2.py");
// pythonInterpreter.exec("print(predict_content)");
// PyFunction pyFunction = pythonInterpreter.get("predict_content", PyFunction.class);
// PyObject pyObject = pyFunction.__call__(new PyString("전문강사 1:1 컨설팅\n" +
// "AI/VR 체험권\n" +
// "이미지메이킹\n" +
// "(퍼스널컬러진단)\n" +
// "면접정장대여"));
// System.out.println("pyObject = " + pyObject.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/notify")
Expand All @@ -27,9 +24,10 @@ public class NotificationController {

@GetMapping
@Operation(summary = "유저의 알림 내역 조회 API", description = "유저의 알림 내역을 조회합니다.")
public CommonResponse<Slice<NotificationListInfoResponseDto>> findAllNotification(@AuthUser User user, @RequestParam Long lastNotificationId, Pageable pageable){
public CommonResponse<Slice<NotificationListInfoResponseDto>> findAllNotification(@AuthUser User user, @RequestParam int page, @RequestParam int size) {
log.info("알림 내역 조회 API, user = {}", user.getUserId());
return CommonResponse.success(notificationService.findAllNotification(user,lastNotificationId,pageable));
// Sort sort = Sort.by(Sort.Direction.fromString(sortOrder), sortField);
return CommonResponse.success(notificationService.findAllNotification(user, page, size));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.cmc.zenefitserver.domain.user.domain.User;
import com.cmc.zenefitserver.global.infra.notification.dao.NotificationQueryRepository;
import com.cmc.zenefitserver.global.infra.notification.dao.NotificationRepository;
import com.cmc.zenefitserver.global.infra.notification.domain.Notification;
import com.cmc.zenefitserver.global.infra.notification.dto.NotificationListInfoResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;

Expand All @@ -17,8 +16,9 @@ public class NotificationService {
private final NotificationRepository notificationRepository;
private final NotificationQueryRepository notificationQueryRepository;

public Slice<NotificationListInfoResponseDto> findAllNotification(User user,Long lastNotificationId , Pageable pageable){
return notificationQueryRepository.searchNotificationBySlice(user,lastNotificationId, pageable);
public Slice<NotificationListInfoResponseDto> findAllNotification(User user, int page, int size) {
PageRequest pageable = PageRequest.of(page, size);
return notificationQueryRepository.searchNotificationBySlice(user, pageable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import com.cmc.zenefitserver.global.infra.notification.dto.NotificationListInfoResponseDto;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.cmc.zenefitserver.domain.policy.domain.QPolicy.policy;
import static com.cmc.zenefitserver.domain.userpolicy.domain.QUserPolicy.userPolicy;
import static com.cmc.zenefitserver.global.infra.notification.domain.QNotification.notification;

@RequiredArgsConstructor
Expand All @@ -23,8 +25,8 @@ public class NotificationQueryRepository {

private final JPAQueryFactory jpaQueryFactory;

public Slice<NotificationListInfoResponseDto> searchNotificationBySlice(User user, Long lastNotificationId, Pageable pageable) {
List<NotificationListInfoResponseDto> results = jpaQueryFactory.select(
public Page<NotificationListInfoResponseDto> searchNotificationBySlice(User user, Pageable pageable) {
JPAQuery<NotificationListInfoResponseDto> query = jpaQueryFactory.select(
Projections.constructor(NotificationListInfoResponseDto.class,
notification.id,
notification.title,
Expand All @@ -34,14 +36,16 @@ public Slice<NotificationListInfoResponseDto> searchNotificationBySlice(User use
)
.from(notification)
.where(
ltNotificationId(lastNotificationId),
userPolicy.user.userId.eq(user.getUserId())
)
.orderBy(userPolicy.policy.id.desc())
notification.user.userId.eq(user.getUserId())
);

List<NotificationListInfoResponseDto> results = query.orderBy(notification.createdDate.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1)
.fetch();

return checkLastPage(pageable, results);
// return checkLastPage(pageable, results);
return PageableExecutionUtils.getPage(results, pageable, query::fetchCount);
}

private BooleanExpression ltNotificationId(Long policyId) {
Expand Down

0 comments on commit 7d771b6

Please sign in to comment.