Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: content type 추가 #62

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
image: redis
ports:
- 6379:6379
networks:
- reverseproxy
khumon:
container_name: khumon
image: chy0310/khumon
Expand Down
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
Expand Up @@ -15,6 +15,7 @@ public class LearningMaterialContent {
private Long id;
private String title;
private String content;
private String type;
private LocalDateTime createAt;
private LocalDateTime modifiedAt;

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,13 +128,14 @@ 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())
.content(learningMaterial.getContent())
.type(learningMaterial.getMediaFileType().getFileType())
.createAt(learningMaterial.getCreatedAt())
.modifiedAt(learningMaterial.getUpdateAt())
.build()).toList();
Expand Down Expand Up @@ -181,4 +184,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);

};
}

}
Loading