From dcfb4066795839e59161921c7767b46addf76465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=AC=EC=9A=B0?= Date: Thu, 24 Oct 2024 21:36:09 +0900 Subject: [PATCH 1/8] =?UTF-8?q?Nginx=20=EC=84=A4=EC=A0=95=EC=9D=B4=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20(#882)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: fix typo * chore: fix typo * chore: fix zdd * chore: fix zdd * chore: fix zdd * chore: fix zdd * chore: remove export hostname * chore: remove export hostname * chore: remove nginx config * chore: fix deploy script * chore: fix deploy script --- backend/submodules/private | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/submodules/private b/backend/submodules/private index 9968b84a3..c434d76a4 160000 --- a/backend/submodules/private +++ b/backend/submodules/private @@ -1 +1 @@ -Subproject commit 9968b84a38d1db534354a0e8d71bfed7180c384c +Subproject commit c434d76a4712b6d3299525142b963bc0cbd8ee74 From 22813d79231812f3ac1330e559d6e0f62325708b Mon Sep 17 00:00:00 2001 From: Moly <102847513+jminkkk@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:30:45 +0900 Subject: [PATCH 2/8] =?UTF-8?q?QueryDSL=20=EB=8F=84=EC=9E=85=20(#869)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 4 + .../repository/CategoryJpaRepository.java | 10 +- .../repository/CategoryRepository.java | 36 ++++- .../global/querydsl/QueryDSLConfig.java | 21 +++ .../codezap/global/rds/DataSourceConfig.java | 1 - .../likes/repository/LikesJpaRepository.java | 14 +- .../repository/LikesQueryDslRepository.java | 25 ++++ .../likes/repository/LikesRepository.java | 35 +++-- .../member/controller/MemberController.java | 13 +- .../controller/SpringDocMemberController.java | 9 +- .../repository/MemberJpaRepository.java | 26 +--- .../repository/MemberQueryDSLRepository.java | 26 ++++ .../member/repository/MemberRepository.java | 35 ++++- .../codezap/member/service/MemberService.java | 2 - .../tag/repository/TagJpaRepository.java | 15 +- .../codezap/tag/repository/TagRepository.java | 32 +++- .../repository/TemplateTagJpaRepository.java | 51 +------ .../TemplateTagQueryDSLRepository.java | 65 ++++++++ .../tag/repository/TemplateTagRepository.java | 46 ++++-- .../codezap/template/domain/TemplateTag.java | 2 +- .../FullTextFunctionContributor.java | 20 +++ .../FullTextSearchMySQLDialect.java | 76 +++++----- .../repository/SourceCodeJpaRepository.java | 24 +-- .../SourceCodeQueryDSLRepository.java | 25 ++++ .../repository/SourceCodeRepository.java | 51 +++++-- .../repository/TemplateJpaRepository.java | 17 +-- .../TemplateOrderSpecifierUtils.java | 56 +++++++ .../TemplateQueryDSLRepository.java | 89 +++++++++++ .../repository/TemplateRepository.java | 54 +++++-- .../TemplateSearchExpressionProvider.java | 74 +++++++++ .../repository/TemplateSpecification.java | 119 --------------- .../repository/ThumbnailJpaRepository.java | 41 +---- .../ThumbnailQueryDSLRepository.java | 42 ++++++ .../repository/ThumbnailRepository.java | 33 +++- .../FullTextSearchSearchStrategy.java | 43 ++++++ .../strategy/LikeSearchStrategy.java | 42 ++++++ .../repository/strategy/SearchStrategy.java | 8 + .../template/service/TemplateService.java | 4 +- ...g.hibernate.boot.model.FunctionContributor | 1 + backend/src/main/resources/application-db.yml | 3 - .../src/main/resources/application-local.yml | 3 - .../BasicAuthCredentialProviderTest.java | 1 - .../repository/CategoryRepositoryTest.java | 4 +- .../global/repository/JpaRepositoryTest.java | 23 --- .../global/repository/RepositoryTest.java | 35 +++++ ...toryTest.java => LikesRepositoryTest.java} | 6 +- ...oryTest.java => MemberRepositoryTest.java} | 6 +- ...sitoryTest.java => TagRepositoryTest.java} | 44 +----- ...st.java => TemplateTagRepositoryTest.java} | 6 +- .../repository/SourceCodeRepositoryTest.java | 4 +- ...yTest.java => TemplateRepositoryTest.java} | 6 +- ...java => TemplateSearchRepositoryTest.java} | 141 ++++++++++++------ .../repository/ThumbnailRepositoryTest.java | 4 +- .../TemplateApplicationServiceTest.java | 5 +- 54 files changed, 1014 insertions(+), 564 deletions(-) create mode 100644 backend/src/main/java/codezap/global/querydsl/QueryDSLConfig.java create mode 100644 backend/src/main/java/codezap/likes/repository/LikesQueryDslRepository.java create mode 100644 backend/src/main/java/codezap/member/repository/MemberQueryDSLRepository.java create mode 100644 backend/src/main/java/codezap/tag/repository/TemplateTagQueryDSLRepository.java create mode 100644 backend/src/main/java/codezap/template/repository/FullTextFunctionContributor.java create mode 100644 backend/src/main/java/codezap/template/repository/SourceCodeQueryDSLRepository.java create mode 100644 backend/src/main/java/codezap/template/repository/TemplateOrderSpecifierUtils.java create mode 100644 backend/src/main/java/codezap/template/repository/TemplateQueryDSLRepository.java create mode 100644 backend/src/main/java/codezap/template/repository/TemplateSearchExpressionProvider.java delete mode 100644 backend/src/main/java/codezap/template/repository/TemplateSpecification.java create mode 100644 backend/src/main/java/codezap/template/repository/ThumbnailQueryDSLRepository.java create mode 100644 backend/src/main/java/codezap/template/repository/strategy/FullTextSearchSearchStrategy.java create mode 100644 backend/src/main/java/codezap/template/repository/strategy/LikeSearchStrategy.java create mode 100644 backend/src/main/java/codezap/template/repository/strategy/SearchStrategy.java create mode 100644 backend/src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor delete mode 100644 backend/src/test/java/codezap/global/repository/JpaRepositoryTest.java create mode 100644 backend/src/test/java/codezap/global/repository/RepositoryTest.java rename backend/src/test/java/codezap/likes/repository/{LikesJpaRepositoryTest.java => LikesRepositoryTest.java} (98%) rename backend/src/test/java/codezap/member/repository/{MemberJpaRepositoryTest.java => MemberRepositoryTest.java} (97%) rename backend/src/test/java/codezap/tag/repository/{TagJpaRepositoryTest.java => TagRepositoryTest.java} (68%) rename backend/src/test/java/codezap/tag/repository/{TemplateTagJpaRepositoryTest.java => TemplateTagRepositoryTest.java} (98%) rename backend/src/test/java/codezap/template/repository/{TemplateJpaRepositoryTest.java => TemplateRepositoryTest.java} (97%) rename backend/src/test/java/codezap/template/repository/{TemplateSearchJpaRepositoryTest.java => TemplateSearchRepositoryTest.java} (68%) diff --git a/backend/build.gradle b/backend/build.gradle index 8181f00f3..612c5dfe9 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -33,6 +33,10 @@ dependencies { runtimeOnly 'com.mysql:mysql-connector-j:9.0.0' implementation 'org.flywaydb:flyway-core' implementation 'org.flywaydb:flyway-mysql' + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta' + annotationProcessor 'jakarta.persistence:jakarta.persistence-api:3.1.0' + annotationProcessor 'jakarta.annotation:jakarta.annotation-api:2.1.1' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.rest-assured:rest-assured:5.5.0' diff --git a/backend/src/main/java/codezap/category/repository/CategoryJpaRepository.java b/backend/src/main/java/codezap/category/repository/CategoryJpaRepository.java index d692f1a48..a2308ba9d 100644 --- a/backend/src/main/java/codezap/category/repository/CategoryJpaRepository.java +++ b/backend/src/main/java/codezap/category/repository/CategoryJpaRepository.java @@ -5,17 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import codezap.category.domain.Category; -import codezap.global.exception.CodeZapException; -import codezap.global.exception.ErrorCode; import codezap.member.domain.Member; -@SuppressWarnings("unused") -public interface CategoryJpaRepository extends CategoryRepository, JpaRepository { - - default Category fetchById(Long id) { - return findById(id).orElseThrow( - () -> new CodeZapException(ErrorCode.RESOURCE_NOT_FOUND, "식별자 " + id + "에 해당하는 카테고리가 존재하지 않습니다.")); - } +public interface CategoryJpaRepository extends JpaRepository { List findAllByMemberIdOrderById(Long memberId); diff --git a/backend/src/main/java/codezap/category/repository/CategoryRepository.java b/backend/src/main/java/codezap/category/repository/CategoryRepository.java index debb78f08..85b4178d2 100644 --- a/backend/src/main/java/codezap/category/repository/CategoryRepository.java +++ b/backend/src/main/java/codezap/category/repository/CategoryRepository.java @@ -2,20 +2,42 @@ import java.util.List; +import org.springframework.stereotype.Repository; + import codezap.category.domain.Category; +import codezap.global.exception.CodeZapException; +import codezap.global.exception.ErrorCode; import codezap.member.domain.Member; +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class CategoryRepository { -public interface CategoryRepository { + private final CategoryJpaRepository categoryJpaRepository; - Category fetchById(Long id); + public Category save(Category category) { + return categoryJpaRepository.save(category); + } - List findAllByMemberIdOrderById(Long memberId); + public Category fetchById(Long id) { + return categoryJpaRepository.findById(id).orElseThrow( + () -> new CodeZapException(ErrorCode.RESOURCE_NOT_FOUND, "식별자 " + id + "에 해당하는 카테고리가 존재하지 않습니다.")); + } - List findAll(); + public List findAllByMemberIdOrderById(Long memberId) { + return categoryJpaRepository.findAllByMemberIdOrderById(memberId); + } - boolean existsByNameAndMember(String categoryName, Member member); + public List findAll() { + return categoryJpaRepository.findAll(); + } - Category save(Category category); + public boolean existsByNameAndMember(String categoryName, Member member) { + return categoryJpaRepository.existsByNameAndMember(categoryName, member); + } - void deleteById(Long id); + public void deleteById(Long id) { + categoryJpaRepository.deleteById(id); + } } diff --git a/backend/src/main/java/codezap/global/querydsl/QueryDSLConfig.java b/backend/src/main/java/codezap/global/querydsl/QueryDSLConfig.java new file mode 100644 index 000000000..384b4b8bb --- /dev/null +++ b/backend/src/main/java/codezap/global/querydsl/QueryDSLConfig.java @@ -0,0 +1,21 @@ +package codezap.global.querydsl; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +@Configuration +public class QueryDSLConfig { + + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} diff --git a/backend/src/main/java/codezap/global/rds/DataSourceConfig.java b/backend/src/main/java/codezap/global/rds/DataSourceConfig.java index fa1f9a6d6..ea1140995 100644 --- a/backend/src/main/java/codezap/global/rds/DataSourceConfig.java +++ b/backend/src/main/java/codezap/global/rds/DataSourceConfig.java @@ -11,7 +11,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; diff --git a/backend/src/main/java/codezap/likes/repository/LikesJpaRepository.java b/backend/src/main/java/codezap/likes/repository/LikesJpaRepository.java index 4c2e1d265..196dadf12 100644 --- a/backend/src/main/java/codezap/likes/repository/LikesJpaRepository.java +++ b/backend/src/main/java/codezap/likes/repository/LikesJpaRepository.java @@ -1,22 +1,22 @@ package codezap.likes.repository; -import java.util.List; - 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.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import codezap.likes.domain.Likes; +import codezap.member.domain.Member; import codezap.template.domain.Template; -public interface LikesJpaRepository extends LikesRepository, JpaRepository { +public interface LikesJpaRepository extends JpaRepository { + + void deleteByMemberAndTemplate(Member member, Template template); + + boolean existsByMemberAndTemplate(Member member, Template template); - @Modifying(clearAutomatically = true) - @Query("DELETE FROM Likes l WHERE l.template.id in :templateIds") - void deleteAllByTemplateIds(@Param(value = "templateIds") List templateIds); + long countByTemplate(Template template); @Query(""" SELECT l.template diff --git a/backend/src/main/java/codezap/likes/repository/LikesQueryDslRepository.java b/backend/src/main/java/codezap/likes/repository/LikesQueryDslRepository.java new file mode 100644 index 000000000..dac87d865 --- /dev/null +++ b/backend/src/main/java/codezap/likes/repository/LikesQueryDslRepository.java @@ -0,0 +1,25 @@ +package codezap.likes.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +import codezap.likes.domain.QLikes; +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class LikesQueryDslRepository { + + private final JPAQueryFactory jpaQueryFactory; + + @Modifying(clearAutomatically = true) + public void deleteAllByTemplateIds(List templateIds) { + jpaQueryFactory.delete(QLikes.likes) + .where(QLikes.likes.template.id.in(templateIds)) + .execute(); + } +} diff --git a/backend/src/main/java/codezap/likes/repository/LikesRepository.java b/backend/src/main/java/codezap/likes/repository/LikesRepository.java index 358c18c9b..1c4e1b690 100644 --- a/backend/src/main/java/codezap/likes/repository/LikesRepository.java +++ b/backend/src/main/java/codezap/likes/repository/LikesRepository.java @@ -4,24 +4,41 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; import codezap.likes.domain.Likes; import codezap.member.domain.Member; import codezap.template.domain.Template; +import lombok.RequiredArgsConstructor; -public interface LikesRepository { +@Repository +@RequiredArgsConstructor +public class LikesRepository { - Likes save(Likes likes); + private final LikesJpaRepository likesJpaRepository; + private final LikesQueryDslRepository likesQueryDslRepository; - boolean existsByMemberAndTemplate(Member member, Template template); + public Likes save(Likes likes) { + return likesJpaRepository.save(likes); + } - long countByTemplate(Template template); + public boolean existsByMemberAndTemplate(Member member, Template template) { + return likesJpaRepository.existsByMemberAndTemplate(member, template); + } - void deleteByMemberAndTemplate(Member member, Template template); + public long countByTemplate(Template template) { + return likesJpaRepository.countByTemplate(template); + } - void deleteAllByTemplateIds(List templateIds); + public void deleteByMemberAndTemplate(Member member, Template template) { + likesJpaRepository.deleteByMemberAndTemplate(member, template); + } - Page