Skip to content

Commit

Permalink
Merge pull request #193 from LearnsMate/feature/lecture
Browse files Browse the repository at this point in the history
강의 관련 메서드 전체적으로 수정 + 월별/연도별 그래프 데이터 조회 기능 추가
  • Loading branch information
YuJeeun authored Nov 15, 2024
2 parents f3d1c70 + e94c19a commit 4fa1837
Show file tree
Hide file tree
Showing 55 changed files with 254 additions and 331 deletions.
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

0 comments on commit 4fa1837

Please sign in to comment.