From 7eef6c1c0c0b5e0def908ecb68190a92f2b92e48 Mon Sep 17 00:00:00 2001 From: Hellin22 Date: Wed, 27 Nov 2024 17:27:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80:=20=EB=B8=94=EB=9E=99=EB=A6=AC=EC=8A=A4=ED=8A=B8=20ad?= =?UTF-8?q?min=20=EC=B0=BE=EC=95=84=EC=98=A4=EB=8A=94=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blacklist/service/BlacklistService.java | 32 +++++++++++++++++-- .../member/service/MemberFacade.java | 3 ++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java index b5391da5..5d69edc0 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java @@ -2,6 +2,7 @@ import intbyte4.learnsmate.admin.domain.dto.AdminDTO; import intbyte4.learnsmate.admin.domain.entity.Admin; +import intbyte4.learnsmate.admin.domain.entity.CustomUserDetails; import intbyte4.learnsmate.admin.mapper.AdminMapper; import intbyte4.learnsmate.admin.service.AdminService; import intbyte4.learnsmate.blacklist.domain.dto.*; @@ -23,10 +24,13 @@ import intbyte4.learnsmate.report.domain.dto.ReportedMemberDTO; import intbyte4.learnsmate.report.service.ReportService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -35,6 +39,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class BlacklistService { private final BlacklistRepository blacklistRepository; @@ -142,9 +147,8 @@ public void addMemberToBlacklist(BlacklistDTO dto) { MemberDTO memberDTO = memberService.findById(dto.getMemberCode()); Member member = memberMapper.fromMemberDTOtoMember(memberDTO); - // 2. admin을 찾아와야 하는데 나중에 token으로 처리 할듯? - AdminDTO adminDTO = adminService.findByAdminCode(202001001L); -// AdminDTO adminDTO = new AdminDTO(); + // 2. admin + AdminDTO adminDTO = adminService.findByAdminCode(getAdminCode()); Admin admin = adminMapper.toEntity(adminDTO); // 3. BlacklistDTO 생성 -> 이유만 있으면 됨. -> 이유도 넘겨받아야함. -> dto 자체를 넘겨받으면 해결 @@ -194,4 +198,26 @@ public List findAllByMemberTypeWithExcel(MemberType memberType){ .map(blacklistMapper::fromBlacklistToBlacklistDTO) .collect(Collectors.toList()); } + + public Long getAdminCode() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + if (authentication == null || authentication.getPrincipal() == null) { + throw new CommonException(StatusEnum.USER_NOT_FOUND); + } + + Object principal = authentication.getPrincipal(); + + if (principal instanceof String) { + throw new CommonException(StatusEnum.USER_NOT_FOUND); + } + + if (principal instanceof CustomUserDetails userDetails) { + log.info("Authentication: {}", authentication); + log.info("userDetails: {}", userDetails.toString()); + return userDetails.getUserDTO().getAdminCode(); + } + + throw new CommonException(StatusEnum.USER_NOT_FOUND); + } } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java b/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java index 9c0649d1..6473c6c4 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java @@ -1,5 +1,6 @@ package intbyte4.learnsmate.member.service; +import intbyte4.learnsmate.admin.domain.entity.CustomUserDetails; import intbyte4.learnsmate.common.exception.CommonException; import intbyte4.learnsmate.common.exception.StatusEnum; import intbyte4.learnsmate.issue_coupon.domain.dto.IssueCouponDTO; @@ -27,6 +28,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import java.time.LocalDateTime; From 2a07b2d1eab1a3c1e03bb1b680ad0b40533d74ec Mon Sep 17 00:00:00 2001 From: Hellin22 Date: Thu, 28 Nov 2024 09:25:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80:=20=EB=A9=A4=EB=B2=84=20=EC=83=81=EC=84=B8=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=B6=94=EC=B2=9C=EA=B0=95=EC=9D=98=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=97=90=EB=9F=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intbyte4/learnsmate/member/service/MemberFacade.java | 5 +++-- .../learnsmate/payment/service/PaymentServiceImpl.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java b/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java index 6473c6c4..3e6d2cfb 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/member/service/MemberFacade.java @@ -76,8 +76,9 @@ public FindSingleStudentDTO findStudentByStudentCode(Long studentCode) { List unansweredVOCByMemberList = vocService.findUnansweredVOCByMember(studentCode); List answeredVOCByMemberList = vocService.findAnsweredVOCByMember(studentCode); - // 강의 추천 로직 추가 + // 4. 강의 추천 로직 추가 String latestLectureCode = paymentService.findLatestLectureCodeByStudent(studentCode); + log.info("마지막 강의 코드: {}", latestLectureCode); List similarStudents = preferredTopicsService.findStudentsWithSimilarPreferredTopics(studentCode); log.info("비슷한 학생들은: {}", similarStudents); @@ -87,7 +88,7 @@ public FindSingleStudentDTO findStudentByStudentCode(Long studentCode) { if (!similarStudents.isEmpty()) { Pageable pageable = PageRequest.of(0, 3); // 상위 3개만 가져오기 List recommendedLectures = paymentService.findRecommendedLectures(similarStudents, latestLectureCode, studentCode, pageable); - + log.info("추천 강의들은: {}", recommendedLectures); recommendedLectureCodes = recommendedLectures.stream() .map(record -> (String) record[0]) .collect(Collectors.toList()); diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/payment/service/PaymentServiceImpl.java b/LearnsMate/src/main/java/intbyte4/learnsmate/payment/service/PaymentServiceImpl.java index 5a5a2824..96f12ab0 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/payment/service/PaymentServiceImpl.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/payment/service/PaymentServiceImpl.java @@ -33,6 +33,7 @@ import intbyte4.learnsmate.payment.mapper.PaymentMapper; import intbyte4.learnsmate.payment.repository.PaymentRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -43,6 +44,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class PaymentServiceImpl implements PaymentService { private final PaymentRepository paymentRepository; private final PaymentMapper paymentMapper; @@ -145,6 +147,7 @@ public String findLatestLectureCodeByStudent(Long studentCode) { @Override public List findRecommendedLectures(List similarStudents, String latestLectureCode, Long studentCode, Pageable pageable) { + log.info("{}{}{}", similarStudents, latestLectureCode, studentCode); return paymentRepository.findRecommendedLectures(similarStudents, latestLectureCode, studentCode, pageable); }