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

✨기능 추가: 블랙리스트 admin 찾아오는 코드 추가 #273

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -35,6 +39,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class BlacklistService {

private final BlacklistRepository blacklistRepository;
Expand Down Expand Up @@ -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 자체를 넘겨받으면 해결
Expand Down Expand Up @@ -194,4 +198,26 @@ public List<BlacklistDTO> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -73,8 +76,9 @@ public FindSingleStudentDTO findStudentByStudentCode(Long studentCode) {
List<VOCDTO> unansweredVOCByMemberList = vocService.findUnansweredVOCByMember(studentCode);
List<VOCDTO> answeredVOCByMemberList = vocService.findAnsweredVOCByMember(studentCode);

// 강의 추천 로직 추가
// 4. 강의 추천 로직 추가
String latestLectureCode = paymentService.findLatestLectureCodeByStudent(studentCode);
log.info("마지막 강의 코드: {}", latestLectureCode);

List<Long> similarStudents = preferredTopicsService.findStudentsWithSimilarPreferredTopics(studentCode);
log.info("비슷한 학생들은: {}", similarStudents);
Expand All @@ -84,7 +88,7 @@ public FindSingleStudentDTO findStudentByStudentCode(Long studentCode) {
if (!similarStudents.isEmpty()) {
Pageable pageable = PageRequest.of(0, 3); // 상위 3개만 가져오기
List<Object[]> recommendedLectures = paymentService.findRecommendedLectures(similarStudents, latestLectureCode, studentCode, pageable);

log.info("추천 강의들은: {}", recommendedLectures);
recommendedLectureCodes = recommendedLectures.stream()
.map(record -> (String) record[0])
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +44,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class PaymentServiceImpl implements PaymentService {
private final PaymentRepository paymentRepository;
private final PaymentMapper paymentMapper;
Expand Down Expand Up @@ -145,6 +147,7 @@ public String findLatestLectureCodeByStudent(Long studentCode) {

@Override
public List<Object[]> findRecommendedLectures(List<Long> similarStudents, String latestLectureCode, Long studentCode, Pageable pageable) {
log.info("{}{}{}", similarStudents, latestLectureCode, studentCode);
return paymentRepository.findRecommendedLectures(similarStudents, latestLectureCode, studentCode, pageable);
}

Expand Down