Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…kend into feature/blacklist
  • Loading branch information
Hellin22 committed Nov 14, 2024
2 parents f3712c7 + d9d4d29 commit 942568e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 87 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ jobs:
server:
port: 5000
management:
endpoints:
web:
exposure:
include: health
endpoint:
health:
show-details: always
spring:
application:
name: learnsmate
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://\${RDS_HOSTNAME}:\${RDS_PORT}/\${RDS_DB_NAME}
Expand Down
2 changes: 1 addition & 1 deletion LearnsMate/.platform/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http {
}

upstream springboot {
server 127.0.0.1:5000;
server 127.0.0.1:8080;
keepalive 1024;
}

Expand Down
3 changes: 3 additions & 0 deletions LearnsMate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ dependencies {
// 엑셀 파일 처리를 위한 apache poi
implementation 'org.apache.poi:poi:5.2.3'
implementation 'org.apache.poi:poi-ooxml:5.2.3'

// EC2 인스턴스 헬스 체크를 위한 actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.named('test') {
Expand Down
2 changes: 1 addition & 1 deletion LearnsMate/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package intbyte4.learnsmate.lecture.domain.vo.response;
package intbyte4.learnsmate.lecture.domain.dto;

import intbyte4.learnsmate.lecture.enums.LectureLevelEnum;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResponseLectureFilterRequestVO {
public class LectureFilterDTO {
private Long lectureCode; // 강의 코드
private String lectureTitle; // 강의명
private Long tutorCode; // 강사 코드
private String tutorName; // 강사 명
private String tutorName; // 강사명
private String lectureCategory; // 강의 카테고리
private LectureLevelEnum lectureLevel; // 강의 난이도
private Boolean lectureConfirmStatus; // 강의 계약 상태
private Boolean lectureStatus; // 강의 상태
private Integer minPrice; // 최소 금액
private Integer maxPrice; // 최대 금액
private LocalDateTime startCreatedAt; // 강의 생성일 시작
private LocalDateTime endCreatedAt; // 강의 생성일 끝
private Integer price; // 금액
private LocalDateTime createdAt; // 강의 생성일
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package intbyte4.learnsmate.lecture.domain.vo.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import intbyte4.learnsmate.lecture.enums.LectureLevelEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class RequestLectureFilterVO {
private Long lectureCode; // 강의 코드
private String lectureTitle; // 강의명
private Long tutorCode; // 강사 코드
private String tutorName; // 강사명
private String lectureCategoryName; // 강의 카테고리
private LectureLevelEnum lectureLevel; // 강의 난이도
private Boolean lectureConfirmStatus; // 강의 계약 상태
private Boolean lectureStatus; // 강의 상태
private Integer minPrice; // 최소 금액
private Integer maxPrice; // 최대 금액
private LocalDateTime startCreatedAt; // 강의 생성일 시작
private LocalDateTime endCreatedAt; // 강의 생성일 끝
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package intbyte4.learnsmate.lecture.repository;

import intbyte4.learnsmate.lecture.domain.dto.LectureFilterDTO;
import intbyte4.learnsmate.lecture.domain.entity.Lecture;
import intbyte4.learnsmate.lecture.domain.vo.response.ResponseLectureFilterRequestVO;
import intbyte4.learnsmate.lecture.domain.vo.request.RequestLectureFilterVO;

import java.util.List;

public interface CustomLectureRepository {
List<Lecture> findLecturesByFilters(ResponseLectureFilterRequestVO request);
List<LectureFilterDTO> findLecturesByFilters(RequestLectureFilterVO request);
}
Original file line number Diff line number Diff line change
@@ -1,123 +1,158 @@
package intbyte4.learnsmate.lecture.repository;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import intbyte4.learnsmate.lecture.domain.entity.Lecture;
import intbyte4.learnsmate.lecture.domain.dto.LectureFilterDTO;
import intbyte4.learnsmate.lecture.domain.entity.QLecture;
import intbyte4.learnsmate.lecture.domain.vo.response.ResponseLectureFilterRequestVO;
import intbyte4.learnsmate.lecture.domain.vo.request.RequestLectureFilterVO;
import intbyte4.learnsmate.lecture_category.domain.entity.QLectureCategory;
import intbyte4.learnsmate.lecture_category_by_lecture.domain.entity.QLectureCategoryByLecture;
import lombok.RequiredArgsConstructor;
import jakarta.persistence.EntityManager;
import org.springframework.stereotype.Repository;

import java.util.List;

import static intbyte4.learnsmate.lecture_category.domain.entity.QLectureCategory.lectureCategory;

@Repository
@RequiredArgsConstructor
public class CustomLectureRepositoryImpl implements CustomLectureRepository {

private final JPAQueryFactory queryFactory;
private final QLecture lecture = QLecture.lecture;
private final QLectureCategoryByLecture lectureCategoryByLecture = QLectureCategoryByLecture.lectureCategoryByLecture;

public CustomLectureRepositoryImpl(EntityManager entityManager) {
this.queryFactory = new JPAQueryFactory(entityManager);
}

@Override
public List<Lecture> findLecturesByFilters(ResponseLectureFilterRequestVO request) {
public List<LectureFilterDTO> findLecturesByFilters(RequestLectureFilterVO request) {
QLecture lecture = QLecture.lecture;
QLectureCategory lectureCategory = QLectureCategory.lectureCategory;
QLectureCategoryByLecture lectureCategoryByLecture = QLectureCategoryByLecture.lectureCategoryByLecture;

BooleanBuilder builder = new BooleanBuilder()
.and(eqLectureCode(request))
.and(likeLectureTitle(request))
.and(eqTutorCode(request))
.and(eqTutorName(request))
.and(eqLectureCategoryName(request))
.and(eqLectureLevel(request))
.and(eqLectureConfirmStatus(request))
.and(eqLectureStatus(request))
.and(betweenLecturePrice(request))
.and(betweenCreatedAt(request));

return queryFactory
.selectFrom(lecture)
.where(
filterByLectureCode(request),
filterByLectureTitle(request),
filterByTutorCode(request),
filterByTutorName(request),
filterByLectureCategory(request),
filterByLectureLevel(request),
filterByLectureConfirmStatus(request),
filterByLectureStatus(request),
filterByPriceRange(request),
filterByCreationDate(request)
)
.select(Projections.constructor(
LectureFilterDTO.class,
lecture.lectureCode,
lecture.lectureTitle,
lecture.tutor.memberCode,
lecture.tutor.memberName,
lectureCategory.lectureCategoryName,
lecture.lectureLevel,
lecture.lectureConfirmStatus,
lecture.lectureStatus,
lecture.lecturePrice,
lecture.createdAt
))
.from(lecture)
.join(lectureCategoryByLecture).on(lectureCategoryByLecture.lecture.eq(lecture))
.join(lectureCategoryByLecture.lectureCategory, lectureCategory)
.where(builder)
.fetch();
}

private BooleanBuilder filterByLectureCode(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureCode() != null) {
builder.and(lecture.lectureCode.eq(request.getLectureCode()));
private BooleanExpression eqLectureCode(RequestLectureFilterVO request) {

if (request.getLectureCode() == null) {
return null;
}
return builder;
return QLecture.lecture.lectureCode.eq(request.getLectureCode());
}

private BooleanBuilder filterByLectureTitle(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureTitle() != null) {
builder.and(lecture.lectureTitle.likeIgnoreCase("%" + request.getLectureTitle() + "%"));
private BooleanExpression likeLectureTitle(RequestLectureFilterVO request) {

if (request.getLectureTitle() == null) {
return null;
}
return builder;
return QLecture.lecture.lectureTitle.likeIgnoreCase("%" + request.getLectureTitle() + "%");
}

private BooleanBuilder filterByTutorCode(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getTutorCode() != null) {
builder.and(lecture.tutor.memberCode.eq(request.getTutorCode()));
private BooleanExpression eqTutorCode(RequestLectureFilterVO request) {

if (request.getTutorCode() == null) {
return null;
}
return builder;
return QLecture.lecture.tutor.memberCode.eq(request.getTutorCode());
}

private BooleanBuilder filterByTutorName(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getTutorName() != null) {
builder.and(lecture.tutor.memberName.likeIgnoreCase("%" + request.getTutorName() + "%"));
private BooleanExpression eqTutorName(RequestLectureFilterVO request) {

if (request.getTutorName() == null) {
return null;
}
return builder;
return QLecture.lecture.tutor.memberName.eq(request.getTutorName());
}

private BooleanBuilder filterByLectureCategory(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureCategory() != null) {
builder.and(lectureCategoryByLecture.lectureCategory.lectureCategoryName.eq(request.getLectureCategory()));
private BooleanExpression eqLectureCategoryName(RequestLectureFilterVO request) {

if (request.getLectureCategoryName() == null) {
return null;
}
return builder;
return lectureCategory.lectureCategoryName.eq(request.getLectureCategoryName());
}

private BooleanBuilder filterByLectureLevel(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureLevel() != null) {
builder.and(lecture.lectureLevel.eq(request.getLectureLevel()));
private BooleanExpression eqLectureLevel(RequestLectureFilterVO request) {

if (request.getLectureLevel() == null) {
return null;
}
return builder;
return QLecture.lecture.lectureLevel.eq(request.getLectureLevel());
}

private BooleanBuilder filterByLectureConfirmStatus(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureConfirmStatus() != null) {
builder.and(lecture.lectureConfirmStatus.eq(request.getLectureConfirmStatus()));
private BooleanExpression eqLectureConfirmStatus(RequestLectureFilterVO request) {

if (request.getLectureConfirmStatus() == null) {
return null;
}
return builder;
return QLecture.lecture.lectureConfirmStatus.eq(request.getLectureConfirmStatus());
}

private BooleanBuilder filterByLectureStatus(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getLectureStatus() != null) {
builder.and(lecture.lectureStatus.eq(request.getLectureStatus()));
private BooleanExpression eqLectureStatus(RequestLectureFilterVO request) {

if (request.getLectureStatus() == null) {
return null;
}
return builder;
return QLecture.lecture.lectureStatus.eq(request.getLectureStatus());
}

private BooleanBuilder filterByPriceRange(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getMinPrice() != null && request.getMaxPrice() != null) {
builder.and(lecture.lecturePrice.between(request.getMinPrice(), request.getMaxPrice()));
private BooleanExpression betweenLecturePrice(RequestLectureFilterVO request) {

if (request.getMinPrice() == null && request.getMaxPrice() == null) {
return null;
}
return builder;
if (request.getMinPrice() == null) {
return QLecture.lecture.lecturePrice.loe(request.getMaxPrice());
}
if (request.getMaxPrice() == null) {
return QLecture.lecture.lecturePrice.gt(request.getMinPrice());
}
return QLecture.lecture.lecturePrice.between(request.getMinPrice(), request.getMaxPrice());
}

private BooleanBuilder filterByCreationDate(ResponseLectureFilterRequestVO request) {
BooleanBuilder builder = new BooleanBuilder();
if (request.getStartCreatedAt() != null) {
builder.and(lecture.createdAt.goe(request.getStartCreatedAt()));
private BooleanExpression betweenCreatedAt(RequestLectureFilterVO request) {

if (request.getStartCreatedAt() == null && request.getEndCreatedAt() == null) {
return null;
}
if (request.getEndCreatedAt() == null) {
return QLecture.lecture.createdAt.gt(request.getStartCreatedAt());
}
if (request.getEndCreatedAt() != null) {
builder.and(lecture.createdAt.loe(request.getEndCreatedAt()));
if (request.getStartCreatedAt() == null) {
return QLecture.lecture.createdAt.lt(request.getEndCreatedAt());
}
return builder;
return QLecture.lecture.createdAt.between(request.getStartCreatedAt(), request.getEndCreatedAt());
}
}

0 comments on commit 942568e

Please sign in to comment.