Skip to content

Commit

Permalink
fix: 검색 쿼리 메서드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin0o0 committed Nov 16, 2023
1 parent aa28ae0 commit 35aa321
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResponseEntity<?> getLearningMaterial(@PathVariable(name = "learning-mate

@PreAuthorize("isAuthenticated()")
@GetMapping("/learning-materials")
public ResponseEntity<?> getLearningMaterials(Principal principal, @PageableDefault(sort = "id", direction = Sort.Direction.DESC, size = 10) Pageable pageable, @RequestParam(required = false, defaultValue = "") String search){
public ResponseEntity<?> getLearningMaterials(Principal principal, @PageableDefault(sort = "id", direction = Sort.Direction.DESC, size = 10) Pageable pageable, @RequestParam(required = false, defaultValue = "", value = "search") String search){
return learningMaterialService.getLearningMaterials(principal, pageable, search);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface LearningMaterialRepository extends JpaRepository<LearningMaterial, Long> {

Page<LearningMaterial> findByMemberIdAndTitleContainingOrContentContaining(Long memberId, String title, String content, Pageable pageable);


Page<LearningMaterial> findAllByTitleIsContainingAndMemberId(String search, Long memberId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ public ResponseEntity<?> getLearningMaterial(Long id, Principal principal) {


public ResponseEntity<?> getLearningMaterials(Principal principal, Pageable pageable, String search) {
log.info("search : " + search);
Member member = memberRepository.findByUsername(principal.getName()).orElseThrow();
Page<LearningMaterial> learningMaterials = learningMaterialRepository.findByMemberIdAndTitleContainingOrContentContaining(member.getId(), search, search, pageable);
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());
List<LearningMaterialContent> learningMaterialContents = learningMaterials.getContent().stream().map(learningMaterial -> LearningMaterialContent.builder()
.id(learningMaterial.getId())
.title(learningMaterial.getTitle())
Expand Down

0 comments on commit 35aa321

Please sign in to comment.