From 1845aaef28ec3055cef2ad2da6b03850d5986c6c Mon Sep 17 00:00:00 2001 From: kyum-q <109158497+kyum-q@users.noreply.github.com> Date: Sat, 5 Oct 2024 00:07:59 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor(main):=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codezap/global/rds/DataSourceRouter.java | 2 +- .../repository/TemplateTagJpaRepository.java | 38 +++++++++---------- .../SpringDocTemplateController.java | 10 ++--- .../FullTextSearchMySQLDialect.java | 7 +++- .../repository/ThumbnailJpaRepository.java | 10 ++--- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/backend/src/main/java/codezap/global/rds/DataSourceRouter.java b/backend/src/main/java/codezap/global/rds/DataSourceRouter.java index d9a76a32e..9ffbe3ef9 100644 --- a/backend/src/main/java/codezap/global/rds/DataSourceRouter.java +++ b/backend/src/main/java/codezap/global/rds/DataSourceRouter.java @@ -12,7 +12,7 @@ public class DataSourceRouter extends AbstractRoutingDataSource { protected Object determineCurrentLookupKey() { boolean readOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); - if(readOnly) { + if (readOnly) { return READER_KEY; } return WRITER_KEY; diff --git a/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java b/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java index 5363b6cf4..1b6af8db1 100644 --- a/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java +++ b/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java @@ -22,31 +22,31 @@ public interface TemplateTagJpaRepository extends TemplateTagRepository, JpaRepo List findAllTagsByTemplate(Template template); @Query(""" - SELECT tt, t - FROM TemplateTag tt - JOIN FETCH tt.tag t - WHERE tt.id.templateId = :templateId - """) + SELECT tt, t + FROM TemplateTag tt + JOIN FETCH tt.tag t + WHERE tt.id.templateId = :templateId + """) List findAllByTemplateId(Long templateId); @Query(""" - SELECT tt, t - FROM TemplateTag tt - JOIN FETCH tt.tag t - WHERE tt.id.templateId in :templateIds - """) + SELECT tt, t + FROM TemplateTag tt + JOIN FETCH tt.tag t + WHERE tt.id.templateId in :templateIds + """) List findAllByTemplateIdsIn(List templateIds); @Query(""" - SELECT DISTINCT t - FROM Tag t - WHERE t.id IN ( - SELECT DISTINCT tt.id.tagId - FROM TemplateTag tt - WHERE tt.id.templateId IN - (SELECT te.id FROM Template te WHERE te.member.id = :memberId) - ) - """) + SELECT DISTINCT t + FROM Tag t + WHERE t.id IN ( + SELECT DISTINCT tt.id.tagId + FROM TemplateTag tt + WHERE tt.id.templateId IN + (SELECT te.id FROM Template te WHERE te.member.id = :memberId) + ) + """) List findAllTagDistinctByMemberId(Long memberId); @Modifying(clearAutomatically = true) diff --git a/backend/src/main/java/codezap/template/controller/SpringDocTemplateController.java b/backend/src/main/java/codezap/template/controller/SpringDocTemplateController.java index 4d0480a68..1537e39e6 100644 --- a/backend/src/main/java/codezap/template/controller/SpringDocTemplateController.java +++ b/backend/src/main/java/codezap/template/controller/SpringDocTemplateController.java @@ -27,7 +27,7 @@ public interface SpringDocTemplateController { 새로운 템플릿을 생성합니다. \n 템플릿명, 템플릿 설명, 소스 코드 목록, 썸네일 순서, 카테고리 ID, 태그 목록이 필요합니다. \n * 템플릿 이름은 비어있거나 공백일 수 없다. - + 소스 코드 목록은 파일명, 소스 코드, 소스 코드 순서가 필요합니다. \n * 소스 코드 순서는 1부터 시작합니다. * 소스 코드 순서는 오름차순으로 정렬하여 보내야 합니다. @@ -62,13 +62,13 @@ public interface SpringDocTemplateController { - 검색 키워드 (템플릿명, 템플릿 설명, 파일명, 소스 코드) - 카테고리 ID - 태그 ID들 \n - + 페이징 조건을 줄 수 있습니다. 페이지 번호는 1, 템플릿 개수는 20, 정렬 방식은 최신순이 기본 값입니다. \n - 페이징 조건 \n - 페이지 번호(pageNumber) - 한 페이지에 템플릿 개수(pageSize) - 페이지 정렬 방식(sort) \n - + - 정렬 방식 \n - 최신순 (modifiedAt,asc) - 오래된순 (modifiedAt,desc) @@ -102,13 +102,13 @@ ResponseEntity findAllTemplates( - 검색 키워드 (템플릿명, 템플릿 설명, 파일명, 소스 코드) - 카테고리 ID - 태그 ID들 \n - + 페이징 조건을 줄 수 있습니다. 페이지 번호는 1, 템플릿 개수는 20, 정렬 방식은 최신순이 기본 값입니다. \n - 페이징 조건 \n - 페이지 번호(pageNumber) - 한 페이지에 템플릿 개수(pageSize) - 페이지 정렬 방식(sort) \n - + - 정렬 방식 \n - 최신순 (modifiedAt,asc) - 오래된순 (modifiedAt,desc) diff --git a/backend/src/main/java/codezap/template/repository/FullTextSearchMySQLDialect.java b/backend/src/main/java/codezap/template/repository/FullTextSearchMySQLDialect.java index a97023fa3..49bcd931f 100644 --- a/backend/src/main/java/codezap/template/repository/FullTextSearchMySQLDialect.java +++ b/backend/src/main/java/codezap/template/repository/FullTextSearchMySQLDialect.java @@ -32,7 +32,12 @@ public ExactPhraseMatchFunction() { } @Override - public void render(SqlAppender sqlAppender, List arguments, ReturnableType returnType, SqlAstTranslator translator) { + public void render( + SqlAppender sqlAppender, + List arguments, + ReturnableType returnType, + SqlAstTranslator translator + ) { sqlAppender.appendSql("MATCH("); translator.render(arguments.get(0), SqlAstNodeRenderingMode.DEFAULT); sqlAppender.appendSql(", "); diff --git a/backend/src/main/java/codezap/template/repository/ThumbnailJpaRepository.java b/backend/src/main/java/codezap/template/repository/ThumbnailJpaRepository.java index 5ad7d18fc..cd2343ce2 100644 --- a/backend/src/main/java/codezap/template/repository/ThumbnailJpaRepository.java +++ b/backend/src/main/java/codezap/template/repository/ThumbnailJpaRepository.java @@ -23,11 +23,11 @@ default Thumbnail fetchByTemplate(Template template) { } @Query(""" - SELECT t, sc - FROM Thumbnail t - join fetch t.sourceCode sc - WHERE t.template = :template - """) + SELECT t, sc + FROM Thumbnail t + join fetch t.sourceCode sc + WHERE t.template = :template + """) Optional findByTemplate(Template template); From c56f260c1f0bd4bfeb5b27b84e79fab8a9e02919 Mon Sep 17 00:00:00 2001 From: kyum-q <109158497+kyum-q@users.noreply.github.com> Date: Sat, 5 Oct 2024 00:18:31 +0900 Subject: [PATCH 02/10] =?UTF-8?q?refactor(main):=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=81=EB=8B=A8=EC=97=90=20=EA=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/codezap/global/cors/CorsProperties.java | 4 ++++ .../main/java/codezap/global/exception/CodeZapException.java | 1 + .../global/serialization/DateTimeFormatConfiguration.java | 1 + .../java/codezap/global/swagger/AuthOperationCustomizer.java | 1 + .../java/codezap/global/swagger/error/ApiErrorResponses.java | 1 + .../global/swagger/error/ApiErrorResponsesCustomizer.java | 1 + .../main/java/codezap/global/validation/ValidationGroups.java | 1 + .../main/java/codezap/likes/repository/LikesRepository.java | 1 + .../java/codezap/tag/controller/SpringDocTagController.java | 1 + .../codezap/template/repository/SourceCodeJpaRepository.java | 1 + .../codezap/template/repository/SourceCodeRepository.java | 1 + .../codezap/template/repository/TemplateSpecification.java | 1 + 12 files changed, 15 insertions(+) diff --git a/backend/src/main/java/codezap/global/cors/CorsProperties.java b/backend/src/main/java/codezap/global/cors/CorsProperties.java index f1fdb4e74..dc2307068 100644 --- a/backend/src/main/java/codezap/global/cors/CorsProperties.java +++ b/backend/src/main/java/codezap/global/cors/CorsProperties.java @@ -4,8 +4,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.bind.DefaultValue; +import lombok.Getter; + +@Getter @ConfigurationProperties(prefix = "cors") public class CorsProperties { + private final String[] allowedOrigins; private final String[] allowedOriginsPatterns; diff --git a/backend/src/main/java/codezap/global/exception/CodeZapException.java b/backend/src/main/java/codezap/global/exception/CodeZapException.java index 71af97c34..bfbf3ed1a 100644 --- a/backend/src/main/java/codezap/global/exception/CodeZapException.java +++ b/backend/src/main/java/codezap/global/exception/CodeZapException.java @@ -6,6 +6,7 @@ @Getter public class CodeZapException extends RuntimeException { + private final HttpStatusCode httpStatusCode; public CodeZapException(HttpStatusCode httpStatusCode, String message) { diff --git a/backend/src/main/java/codezap/global/serialization/DateTimeFormatConfiguration.java b/backend/src/main/java/codezap/global/serialization/DateTimeFormatConfiguration.java index 959886ebe..85f47477e 100644 --- a/backend/src/main/java/codezap/global/serialization/DateTimeFormatConfiguration.java +++ b/backend/src/main/java/codezap/global/serialization/DateTimeFormatConfiguration.java @@ -10,6 +10,7 @@ @Configuration public class DateTimeFormatConfiguration { + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; @Bean diff --git a/backend/src/main/java/codezap/global/swagger/AuthOperationCustomizer.java b/backend/src/main/java/codezap/global/swagger/AuthOperationCustomizer.java index ca2e048dc..03c884f46 100644 --- a/backend/src/main/java/codezap/global/swagger/AuthOperationCustomizer.java +++ b/backend/src/main/java/codezap/global/swagger/AuthOperationCustomizer.java @@ -27,6 +27,7 @@ */ @Component public class AuthOperationCustomizer implements OperationCustomizer { + private static final ObjectMapper objectMapper = new ObjectMapper(); @Override diff --git a/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponses.java b/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponses.java index 2589cf96d..8d3ad4ff6 100644 --- a/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponses.java +++ b/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponses.java @@ -8,5 +8,6 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ApiErrorResponses { + ApiErrorResponse[] value(); } diff --git a/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponsesCustomizer.java b/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponsesCustomizer.java index a2bcc78aa..766444dc5 100644 --- a/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponsesCustomizer.java +++ b/backend/src/main/java/codezap/global/swagger/error/ApiErrorResponsesCustomizer.java @@ -20,6 +20,7 @@ @Component public class ApiErrorResponsesCustomizer implements OperationCustomizer { + @Override public Operation customize(Operation operation, HandlerMethod handlerMethod) { List apiErrorResponses = getApiErrorResponses(handlerMethod); diff --git a/backend/src/main/java/codezap/global/validation/ValidationGroups.java b/backend/src/main/java/codezap/global/validation/ValidationGroups.java index df4729a5c..8f36c360e 100644 --- a/backend/src/main/java/codezap/global/validation/ValidationGroups.java +++ b/backend/src/main/java/codezap/global/validation/ValidationGroups.java @@ -1,6 +1,7 @@ package codezap.global.validation; public class ValidationGroups { + public interface NotNullGroup {} public interface SourceCodeOrdinalGroup {} diff --git a/backend/src/main/java/codezap/likes/repository/LikesRepository.java b/backend/src/main/java/codezap/likes/repository/LikesRepository.java index 5cefefaac..e4b92a9de 100644 --- a/backend/src/main/java/codezap/likes/repository/LikesRepository.java +++ b/backend/src/main/java/codezap/likes/repository/LikesRepository.java @@ -5,6 +5,7 @@ import codezap.template.domain.Template; public interface LikesRepository { + Likes save(Likes likes); boolean existsByMemberAndTemplate(Member member, Template template); diff --git a/backend/src/main/java/codezap/tag/controller/SpringDocTagController.java b/backend/src/main/java/codezap/tag/controller/SpringDocTagController.java index efc67d367..af3006ae6 100644 --- a/backend/src/main/java/codezap/tag/controller/SpringDocTagController.java +++ b/backend/src/main/java/codezap/tag/controller/SpringDocTagController.java @@ -10,6 +10,7 @@ @Tag(name = "태그 API", description = "태그 조회 API") public interface SpringDocTagController { + @SecurityRequirement(name = "쿠키 인증 토큰") @Operation(summary = "태그 조회", description = "해당 멤버의 템플릿들에 포함된 태그를 조회합니다.") @ApiResponse(responseCode = "200", description = "태그 조회 성공") diff --git a/backend/src/main/java/codezap/template/repository/SourceCodeJpaRepository.java b/backend/src/main/java/codezap/template/repository/SourceCodeJpaRepository.java index 57fcc7243..36c472788 100644 --- a/backend/src/main/java/codezap/template/repository/SourceCodeJpaRepository.java +++ b/backend/src/main/java/codezap/template/repository/SourceCodeJpaRepository.java @@ -14,6 +14,7 @@ @SuppressWarnings("unused") public interface SourceCodeJpaRepository extends SourceCodeRepository, JpaRepository { + default SourceCode fetchById(Long id) { return findById(id).orElseThrow( () -> new CodeZapException(HttpStatus.NOT_FOUND, "식별자 " + id + "에 해당하는 소스 코드가 존재하지 않습니다.")); diff --git a/backend/src/main/java/codezap/template/repository/SourceCodeRepository.java b/backend/src/main/java/codezap/template/repository/SourceCodeRepository.java index 1f6936857..745f3ae77 100644 --- a/backend/src/main/java/codezap/template/repository/SourceCodeRepository.java +++ b/backend/src/main/java/codezap/template/repository/SourceCodeRepository.java @@ -7,6 +7,7 @@ import codezap.template.domain.Template; public interface SourceCodeRepository { + SourceCode fetchById(Long id); List findAllByTemplate(Template template); diff --git a/backend/src/main/java/codezap/template/repository/TemplateSpecification.java b/backend/src/main/java/codezap/template/repository/TemplateSpecification.java index 2001ec93a..71aef43dd 100644 --- a/backend/src/main/java/codezap/template/repository/TemplateSpecification.java +++ b/backend/src/main/java/codezap/template/repository/TemplateSpecification.java @@ -17,6 +17,7 @@ import codezap.template.domain.TemplateTag; public class TemplateSpecification implements Specification