From 2738bf42045aba965337180b131a80e9b2b3ae3d Mon Sep 17 00:00:00 2001 From: Redddy <78539407+reddevilmidzy@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:29:30 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20=EC=9A=B4=EC=98=81=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=20=EB=B0=B0=ED=8F=AC=20(#579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 링크 조회시에도 카테고리 리턴타입 변경 * style: api 엔드포인트 변경 * [BE] 개발(테스트) 서버와 프로덕션 서버 oauth secret분리 (#571) * fix: cors 오류 해결 * [BE] 잘못된 test yml 수정 * [BE] 개발(테스트) 서버와 프로덕션 서버 oauth secret분리 (#581) Co-authored-by: Redddy <78539407+reddevilmidzy@users.noreply.github.com> --------- Co-authored-by: lemone <55480011+JiHyeonL@users.noreply.github.com> Co-authored-by: 김민종 --- .github/workflows/be_cd-test.yml | 6 +++--- .../main/java/site/coduo/common/config/WebMvcConfig.java | 4 ++-- .../coduo/referencelink/controller/CategoryController.java | 4 ++-- .../site/coduo/referencelink/service/CategoryService.java | 4 ++-- .../referencelink/service/dto/CategoryCreateResponse.java | 7 ++++++- .../referencelink/service/dto/CategoryReadResponse.java | 4 ++-- .../java/site/coduo/acceptance/CategoryAcceptanceTest.java | 2 +- .../coduo/referencelink/service/CategoryServiceTest.java | 4 ++-- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/be_cd-test.yml b/.github/workflows/be_cd-test.yml index eed370ffd..a5abb6271 100644 --- a/.github/workflows/be_cd-test.yml +++ b/.github/workflows/be_cd-test.yml @@ -81,9 +81,9 @@ jobs: DDL_AUTO=${{ secrets.DDL_AUTO }} # OAUTH & JWT - CLIENT_ID=${{ secrets.CLIENT_ID }} - CLIENT_SECRET=${{ secrets.CLIENT_SECRET }} - CLIENT_REDIRECT_URI=${{ secrets.CLIENT_REDIRECT_URI }} + CLIENT_ID=${{ secrets.TEST_CLIENT_ID }} + CLIENT_SECRET=${{ secrets.TEST_CLIENT_SECRET }} + CLIENT_REDIRECT_URI=${{ secrets.TEST_CLIENT_REDIRECT_URI }} JWT_KEY=${{ secrets.JWT_KEY}} # Server App diff --git a/backend/src/main/java/site/coduo/common/config/WebMvcConfig.java b/backend/src/main/java/site/coduo/common/config/WebMvcConfig.java index 54355f7db..b26f3797f 100644 --- a/backend/src/main/java/site/coduo/common/config/WebMvcConfig.java +++ b/backend/src/main/java/site/coduo/common/config/WebMvcConfig.java @@ -22,8 +22,8 @@ public void configurePathMatch(final PathMatchConfigurer configurer) { public void addCorsMappings(final CorsRegistry registry) { registry.addMapping("/**") .allowedMethods("*") - .allowedOrigins("http://localhost:3000", "https://coduo.site", "http://coduo.site:443", - "https://test.coduo.site") + .allowedOrigins("http://localhost:3000", "https://coduo.site", "https://test.coduo.site", + "https://api-test.coduo.site/") .allowCredentials(true); } } diff --git a/backend/src/main/java/site/coduo/referencelink/controller/CategoryController.java b/backend/src/main/java/site/coduo/referencelink/controller/CategoryController.java index 0e5729d3e..19a9d73ba 100644 --- a/backend/src/main/java/site/coduo/referencelink/controller/CategoryController.java +++ b/backend/src/main/java/site/coduo/referencelink/controller/CategoryController.java @@ -58,10 +58,10 @@ public ResponseEntity updateCategory( return ResponseEntity.ok(response); } - @DeleteMapping("/{accessCode}/category/{categoryName}") + @DeleteMapping("/{accessCode}/category/{categoryId}") public ResponseEntity deleteCategory( @PathVariable("accessCode") String accessCode, - @PathVariable("categoryName") Long categoryId + @PathVariable("categoryId") Long categoryId ) { categoryService.deleteCategory(accessCode, categoryId); diff --git a/backend/src/main/java/site/coduo/referencelink/service/CategoryService.java b/backend/src/main/java/site/coduo/referencelink/service/CategoryService.java index 0a4d7aedc..666125cac 100644 --- a/backend/src/main/java/site/coduo/referencelink/service/CategoryService.java +++ b/backend/src/main/java/site/coduo/referencelink/service/CategoryService.java @@ -42,10 +42,10 @@ public List findAllByPairRoomAccessCode(final String acces public CategoryCreateResponse createCategory(final String accessCode, final CategoryCreateRequest request) { final PairRoomEntity pairRoomEntity = pairRoomRepository.fetchByAccessCode(new AccessCode(accessCode)); validateDuplicated(request.value(), pairRoomEntity); - final CategoryEntity saved = categoryRepository.save( + final CategoryEntity categoryEntity = categoryRepository.save( new CategoryEntity(pairRoomEntity, new Category(request.value()))); - return new CategoryCreateResponse(saved.getId(), saved.getCategoryName()); + return CategoryCreateResponse.from(categoryEntity); } private void validateDuplicated(final String categoryName, final PairRoomEntity pairRoomEntity) { diff --git a/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryCreateResponse.java b/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryCreateResponse.java index 8bf1b74fc..47202521d 100644 --- a/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryCreateResponse.java +++ b/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryCreateResponse.java @@ -1,13 +1,18 @@ package site.coduo.referencelink.service.dto; import io.swagger.v3.oas.annotations.media.Schema; +import site.coduo.referencelink.repository.CategoryEntity; @Schema(description = "카테고리 생성 응답") public record CategoryCreateResponse( @Schema(description = "카테고리 ID") - Long id, + String id, @Schema(description = "카테고리 값") String value ) { + + public static CategoryCreateResponse from(final CategoryEntity category) { + return new CategoryCreateResponse(String.valueOf(category.getId()), category.getCategoryName()); + } } diff --git a/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryReadResponse.java b/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryReadResponse.java index 0f05bfcaa..b16851efb 100644 --- a/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryReadResponse.java +++ b/backend/src/main/java/site/coduo/referencelink/service/dto/CategoryReadResponse.java @@ -6,13 +6,13 @@ @Schema(description = "카테고리 조회 응답") public record CategoryReadResponse( @Schema(description = "카테고리 ID", example = "0") - Long id, + String id, @Schema(description = "카테고리 값", example = "카테고리 없음") String value ) { public static CategoryReadResponse from(final CategoryEntity category) { - return new CategoryReadResponse(category.getId(), category.getCategoryName()); + return new CategoryReadResponse(String.valueOf(category.getId()), category.getCategoryName()); } } diff --git a/backend/src/test/java/site/coduo/acceptance/CategoryAcceptanceTest.java b/backend/src/test/java/site/coduo/acceptance/CategoryAcceptanceTest.java index 37bac7b59..5252ebdac 100644 --- a/backend/src/test/java/site/coduo/acceptance/CategoryAcceptanceTest.java +++ b/backend/src/test/java/site/coduo/acceptance/CategoryAcceptanceTest.java @@ -72,7 +72,7 @@ void update_category() { new CategoryCreateRequest("이전 카테고리")); final String updateName = "변경된 카테고리"; - final CategoryUpdateRequest request = new CategoryUpdateRequest(previousCategory.id(), updateName); + final CategoryUpdateRequest request = new CategoryUpdateRequest(Long.parseLong(previousCategory.id()), updateName); //when & then final CategoryUpdateResponse categoryUpdateResponse = RestAssured diff --git a/backend/src/test/java/site/coduo/referencelink/service/CategoryServiceTest.java b/backend/src/test/java/site/coduo/referencelink/service/CategoryServiceTest.java index 663c2f9c9..a0bb90c18 100644 --- a/backend/src/test/java/site/coduo/referencelink/service/CategoryServiceTest.java +++ b/backend/src/test/java/site/coduo/referencelink/service/CategoryServiceTest.java @@ -86,7 +86,7 @@ void update_category() { //when final CategoryUpdateResponse updatedCategory = categoryService.updateCategoryName(ACCESS_CODE.getValue(), - new CategoryUpdateRequest(createdCategory.id(), "파이썬")); + new CategoryUpdateRequest(Long.parseLong(createdCategory.id()), "파이썬")); //then final List categories = categoryService.findAllByPairRoomAccessCode( @@ -144,7 +144,7 @@ void delete_category() { final List beforeDelete = categoryService.findAllByPairRoomAccessCode( ACCESS_CODE.getValue()); - categoryService.deleteCategory(ACCESS_CODE.getValue(), category.id()); + categoryService.deleteCategory(ACCESS_CODE.getValue(), Long.parseLong(category.id())); final List afterDelete = categoryService.findAllByPairRoomAccessCode( ACCESS_CODE.getValue());