Skip to content

Commit

Permalink
[UPDATE] repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jhhong0509 committed May 5, 2021
1 parent d3439ce commit be708b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Page<Report> findAllByAccessAndGradeAndFieldAndType(Grade grade, Field fi
.and(report.isAccepted.eq(true)))
.where(eqGrade(grade)
.and(eqType(type))
.and(eqAccess(Access.EVERY))
.and(eqAccess())
.and(eqField(field)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand All @@ -41,14 +41,14 @@ public Page<Report> findAllByAccessAndGradeAndFieldAndType(Grade grade, Field fi
return new PageImpl<>(results.getResults(), pageable, results.getTotal());
}

public Page<Report> findAllByMembersContainsAndIsAcceptedAndIsSubmittedTrueAndReportTypeAccessOrderByReportIdDesc(User user, Access access, Pageable page) {
public Page<Report> findAllByMembersContainsAndIsAcceptedAndIsSubmittedTrueAndReportTypeAccessOrderByReportIdDesc(User user, Pageable page) {
QueryResults<Report> results = jpaQueryFactory
.select(report)
.from(report)
.where(report.members.any().user.eq(user)
.and(report.isAccepted.eq(true))
.and(report.isSubmitted.eq(true))
.and(report.reportType.access.eq(access)))
.and(eqAccess()))
.offset(page.getOffset())
.limit(page.getPageSize())
.orderBy(report.id.desc())
Expand All @@ -57,11 +57,8 @@ public Page<Report> findAllByMembersContainsAndIsAcceptedAndIsSubmittedTrueAndRe
return new PageImpl<>(results.getResults(), page, results.getTotal());
}

private BooleanExpression eqAccess(Access access) {
if (access == null) {
return null;
}
return report.reportType.access.eq(access);
private BooleanExpression eqAccess() {
return report.reportType.access.eq(Access.EVERY);
}

private BooleanExpression eqGrade(Grade grade) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dsmpear.main.user_backend_v2.entity.report;
package com.dsmpear.main.user_backend_v2.entity.report.repository;

import com.dsmpear.main.user_backend_v2.entity.report.Report;
import com.dsmpear.main.user_backend_v2.entity.report.enums.Access;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -8,7 +9,6 @@

import java.util.Optional;


@Repository
public interface ReportRepository extends CrudRepository<Report,Long> {
// 보고서 갖고오기
Expand Down

0 comments on commit be708b4

Please sign in to comment.