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: 기존 model 및 logic을 데모 전용으로 변경 #44

Merged
merged 1 commit into from
May 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import vook.server.api.helper.QuerydslHelper;
import vook.server.api.model.QTerm;
import vook.server.api.model.Term;
import vook.server.api.model.demo.DemoTerm;
import vook.server.api.model.demo.QDemoTerm;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class TermSearchRepository {
public class DemoSearchRepository {

private final JPAQueryFactory queryFactory;

public List<Term> search(String glossaryUid, Pageable pageable) {
QTerm term = QTerm.term1;
public List<DemoTerm> searchDemoTerm(String demoGlossaryUid, Pageable pageable) {
QDemoTerm demoTerm = QDemoTerm.demoTerm;

// fetch join과 pagination을 같이 하면,
// HHH90003004: firstResult/maxResults specified with collection fetch; applying in memory
// 에러가 발생, 이를 피하기 위해 pagination이 포함된 쿼리를 서브 쿼리로 하여 수행
JPAQuery<Long> termIdQuery = queryFactory
.select(term.id)
.from(term)
.where(term.glossary.uid.eq(glossaryUid))
.select(demoTerm.id)
.from(demoTerm)
.where(demoTerm.demoGlossary.uid.eq(demoGlossaryUid))
.offset(pageable.getOffset())
.limit(pageable.getPageSize());

QuerydslHelper
.toOrderSpecifiers(term, pageable)
.toOrderSpecifiers(demoTerm, pageable)
.forEach(termIdQuery::orderBy);

JPAQuery<Term> dataQuery = queryFactory
.selectFrom(term)
.leftJoin(term.synonyms).fetchJoin()
.where(term.id.in(termIdQuery));
JPAQuery<DemoTerm> dataQuery = queryFactory
.selectFrom(demoTerm)
.leftJoin(demoTerm.synonyms).fetchJoin()
.where(demoTerm.id.in(termIdQuery));

// In 절에 들어간 입력순대로 출력되지 않음으로 정렬 조건을 다시 한번 설정
QuerydslHelper
.toOrderSpecifiers(term, pageable)
.toOrderSpecifiers(demoTerm, pageable)
.forEach(dataQuery::orderBy);

return dataQuery.fetch();
Expand Down
31 changes: 31 additions & 0 deletions api/src/main/java/vook/server/api/app/DemoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package vook.server.api.app;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import vook.server.api.model.demo.DemoGlossary;
import vook.server.api.model.demo.DemoGlossaryRepository;
import vook.server.api.model.demo.DemoTerm;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class DemoService {

private final DemoGlossaryRepository demoGlossaryRepository;
private final DemoSearchRepository searchRepository;

public List<DemoGlossary> findAllDemoGlossary() {
return demoGlossaryRepository.findAll();
}

public Optional<DemoGlossary> findDemoGlossaryByUid(String demoGlossaryUid) {
return demoGlossaryRepository.findByUid(demoGlossaryUid);
}

public List<DemoTerm> findAllDemoTermBy(DemoGlossary demoGlossary, Pageable pageable) {
return searchRepository.searchDemoTerm(demoGlossary.getUid(), pageable);
}
}
24 changes: 0 additions & 24 deletions api/src/main/java/vook/server/api/app/GlossaryService.java

This file was deleted.

20 changes: 0 additions & 20 deletions api/src/main/java/vook/server/api/app/TermService.java

This file was deleted.

49 changes: 21 additions & 28 deletions api/src/main/java/vook/server/api/devhelper/InitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vook.server.api.model.*;
import vook.server.api.outbound.search.SearchClearable;
import vook.server.api.outbound.search.SearchService;
import vook.server.api.model.demo.*;
import vook.server.api.outbound.search.DemoTermSearchService;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -21,38 +20,32 @@ public class InitService {

private final ResourceLoader resourceLoader;

private final MemberRepository memberRepository;
private final GlossaryRepository glossaryRepository;
private final TermRepository termRepository;
private final TermSynonymRepository termSynonymRepository;
private final SearchClearable searchClearable;

private final SearchService searchService;
private final DemoGlossaryRepository demoGlossaryRepository;
private final DemoTermRepository demoTermRepository;
private final DemoTermSynonymRepository demoTermSynonymRepository;
private final DemoTermSearchService searchService;

public void init() {
termSynonymRepository.deleteAllInBatch();
termRepository.deleteAllInBatch();
glossaryRepository.deleteAllInBatch();
memberRepository.deleteAllInBatch();
searchClearable.clearAll();

Member vook = memberRepository.save(Member.forCreateOf("vook"));
demoTermSynonymRepository.deleteAllInBatch();
demoTermRepository.deleteAllInBatch();
demoGlossaryRepository.deleteAllInBatch();
searchService.clearAll();

Glossary devGlossary = glossaryRepository.save(Glossary.forCreateOf("개발", vook));
DemoGlossary devGlossary = demoGlossaryRepository.save(DemoGlossary.forCreateOf("개발"));
searchService.createGlossary(devGlossary);
Glossary designGlossary = glossaryRepository.save(Glossary.forCreateOf("디자인", vook));
DemoGlossary designGlossary = demoGlossaryRepository.save(DemoGlossary.forCreateOf("디자인"));
searchService.createGlossary(designGlossary);
Glossary marketingGlossary = glossaryRepository.save(Glossary.forCreateOf("마케팅", vook));
DemoGlossary marketingGlossary = demoGlossaryRepository.save(DemoGlossary.forCreateOf("마케팅"));
searchService.createGlossary(marketingGlossary);
Glossary practiceGlossary = glossaryRepository.save(Glossary.forCreateOf("실무", vook));
DemoGlossary practiceGlossary = demoGlossaryRepository.save(DemoGlossary.forCreateOf("실무"));
searchService.createGlossary(practiceGlossary);

List<Term> devTerms = getTerms("classpath:init/개발.tsv", devGlossary);
List<Term> terms = termRepository.saveAll(devTerms);
searchService.addTerms(terms, devGlossary);
List<DemoTerm> devTerms = getTerms("classpath:init/개발.tsv", devGlossary);
List<DemoTerm> terms = demoTermRepository.saveAll(devTerms);
searchService.addTerms(devGlossary, terms);
}

private List<Term> getTerms(String location, Glossary glossary) {
private List<DemoTerm> getTerms(String location, DemoGlossary glossary) {
try {
// file로 바로 접근 할 경우, IDE에서는 접근 가능하나, jar로 패키징 후 실행 시에는 접근 불가능
// ref) https://velog.io/@haron/트러블슈팅-Spring-IDE-에서-되는데-배포하면-안-돼요
Expand All @@ -65,7 +58,7 @@ private List<Term> getTerms(String location, Glossary glossary) {
}
}

private static @NotNull List<Term> toTerms(List<RawTerm> rawTerms, Glossary glossary) {
private static @NotNull List<DemoTerm> toTerms(List<RawTerm> rawTerms, DemoGlossary glossary) {
return rawTerms.stream()
.map(rawTerm -> rawTerm.toTerm(glossary))
.toList();
Expand All @@ -76,8 +69,8 @@ public static class RawTerm {
private String synonyms;
private String meaning;

public Term toTerm(Glossary glossary) {
Term term = Term.forCreateOf(this.term, this.meaning, glossary);
public DemoTerm toTerm(DemoGlossary glossary) {
DemoTerm term = DemoTerm.forCreateOf(this.term, this.meaning, glossary);
String[] synonymArray = this.synonyms.split("//n");
Arrays.stream(synonymArray)
.map(String::trim)
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/vook/server/api/devhelper/LocalInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import vook.server.api.model.MemberRepository;
import vook.server.api.model.demo.DemoGlossaryRepository;

@Slf4j
@Profile("local")
@Component
@RequiredArgsConstructor
public class LocalInit {

private final MemberRepository memberRepository;
private final DemoGlossaryRepository demoGlossaryRepository;
private final InitService initService;

@PostConstruct
public void init() {
if (memberRepository.count() > 0) {
if (demoGlossaryRepository.count() > 0) {
return;
}

Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions api/src/main/java/vook/server/api/model/Member.java

This file was deleted.

6 changes: 0 additions & 6 deletions api/src/main/java/vook/server/api/model/MemberRepository.java

This file was deleted.

55 changes: 0 additions & 55 deletions api/src/main/java/vook/server/api/model/Term.java

This file was deleted.

6 changes: 0 additions & 6 deletions api/src/main/java/vook/server/api/model/TermRepository.java

This file was deleted.

This file was deleted.

Loading
Loading