Skip to content

Commit

Permalink
feat: search extend (#61)
Browse files Browse the repository at this point in the history
* feat: 검색 기능 확장

* fix: nginx maxfilesize 변경
  • Loading branch information
Martin0o0 authored Nov 20, 2023
1 parent 35aa321 commit eb16eb0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
9 changes: 9 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ server {
location / {
return 301 https://$host$request_uri;
}

proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
client_max_body_size 600M;
}


Expand All @@ -34,6 +38,11 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
client_max_body_size 600M;

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.teamh.khumon.repository;

import com.teamh.khumon.domain.LearningMaterial;
import jakarta.persistence.criteria.Predicate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand All @@ -13,5 +16,7 @@ public interface LearningMaterialRepository extends JpaRepository<LearningMateri



Page<LearningMaterial> findAllByTitleIsContainingAndMemberId(String search, Long memberId, Pageable pageable);
// Page<LearningMaterial> findAllByTitleIsContainingAndMemberId(String search, Long memberId, Pageable pageable);

Page<LearningMaterial> findAll(Specification<LearningMaterial> specification, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.teamh.khumon.util.AmazonS3Util;
import com.teamh.khumon.util.MediaUtil;
import com.teamh.khumon.util.ObjectToDtoUtil;
import jakarta.persistence.criteria.*;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -126,9 +128,9 @@ public ResponseEntity<?> getLearningMaterials(Principal principal, Pageable page
log.info("search : " + search);
Member member = memberRepository.findByUsername(principal.getName()).orElseThrow();
log.info("member ID : " + member.getId());
//log.info(learningMaterialRepository.findAllByMemberId(member.getId()).toString());
Page<LearningMaterial> learningMaterials = learningMaterialRepository.findAllByTitleIsContainingAndMemberId(search, member.getId() , pageable);
//log.info(learningMaterials.getContent().toString());
Specification<LearningMaterial> specification = search(search, member.getId());
Page<LearningMaterial> learningMaterials = learningMaterialRepository.findAll(specification, pageable);

List<LearningMaterialContent> learningMaterialContents = learningMaterials.getContent().stream().map(learningMaterial -> LearningMaterialContent.builder()
.id(learningMaterial.getId())
.title(learningMaterial.getTitle())
Expand Down Expand Up @@ -181,4 +183,17 @@ public ResponseEntity<?> delete(Principal principal, Long id) {
return new ResponseEntity<Void>(HttpStatus.OK);
}

private Specification<LearningMaterial> search(String kw, Long memberId) {
return (Root<LearningMaterial> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) -> {
criteriaQuery.distinct(true); // 중복을 제거
root.join("member", JoinType.INNER);
Predicate memberIdPredicate = criteriaBuilder.equal(root.get("member").get("id"), memberId);
Predicate searchPredicate = criteriaBuilder.or(criteriaBuilder.like(root.get("title"), "%" + kw + "%"), // 제목
criteriaBuilder.like(root.get("content"), "%" + kw + "%"), // 내용
criteriaBuilder.like(root.get("summary"), "%" + kw + "%")); //script
return criteriaBuilder.and(memberIdPredicate, searchPredicate);

};
}

}

0 comments on commit eb16eb0

Please sign in to comment.