Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…kend into feature/config
  • Loading branch information
JoJeHuni committed Nov 14, 2024
2 parents 3adf7d5 + b6f196d commit ec760e1
Show file tree
Hide file tree
Showing 45 changed files with 711 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package intbyte4.learnsmate.campaign.repository;

import intbyte4.learnsmate.campaign.domain.dto.CampaignDTO;
import intbyte4.learnsmate.campaign.domain.entity.Campaign;

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

public interface CampaignRepositoryCustom {
List<Campaign> searchBy(Campaign campaign, LocalDateTime startDate, LocalDateTime endDate);
List<Campaign> searchBy(CampaignDTO campaignDTO, LocalDateTime startDate, LocalDateTime endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import intbyte4.learnsmate.campaign.domain.dto.CampaignDTO;
import intbyte4.learnsmate.campaign.domain.entity.Campaign;
import intbyte4.learnsmate.campaign.domain.entity.CampaignTypeEnum;
import intbyte4.learnsmate.campaign.domain.entity.QCampaign;
import intbyte4.learnsmate.common.exception.CommonException;
import intbyte4.learnsmate.common.exception.StatusEnum;
Expand All @@ -14,40 +16,40 @@
@RequiredArgsConstructor
public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final QCampaign qCampaign;
private final QCampaign qCampaign = QCampaign.campaign;

@Override
public List<Campaign> searchBy(Campaign campaign, LocalDateTime startDate, LocalDateTime endDate) {
public List<Campaign> searchBy(CampaignDTO campaignDTO, LocalDateTime startDate, LocalDateTime endDate) {

return queryFactory
.selectFrom(qCampaign)
.where(searchByType(campaign)
.and(searchByTitle(campaign))
.and(searchByPeriod(campaign, startDate, endDate))
.and(searchBySentStatus(campaign))
.and(searchByScheduledStatus(campaign))
.where(searchByType(campaignDTO)
.and(searchByTitle(campaignDTO))
.and(searchByPeriod(campaignDTO, startDate, endDate))
.and(searchBySentStatus(campaignDTO))
.and(searchByScheduledStatus(campaignDTO))
)
.fetch();
}

public BooleanBuilder searchByType(Campaign campaign) {
public BooleanBuilder searchByType(CampaignDTO campaignDTO) {
BooleanBuilder booleanBuilder = new BooleanBuilder();

if (campaign.getCampaignType() != null) {
booleanBuilder.and(qCampaign.campaignType.eq(campaign.getCampaignType()));
if (campaignDTO.getCampaignType() != null) {
booleanBuilder.and(qCampaign.campaignType.eq(CampaignTypeEnum.valueOf(campaignDTO.getCampaignType())));
}

return booleanBuilder;
}

public BooleanBuilder searchByTitle(Campaign campaign) {
public BooleanBuilder searchByTitle(CampaignDTO campaignDTO) {
BooleanBuilder booleanBuilder = new BooleanBuilder();

if (campaign.getCampaignTitle() == null) {
if (campaignDTO.getCampaignTitle() == null) {
return booleanBuilder;
}

String[] keywords = campaign.getCampaignTitle().split(" ");
String[] keywords = campaignDTO.getCampaignTitle().split(" ");
if (keywords.length < 2) {
throw new CommonException(StatusEnum.MINIMUM_KEYWORD_LENGTH_REQUIRED);
}
Expand All @@ -59,9 +61,9 @@ public BooleanBuilder searchByTitle(Campaign campaign) {
return booleanBuilder;
}

public BooleanBuilder searchByPeriod(Campaign campaign, LocalDateTime startDate, LocalDateTime endDate) {
public BooleanBuilder searchByPeriod(CampaignDTO campaignDTO, LocalDateTime startDate, LocalDateTime endDate) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (campaign.getCampaignSendDate() == null) return booleanBuilder;
if (campaignDTO.getCampaignSendDate() == null) return booleanBuilder;

if (startDate != null) {
booleanBuilder.and(qCampaign.campaignSendDate.goe(startDate));
Expand All @@ -74,18 +76,18 @@ public BooleanBuilder searchByPeriod(Campaign campaign, LocalDateTime startDate,
return booleanBuilder;
}

public BooleanBuilder searchBySentStatus(Campaign campaign) {
public BooleanBuilder searchBySentStatus(CampaignDTO campaignDTO) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (campaign.getCampaignSendDate() == null) return booleanBuilder;
if (campaignDTO.getCampaignSendDate() == null) return booleanBuilder;

booleanBuilder.and(qCampaign.campaignSendDate.loe(LocalDateTime.now()));

return booleanBuilder;
}

public BooleanBuilder searchByScheduledStatus(Campaign campaign) {
public BooleanBuilder searchByScheduledStatus(CampaignDTO campaignDTO) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (campaign.getCampaignSendDate() == null) return booleanBuilder;
if (campaignDTO.getCampaignSendDate() == null) return booleanBuilder;

booleanBuilder.and(qCampaign.campaignSendDate.goe(LocalDateTime.now()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,9 @@ public CampaignDTO findCampaign(CampaignDTO request) {
@Override
public List<CampaignDTO> findCampaignListByCondition
(CampaignDTO request, LocalDateTime startDate, LocalDateTime endDate) {
AdminDTO adminDTO = adminService.findByAdminCode(request.getAdminCode());
Admin admin = adminMapper.toEntity(adminDTO);

List<Campaign> campaign = campaignRepositoryCustom
.searchBy(campaignMapper.toEntity(request,admin), startDate, endDate);
.searchBy(request, startDate, endDate);

List<CampaignDTO> campaignDTOList = new ArrayList<>();
campaign.forEach(entity -> campaignDTOList.add(campaignMapper.toDTO(entity)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@
import intbyte4.learnsmate.comment.domain.vo.request.ResponseFindCommentVO;
import intbyte4.learnsmate.comment.mapper.CommentMapper;
import intbyte4.learnsmate.comment.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

private final CommentService commentService;
private final CommentMapper commentMapper;

@Autowired
public CommentController(CommentService commentService, CommentMapper commentMapper) {
this.commentService = commentService;
this.commentMapper = commentMapper;
}

// 1. comment 모두 조회 -> 사실 이게 우리쪽에서 comment를 봐야하는가? 봐야하지 않을까? 블랙리스트에서 어떤 코멘트가 신고먹었는지는?
@Operation(summary = "모든 댓글 조회")
@GetMapping
public ResponseEntity<List<ResponseFindCommentVO>> findAllComments() {
List<CommentDTO> commentDTOList = commentService.findAllComments();
Expand All @@ -38,12 +31,23 @@ public ResponseEntity<List<ResponseFindCommentVO>> findAllComments() {
.collect(Collectors.toList()));
}

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

return ResponseEntity.status(HttpStatus.OK)
.body(commentMapper.fromCommentDTOToResponseFindCommentVO(commentDTO));
}


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

return ResponseEntity.status(HttpStatus.OK).body(commentDTOList.stream()
.map(commentMapper::fromCommentDTOToResponseFindCommentVO)
.collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package intbyte4.learnsmate.comment.repository;

import intbyte4.learnsmate.comment.domain.entity.Comment;
import intbyte4.learnsmate.lecture.domain.entity.Lecture;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findByLecture(Lecture lecture);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ public interface CommentService {
List<CommentDTO> findAllComments();

CommentDTO findComentByCommentCode(Long commentCode);

// 강의별 댓글 1개 조회
List<CommentDTO> findCommentByLectureCode(Long lectureCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
import intbyte4.learnsmate.comment.repository.CommentRepository;
import intbyte4.learnsmate.common.exception.CommonException;
import intbyte4.learnsmate.common.exception.StatusEnum;
import intbyte4.learnsmate.lecture.domain.dto.LectureDTO;
import intbyte4.learnsmate.lecture.domain.entity.Lecture;
import intbyte4.learnsmate.lecture.mapper.LectureMapper;
import intbyte4.learnsmate.lecture.service.LectureService;
import intbyte4.learnsmate.member.domain.MemberType;
import intbyte4.learnsmate.member.domain.dto.MemberDTO;
import intbyte4.learnsmate.member.domain.entity.Member;
import intbyte4.learnsmate.member.mapper.MemberMapper;
import intbyte4.learnsmate.member.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -19,6 +28,10 @@ public class CommentServiceImpl implements CommentService {

private final CommentRepository commentRepository;
private final CommentMapper commentMapper;
private final LectureService lectureService;
private final LectureMapper lectureMapper;
private final MemberService memberService;
private final MemberMapper memberMapper;

@Override
// 모든 댓글 조회
Expand All @@ -39,4 +52,20 @@ public CommentDTO findComentByCommentCode(Long commentCode) {

return commentMapper.fromCommentToCommentDTO(comment);
}

@Override
// 강의별 댓글 1개 조회
public List<CommentDTO> findCommentByLectureCode(Long 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);

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

return commentList.stream()
.map(commentMapper::fromCommentToCommentDTO)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package intbyte4.learnsmate.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import intbyte4.learnsmate.campaign.domain.entity.QCampaign;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
Expand All @@ -17,7 +16,4 @@ public class QuerydslConfig {
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}

@Bean
public QCampaign qCampaign() { return QCampaign.campaign; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface ContractProcessRepository extends JpaRepository<ContractProcess
ContractProcess findByLecture(Lecture lecture);

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

long countByLecture(Lecture lecture);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package intbyte4.learnsmate.contractprocess.service;

import intbyte4.learnsmate.contractprocess.domain.dto.ContractProcessDTO;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ContractProcessService {
// 단건 조회
Expand All @@ -14,4 +11,5 @@ public interface ContractProcessService {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
import intbyte4.learnsmate.lecture.domain.entity.Lecture;
import intbyte4.learnsmate.lecture.mapper.LectureMapper;
import intbyte4.learnsmate.lecture.service.LectureService;
import intbyte4.learnsmate.lecture_category.domain.dto.LectureCategoryDTO;
import intbyte4.learnsmate.lecture_category.domain.entity.LectureCategory;
import intbyte4.learnsmate.lecture_category.mapper.LectureCategoryMapper;
import intbyte4.learnsmate.lecture_category.service.LectureCategoryService;
import intbyte4.learnsmate.member.domain.MemberType;
import intbyte4.learnsmate.member.domain.dto.MemberDTO;
import intbyte4.learnsmate.member.domain.entity.Member;
Expand All @@ -35,8 +31,6 @@
public class ContractProcessServiceImpl implements ContractProcessService {
private final ContractProcessRepository contractProcessRepository;
private final ContractProcessMapper contractProcessMapper;
private final LectureCategoryService lectureCategoryService;
private final LectureCategoryMapper lectureCategoryMapper;
private final AdminService adminService;
private final AdminMapper adminMapper;
private final MemberService memberService;
Expand All @@ -62,10 +56,6 @@ public ContractProcessDTO getApprovalProcessByLectureCode(Long lectureCode) {
MemberDTO tutorDTO = memberService.findMemberByMemberCode(lecturedto.getLectureCode(), MemberType.TUTOR);
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);

// LectureCategoryDTO lectureCategoryDTO = lectureCategoryService.findByLectureCategoryCode(lecturedto.getLectureCategoryCode());
// LectureCategory lectureCategory = lectureCategoryMapper.toEntity(lectureCategoryDTO);

// Lecture lecture = lectureMapper.toEntity(lecturedto, tutor, lectureCategory);
Lecture lecture = lectureMapper.toEntity(lecturedto, tutor);

ContractProcess contractProcess = contractProcessRepository.findByLecture(lecture);
Expand All @@ -87,10 +77,6 @@ public ContractProcessDTO createContractProcess(Long lectureCode, ContractProces
MemberDTO tutorDTO = memberService.findMemberByMemberCode(lectureDTO.getTutorCode(), MemberType.TUTOR);
Member tutor = memberMapper.fromMemberDTOtoMember(tutorDTO);

// LectureCategoryDTO lectureCategoryDTO = lectureCategoryService.findByLectureCategoryCode(lectureDTO.getLectureCategoryCode());
// LectureCategory category = lectureCategoryMapper.toEntity(lectureCategoryDTO);

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

AdminDTO adminDTO = adminService.findByAdminCode(contractProcessDTO.getAdminCode());
Expand All @@ -116,6 +102,14 @@ public ContractProcessDTO createContractProcess(Long lectureCode, ContractProces

contractProcessRepository.save(contractProcess);

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

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

return contractProcessMapper.toDTO(contractProcess);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import intbyte4.learnsmate.coupon.mapper.CouponMapper;
import intbyte4.learnsmate.coupon.service.CouponService;
import intbyte4.learnsmate.coupon_category.domain.CouponCategory;
import intbyte4.learnsmate.facade.CouponLectureFacade;
import intbyte4.learnsmate.coupon.service.CouponFacade;
import intbyte4.learnsmate.member.domain.entity.Member;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,7 +27,7 @@ public class CouponController {

private final CouponService couponService;
private final CouponMapper couponMapper;
private final CouponLectureFacade couponLectureFacade;
private final CouponFacade couponFacade;

@Operation(summary = "쿠폰 전체 조회")
@GetMapping("/coupons")
Expand Down Expand Up @@ -65,7 +65,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) {
CouponDTO couponDTO = couponLectureFacade.tutorRegisterCoupon(request, tutor, couponCategory, lectureCode);
CouponDTO couponDTO = couponFacade.tutorRegisterCoupon(request, tutor, couponCategory, lectureCode);
return ResponseEntity.status(HttpStatus.CREATED).body(couponMapper.fromDTOToRegisterResponseVO(couponDTO));
}

Expand Down
Loading

0 comments on commit ec760e1

Please sign in to comment.