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

♻️ 코드 수정: PaymentService -> lecturePayment 수정 #189

Merged
merged 6 commits into from
Nov 14, 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 @@ -62,29 +62,42 @@ public class LectureFacade {
private final AdminMapper adminMapper;

@Transactional
public LectureDTO discountLecturePrice(LectureDTO lectureDTO, IssueCouponDTO issueCouponDTO) {
MemberDTO tutorDTO = memberService.findById(lectureDTO.getTutorCode());
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);

Lecture lecture = lectureMapper.toEntity(lectureDTO, tutor);

MemberDTO studentDTO = memberService.findById(issueCouponDTO.getStudentCode());
Member student = memberMapper.fromMemberDTOtoMember(studentDTO);

CouponDTO couponDTO = couponService.findCouponDTOByCouponCode(issueCouponDTO.getCouponCode());
// 쿠폰카테고리디티오로 반환하는게 필요
CouponCategory couponCategory = couponCategoryService.findByCouponCategoryCode(couponDTO.getCouponCategoryCode());

AdminDTO adminDTO = adminService.findByAdminCode(couponDTO.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);
CouponEntity coupon = couponMapper.toEntity(couponDTO,couponCategory,admin,tutor);

CouponByLectureDTO couponByLectureDTO = couponByLectureService.findByCouponAndLecture(lecture, coupon);
if(couponByLectureDTO == null) return lectureDTO;
lectureDTO.setLecturePrice(lectureDTO.getLecturePrice() * (1 - couponDTO.getCouponDiscountRate() / 100));
return lectureDTO;
public List<LectureDTO> discountLecturePrice(List<LectureDTO> lectureDTOList, List<IssueCouponDTO> issueCouponDTOList) {
return lectureDTOList.stream()
.map(lectureDTO -> {
MemberDTO memberDTO = new MemberDTO();
memberDTO.setMemberCode(lectureDTO.getTutorCode());
Member tutor = memberMapper.fromMemberDTOtoMember(memberDTO);
Lecture lecture = lectureMapper.toEntity(lectureDTO, tutor);

IssueCouponDTO matchedCoupon = issueCouponDTOList.stream()
.filter(issueCouponDTO -> {
CouponDTO couponDTO = couponService.findCouponDTOByCouponCode(issueCouponDTO.getCouponCode());
CouponCategory couponCategory = couponCategoryService.findByCouponCategoryCode(couponDTO.getCouponCategoryCode());

AdminDTO adminDTO = adminService.findByAdminCode(couponDTO.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);

MemberDTO tutorDTO = memberService.findMemberByMemberCode(couponDTO.getTutorCode(), MemberType.TUTOR);
Member tutorEntity = memberMapper.fromMemberDTOtoMember(tutorDTO);

CouponEntity couponEntity = couponMapper.toEntity(couponDTO, couponCategory, admin, tutorEntity);
CouponByLectureDTO couponByLectureDTO = couponByLectureService.findByCouponAndLecture(lecture, couponEntity);
return couponByLectureDTO != null;
})
.findFirst()
.orElse(null);

if (matchedCoupon != null) {
CouponDTO couponDTO = couponService.findCouponDTOByCouponCode(matchedCoupon.getCouponCode());
lectureDTO.setLecturePrice(lectureDTO.getLecturePrice() * (1 - couponDTO.getCouponDiscountRate() / 100));
}
return lectureDTO;
})
.toList();
}


@Transactional
public LectureDTO removeLecture(Long lectureCode) {
Lecture lecture = lectureRepository.findById(lectureCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import intbyte4.learnsmate.payment.service.PaymentServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.apache.coyote.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -60,8 +59,9 @@ public ResponseEntity<ResponseFindPaymentVO> getPaymentDetails(@PathVariable("pa
@PostMapping("/register")
public ResponseEntity<List<ResponseRegisterPaymentVO>> registerPayment
(@RequestBody RequestRegisterPaymentVO requestRegisterPaymentVO) {
IssueCouponDTO issueCouponDTO = issueCouponMapper
.fromRequestRegisterIssueCouponPaymentVOToDTO(requestRegisterPaymentVO.getIssueCouponVO());
List<IssueCouponDTO> issueCouponDTOList = requestRegisterPaymentVO.getIssueCouponVOList().stream()
.map(issueCouponMapper::fromRequestRegisterIssueCouponPaymentVOToDTO)
.toList();

MemberDTO memberDTO = memberMapper
.fromRequestRegisterMemberPaymentVOToMemberDTO(requestRegisterPaymentVO.getMemberVO());
Expand All @@ -70,11 +70,9 @@ public ResponseEntity<ResponseFindPaymentVO> getPaymentDetails(@PathVariable("pa
.map(lectureMapper::fromRequestRegisterLecturePaymentVOToDTO)
.toList();

List<LectureDTO> lectures = lectureDTOList.stream()
.map(lectureDTO -> lectureFacade.discountLecturePrice(lectureDTO, issueCouponDTO))
.toList();
List<LectureDTO> lectures = lectureFacade.discountLecturePrice(lectureDTOList, issueCouponDTOList);

List<PaymentDTO> payments = paymentService.lecturePayment(memberDTO, lectures, issueCouponDTO);
List<PaymentDTO> payments = paymentService.lecturePayment(memberDTO, lectures, issueCouponDTOList);

List<ResponseRegisterPaymentVO> responseList = payments.stream()
.map(paymentMapper::fromPaymentDTOtoResponseRegisterPaymentVO)
Expand All @@ -83,6 +81,7 @@ public ResponseEntity<ResponseFindPaymentVO> getPaymentDetails(@PathVariable("pa
return ResponseEntity.ok(responseList);
}


@Operation(summary = "필터별 결제 내역 조회")
@GetMapping("/filter")
public ResponseEntity<List<PaymentFilterDTO>> getPaymentsByFilters(@RequestBody PaymentFilterRequestVO request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class RequestRegisterPaymentVO {
private RequestRegisterIssueCouponPaymentVO issueCouponVO;
private List<RequestRegisterIssueCouponPaymentVO> issueCouponVOList;
private RequestRegisterMemberPaymentVO memberVO;
private List<RequestRegisterLecturePaymentVO> LectureVOList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public interface PaymentService {
// 직원이 특정 결제 내역을 단건 상세 조회
PaymentDTO getPaymentDetails(Long paymentCode);

List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lectureDTOList, IssueCouponDTO issueCouponDTO);
List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lectureDTOList, List<IssueCouponDTO> issueCouponDTOList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public PaymentDTO getPaymentDetails(Long paymentCode) {
}

@Override
public List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lectureDTOList, IssueCouponDTO issueCouponDTO) {
public List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lectureDTOList, List<IssueCouponDTO> issueCouponDTOList) {
List<LectureByStudentDTO> lectureByStudentDTOList = new ArrayList<>();

Member student = memberMapper.fromMemberDTOtoMember(memberDTO);
Expand All @@ -106,43 +106,47 @@ public List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lec
lectureByStudentDTOList.add(lectureByStudentDTO);
});

CouponDTO couponDTO = couponService.findCouponDTOByCouponCode(issueCouponDTO.getCouponCode());
List<PaymentDTO> payments = new ArrayList<>();
for (IssueCouponDTO issueCouponDTO : issueCouponDTOList) {
CouponDTO couponDTO = couponService.findCouponDTOByCouponCode(issueCouponDTO.getCouponCode());

// 쿠폰카테고리DTO 반환하는 메서드 필요
CouponCategory couponCategory = couponCategoryService
.findByCouponCategoryCode(couponDTO.getCouponCategoryCode());
CouponCategory couponCategory = couponCategoryService
.findByCouponCategoryCode(couponDTO.getCouponCategoryCode());

AdminDTO adminDTO = adminService.findByAdminCode(couponDTO.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);
AdminDTO adminDTO = adminService.findByAdminCode(couponDTO.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);

MemberDTO tutorDTO = memberService.findMemberByMemberCode(couponDTO.getTutorCode(), memberDTO.getMemberType());
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);
MemberDTO tutorDTO = memberService.findMemberByMemberCode(couponDTO.getTutorCode(), memberDTO.getMemberType());
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);

CouponEntity coupon = couponMapper.toEntity(couponDTO, couponCategory, admin, tutor);
CouponEntity coupon = couponMapper.toEntity(couponDTO, couponCategory, admin, tutor);

lectureDTOList.forEach(lectureDTO -> {
Lecture lecture = lectureMapper.toEntity(lectureDTO, tutor);
LectureByStudentDTO lectureByStudentDTO = lectureByStudentService
.findByLectureAndStudent(lecture, student);
LectureByStudent lectureByStudent = lectureByStudentMapper
.toEntity(lectureByStudentDTO, lecture, student);

PaymentDTO paymentDTO = new PaymentDTO();
paymentDTO.setPaymentCode(null);
paymentDTO.setPaymentPrice(lectureDTO.getLecturePrice());
paymentDTO.setCreatedAt(LocalDateTime.now());
paymentDTO.setLectureByStudentCode(lectureByStudentService.findStudentCodeByLectureCode(lecture));

if (issueCouponDTO.getStudentCode().equals(lectureByStudentDTO.getStudent().getMemberCode())) {
paymentDTO.setCouponIssuanceCode(issueCouponDTO.getCouponIssuanceCode());
}

Payment payment = paymentMapper.toEntity(paymentDTO, lectureByStudent, issueCouponMapper
.toEntity(issueCouponDTO, student, coupon));

paymentRepository.save(payment);

payments.add(paymentDTO);
});
}

List<PaymentDTO> payments = new ArrayList<>();
lectureDTOList.forEach(lectureDTO -> {
Lecture lecture = lectureMapper.toEntity(lectureDTO, tutor);
LectureByStudentDTO lectureByStudentDTO = lectureByStudentService
.findByLectureAndStudent(lecture, student);
LectureByStudent lectureByStudent = lectureByStudentMapper
.toEntity(lectureByStudentDTO, lecture, student);

PaymentDTO paymentDTO = new PaymentDTO();
paymentDTO.setPaymentCode(null);
paymentDTO.setPaymentPrice(lectureDTO.getLecturePrice());
paymentDTO.setCreatedAt(LocalDateTime.now());
paymentDTO.setLectureByStudentCode(lectureByStudentService.findStudentCodeByLectureCode(lecture));
if (issueCouponDTO.getStudentCode().equals(lectureByStudentDTO.getStudent().getMemberCode()))
paymentDTO.setCouponIssuanceCode(issueCouponDTO.getCouponIssuanceCode());
paymentDTO.setCouponIssuanceCode(null);
Payment payment = paymentMapper.toEntity(paymentDTO, lectureByStudent, issueCouponMapper
.toEntity(issueCouponDTO, student, coupon));

paymentRepository.save(payment);

payments.add(paymentDTO);
});
lectureByStudentDTOList.forEach(lectureByStudentDTO -> {
LectureVideoByStudentDTO lectureVideoByStudentDTO = new LectureVideoByStudentDTO();
lectureVideoByStudentDTO.setVideoCode(null);
Expand All @@ -152,6 +156,7 @@ public List<PaymentDTO> lecturePayment(MemberDTO memberDTO, List<LectureDTO> lec

return payments;
}

// 직원이 예상 매출액과 할인 매출액을 비교해서 조회

// 직원이 기간 별 매출액을 리스트와 그래프로 조회
Expand Down