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

강의 관련 메서드 전체적으로 수정 + 월별/연도별 그래프 데이터 조회 기능 추가 #193

Merged
merged 15 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
337b5fd
♻️ 코드 수정 : commentService 메서드명 수정으로 인해 리팩터링
JoJeHuni Nov 15, 2024
9a5e00b
♻️ 코드 수정 : CommentController 자료형 수정, PathVariable 수정
JoJeHuni Nov 15, 2024
bf5d3c2
♻️ 코드 수정 : CommentService 자료형 수정, 반환 데이터 수정
JoJeHuni Nov 15, 2024
90bcf38
✨ 기능 추가 : 계약 과정 전체 조회 기능 추가
JoJeHuni Nov 15, 2024
73956ef
✨ 기능 추가 : 계약 과정 서비스 - 전체 조회 기능 추가
JoJeHuni Nov 15, 2024
a90233f
♻️ 코드 수정 : 계약 과정 리포지토리 - 자료형 수정
JoJeHuni Nov 15, 2024
bdc809c
♻️ 코드 수정 : lectureCode 자료형 수정
JoJeHuni Nov 15, 2024
b7f4ea4
✨ 기능 추가 : lectureService - 클릭 수 증가 메서드, 월별/연도별 강의 개수 데이터 구하는 메서드 추가 및…
JoJeHuni Nov 15, 2024
635bb5d
✨ 기능 추가 : 월별/연도별 강의 개수 데이터를 위한 DTO 추가
JoJeHuni Nov 15, 2024
fef062f
✨ 기능 추가 : 퍼사드 수정
JoJeHuni Nov 15, 2024
5c81a23
✨ 기능 추가 : 매퍼 수정 - 수정 시 필요한 데이터만 가지고 update하기 위해
JoJeHuni Nov 15, 2024
9904662
✨ 기능 추가 : 강의 추가, 수정 시 메서드 수정 및 월별/연도별 컨트롤러 코드 추가
JoJeHuni Nov 15, 2024
cce7c77
✨ 기능 수정 : 강의 별 강의 카테고리 저장하는 메서드 수정
JoJeHuni Nov 15, 2024
06fe1c6
♻️ 코드 수정 : 불필요한 주석 삭제
JoJeHuni Nov 15, 2024
e94c19a
Merge branch 'develop' of https://github.com/LearnsMate/LearnsMateBac…
JoJeHuni Nov 15, 2024
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 @@ -40,10 +40,7 @@ public class BlacklistService {

// 1. flag는 볼필요 없음. -> 학생, 강사만 구분해야함.
public List<BlacklistDTO> findAllBlacklistByMemberType(MemberType memberType) {

List<BlacklistDTO> blacklistDTOList = blacklistRepository.findAllBlacklistByMemberType(memberType);

return blacklistDTOList;
return blacklistRepository.findAllBlacklistByMemberType(memberType);
}

// 1. 멤버 타입에 따라 신고내역 횟수 뒤져서 찾기 reportService.findCount
Expand Down Expand Up @@ -72,8 +69,8 @@ public List<BlacklistReportCommentDTO> findBlacklistReportComment(Long memberCod

// 2. ReportDTO의 comment_code 내역 가져오기 -> comment table
List<CommentDTO> commentDTOList = reportDTOlist.stream()
.map(reportDTO -> commentService.findComentByCommentCode(reportDTO.getCommentCode()))
.collect(Collectors.toList());
.map(reportDTO -> commentService.findCommentByCommentCode(reportDTO.getCommentCode()))
.toList();

// 3. List<BlacklistReportCommentDTO> 생성 및 데이터 추가
List<BlacklistReportCommentDTO> blacklistReportCommentDTOList = new ArrayList<>();
Expand Down Expand Up @@ -111,10 +108,8 @@ public void addMemberToBlacklist(BlacklistDTO dto) {
public List<BlacklistDTO> filterBlacklistMember(BlacklistFilterRequestDTO dto){
List<Blacklist> blacklistList = blacklistRepository.searchBy(dto);

List<BlacklistDTO> blacklistDTOList = blacklistList.stream()
return blacklistList.stream()
.map(blacklistMapper::fromBlacklistToBlacklistDTO)
.collect(Collectors.toList());

return blacklistDTOList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public ResponseEntity<List<ResponseFindCommentVO>> findAllComments() {
}

@Operation(summary = "댓글 단건 조회")
@GetMapping("/{commentcode}")
public ResponseEntity<ResponseFindCommentVO> findCommentByCommentCode(@PathVariable("commentcode") Long commentCode) {
CommentDTO commentDTO = commentService.findComentByCommentCode(commentCode);
@GetMapping("/{commentCode}")
public ResponseEntity<ResponseFindCommentVO> findCommentByCommentCode(@PathVariable("commentCode") Long commentCode) {
CommentDTO commentDTO = commentService.findCommentByCommentCode(commentCode);

return ResponseEntity.status(HttpStatus.OK)
.body(commentMapper.fromCommentDTOToResponseFindCommentVO(commentDTO));
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<ResponseFindCommentVO> findCommentByCommentCode(@PathVaria

@Operation(summary = "강의별 댓글 조회")
@GetMapping("/lecture/{lectureCode}")
public ResponseEntity<List<ResponseFindCommentVO>> findCommentByLectureCode(@PathVariable("lectureCode") Long lectureCode ) {
public ResponseEntity<List<ResponseFindCommentVO>> findCommentByLectureCode(@PathVariable("lectureCode") String lectureCode ) {
List<CommentDTO> commentDTOList = commentService.findCommentByLectureCode(lectureCode);

return ResponseEntity.status(HttpStatus.OK).body(commentDTOList.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public class CommentDTO {
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private Long memberCode;
private Long lectureCode;
private String lectureCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public class ResponseFindCommentVO {
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private Long memberCode;
private Long lectureCode;
private String lectureCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
public interface CommentService {
List<CommentDTO> findAllComments();

CommentDTO findComentByCommentCode(Long commentCode);
CommentDTO findCommentByCommentCode(Long commentCode);

// 강의별 댓글 1개 조회
List<CommentDTO> findCommentByLectureCode(Long lectureCode);
List<CommentDTO> findCommentByLectureCode(String lectureCode);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package intbyte4.learnsmate.comment.service;


import intbyte4.learnsmate.comment.domain.dto.CommentDTO;
import intbyte4.learnsmate.comment.domain.entity.Comment;
import intbyte4.learnsmate.comment.mapper.CommentMapper;
Expand Down Expand Up @@ -34,9 +33,7 @@ public class CommentServiceImpl implements CommentService {
private final MemberMapper memberMapper;

@Override
// 모든 댓글 조회
public List<CommentDTO> findAllComments() {
// 1. repo에 있는 모든 데이터 조회하면 됨.
List<Comment> commentList = commentRepository.findAll();

return commentList.stream()
Expand All @@ -45,22 +42,20 @@ public List<CommentDTO> findAllComments() {
}

@Override
// 댓글 1개 조회
public CommentDTO findComentByCommentCode(Long commentCode) {
public CommentDTO findCommentByCommentCode(Long commentCode) {
Comment comment = commentRepository.findById(commentCode)
.orElseThrow(() -> new CommonException(StatusEnum.COMMENT_NOT_FOUND));

return commentMapper.fromCommentToCommentDTO(comment);
}

@Override
// 강의별 댓글 1개 조회
public List<CommentDTO> findCommentByLectureCode(Long lectureCode) {
public List<CommentDTO> findCommentByLectureCode(String lectureCode) {
LectureDTO lectureDTO = lectureService.getLectureById(lectureCode);

MemberDTO studentDTO = memberService.findMemberByMemberCode(lectureDTO.getLectureCode(), MemberType.STUDENT);
Member member = memberMapper.fromMemberDTOtoMember(studentDTO);
Lecture lecture = lectureMapper.toEntity(lectureDTO,member);
MemberDTO tutorDTO = memberService.findMemberByMemberCode(lectureDTO.getTutorCode(), MemberType.TUTOR);
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);
Lecture lecture = lectureMapper.toEntity(lectureDTO, tutor);

List<Comment> commentList = commentRepository.findByLecture(lecture);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/contractprocess")
@RequestMapping("/contract-process")
@Slf4j
@RequiredArgsConstructor
public class ContractProcessController {

private final ContractProcessService contractProcessService;
private final ContractProcessMapper contractProcessMapper;

@Operation(summary = "계약과정 전체 조회")
@GetMapping("list")
public ResponseEntity<List<ResponseFindContractProcessVO>> listContractProcess() {
List<ContractProcessDTO> contractProcessDTOList = contractProcessService.findAll();
List<ResponseFindContractProcessVO> response = new ArrayList<>();
for (ContractProcessDTO contractProcessDTO : contractProcessDTOList) {
ResponseFindContractProcessVO responseVO = contractProcessMapper.fromDtoToResponseVO(contractProcessDTO);
response.add(responseVO);
}
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@Operation(summary = "계약과정코드로 계약과정 단건 조회")
@GetMapping("/{contractProcessCode}")
public ResponseEntity<ResponseFindContractProcessVO> getContractProcess(@PathVariable("contractProcessCode") Long contractProcessCode) {
Expand All @@ -31,19 +46,16 @@ public ResponseEntity<ResponseFindContractProcessVO> getContractProcess(@PathVar

@Operation(summary = "강의별 계약과정 조회")
@GetMapping("/lecture/{lectureCode}")
public ResponseEntity<ResponseFindContractProcessVO> getApprovalProcessByLectureCode(
@PathVariable("lectureCode") Long lectureCode) {
public ResponseEntity<ResponseFindContractProcessVO> getApprovalProcessByLectureCode(@PathVariable("lectureCode") String lectureCode) {
ContractProcessDTO contractProcessDTO = contractProcessService.getApprovalProcessByLectureCode(lectureCode);
return ResponseEntity.status(HttpStatus.OK).body(contractProcessMapper.fromDtoToResponseVO(contractProcessDTO));
}


@Operation(summary = "강의별 계약과정 등록")
@PutMapping("/lecture/{lectureCode}")
@PostMapping("/lecture-approve/{lectureCode}")
public ResponseEntity<ResponseRegisterContractProcessVO> createContractProcessByLecture(
@PathVariable("lectureCode") Long lectureCode, @RequestBody RequestRegisterContractProcessVO requestVO) {
@PathVariable("lectureCode") String lectureCode, @RequestBody RequestRegisterContractProcessVO requestVO) {
ContractProcessDTO contractProcessDTO = contractProcessService.createContractProcess(lectureCode,contractProcessMapper.fromRegisterRequestVOtoDto(requestVO));
return ResponseEntity.status(HttpStatus.CREATED).body(contractProcessMapper.fromDtoToRegisterResponseVO(contractProcessDTO));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class ContractProcessDTO {
private Integer approvalProcess;
private LocalDateTime createdAt;
private String note;
private Long lectureCode;
private String lectureCode;
private Long adminCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class ResponseRegisterContractProcessVO {
private Integer approvalProcess;
private LocalDateTime createdAt;
private String note;
private Long lectureCode;
private String lectureCode;
private Long adminCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class RequestRegisterContractProcessVO {
private Integer approvalProcess;
private LocalDateTime createdAt;
private String note;
private Long lectureCode;
private String lectureCode;
private Long adminCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class ResponseFindContractProcessVO {
private Integer approvalProcess;
private LocalDateTime createdAt;
private String note;
private Long lectureCode;
private String lectureCode;
private Long adminCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public interface ContractProcessRepository extends JpaRepository<ContractProcess

Optional<ContractProcess> findByLectureAndApprovalProcess(Lecture lecture, Integer approvalProcess);

long countByLecture(Lecture lecture);
int countByLecture(Lecture lecture);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import intbyte4.learnsmate.contractprocess.domain.dto.ContractProcessDTO;

import java.util.List;

public interface ContractProcessService {
// 단건 조회
ContractProcessDTO getContractProcess(Long contractProcessCode);

// 강의별 승인과정 절차 조회
ContractProcessDTO getApprovalProcessByLectureCode(Long lectureCode);
ContractProcessDTO getApprovalProcessByLectureCode(String lectureCode);

// 계약과정 등록
ContractProcessDTO createContractProcess(Long lectureCode, ContractProcessDTO contractProcessDTO);
ContractProcessDTO createContractProcess(String lectureCode, ContractProcessDTO contractProcessDTO);

List<ContractProcessDTO> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


@Service
Expand All @@ -38,22 +40,18 @@ public class ContractProcessServiceImpl implements ContractProcessService {
private final LectureService lectureService;
private final LectureMapper lectureMapper;


// 단건 조회
@Override
public ContractProcessDTO getContractProcess(Long contractProcessCode) {
ContractProcess contractProcess = contractProcessRepository.findById(contractProcessCode)
.orElseThrow(() -> new CommonException(StatusEnum.CONTRACT_PROCESS_NOT_FOUND));
return contractProcessMapper.toDTO(contractProcess);
}


// 강의별 승인과정 절차 조회
@Override
public ContractProcessDTO getApprovalProcessByLectureCode(Long lectureCode) {
public ContractProcessDTO getApprovalProcessByLectureCode(String lectureCode) {
LectureDTO lecturedto = lectureService.getLectureById(lectureCode);

MemberDTO tutorDTO = memberService.findMemberByMemberCode(lecturedto.getLectureCode(), MemberType.TUTOR);
MemberDTO tutorDTO = memberService.findMemberByMemberCode(lecturedto.getTutorCode(), MemberType.TUTOR);
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);

Lecture lecture = lectureMapper.toEntity(lecturedto, tutor);
Expand All @@ -67,12 +65,9 @@ public ContractProcessDTO getApprovalProcessByLectureCode(Long lectureCode) {
return contractProcessMapper.toDTO(contractProcess);
}



// 계약과정 등록
@Transactional
@Override
public ContractProcessDTO createContractProcess(Long lectureCode, ContractProcessDTO contractProcessDTO) {
public ContractProcessDTO createContractProcess(String lectureCode, ContractProcessDTO contractProcessDTO) {
LectureDTO lectureDTO = lectureService.getLectureById(lectureCode);
MemberDTO tutorDTO = memberService.findMemberByMemberCode(lectureDTO.getTutorCode(), MemberType.TUTOR);
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);
Expand All @@ -82,12 +77,10 @@ public ContractProcessDTO createContractProcess(Long lectureCode, ContractProces
AdminDTO adminDTO = adminService.findByAdminCode(contractProcessDTO.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);

// 강의별 계약과정 ApprovalProcess이 같은 강의 코드와 같은 ApprovalProcess의 값이 존재하는지 확인
ContractProcess existingContractProcess = contractProcessRepository
.findByLectureAndApprovalProcess(lecture, contractProcessDTO.getApprovalProcess())
.orElse(null);

// 이미 존재하는 계약과정이 있으면 예외 처리
if (existingContractProcess != null) {
throw new CommonException(StatusEnum.EXISTING_CONTRACT_PROCESS);
}
Expand All @@ -102,16 +95,23 @@ public ContractProcessDTO createContractProcess(Long lectureCode, ContractProces

contractProcessRepository.save(contractProcess);

long contractProcessCount = contractProcessRepository.countByLecture(lecture);
int contractProcessCount = contractProcessRepository.countByLecture(lecture);
LectureDTO lecturedto = lectureMapper.toDTO(lecture);

// 계약과정이 7개일 경우 강의 승인 상태 변경
if (contractProcessCount == 7) {
lectureService.updateLectureConfirmStatus(lecturedto.getLectureCode());
}

return contractProcessMapper.toDTO(contractProcess);
}


@Override
public List<ContractProcessDTO> findAll() {
List<ContractProcess> contractProcessList = contractProcessRepository.findAll();
List<ContractProcessDTO> contractProcessDTOList = new ArrayList<>();
for (ContractProcess contractProcess : contractProcessList) {
contractProcessDTOList.add(contractProcessMapper.toDTO(contractProcess));
}
return contractProcessDTOList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ResponseEntity<CouponRegisterResponseVO> createCoupon(@RequestBody AdminC

@Operation(summary = "강사 - 쿠폰 등록")
@PostMapping("/tutor/register")
public ResponseEntity<CouponRegisterResponseVO> createCoupon(@RequestBody TutorCouponRegisterRequestVO request, Member tutor, CouponCategory couponCategory, Long lectureCode) {
public ResponseEntity<CouponRegisterResponseVO> createCoupon(@RequestBody TutorCouponRegisterRequestVO request, Member tutor, CouponCategory couponCategory, String lectureCode) {
CouponDTO couponDTO = couponFacade.tutorRegisterCoupon(request, tutor, couponCategory, lectureCode);
return ResponseEntity.status(HttpStatus.CREATED).body(couponMapper.fromDTOToRegisterResponseVO(couponDTO));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CouponFacade {
private final LectureMapper lectureMapper;

@Transactional
public CouponDTO tutorRegisterCoupon(TutorCouponRegisterRequestVO request, Member tutor, CouponCategory couponCategory, Long lectureCode) {
public CouponDTO tutorRegisterCoupon(TutorCouponRegisterRequestVO request, Member tutor, CouponCategory couponCategory, String lectureCode) {
CouponEntity newCouponEntity = couponMapper.newCouponEntity(request, tutor, couponCategory);

LectureDTO lectureDTO = lectureService.getLectureById(lectureCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
public class CouponByLectureDTO {
private Long couponByLectureCode;
private Long couponCode;
private Long lectureCode;
private String lectureCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class CouponByLectureFindResponseVO {
private Long couponCode;

@JsonProperty("lecture_code")
private Long lectureCode;
private String lectureCode;

}
Loading