From 0a5e2859a4a39b19f084c471937c66c916a48c46 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Thu, 26 May 2022 15:11:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20v1=20/=20v2=20=EA=B5=AC=EB=B6=84=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xit/Application.java | 2 +- .../ctgy/v2/controller/BoardController.java | 81 +++++++++++++++++++ .../support}/CustomBeanNameGenerator.java | 2 +- .../config/support/SpringDocApiConfig.java | 10 +++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java rename src/main/java/com/xit/core/{api => config/support}/CustomBeanNameGenerator.java (97%) diff --git a/src/main/java/com/xit/Application.java b/src/main/java/com/xit/Application.java index c09cbd9..78457df 100644 --- a/src/main/java/com/xit/Application.java +++ b/src/main/java/com/xit/Application.java @@ -2,7 +2,7 @@ package com.xit; //import com.xit.core.config.ignore.DataJdbcConfig; -import com.xit.core.api.CustomBeanNameGenerator; +import com.xit.core.config.support.CustomBeanNameGenerator; import com.xit.core.oauth2.config.properties.AppProperties; import com.xit.core.oauth2.config.properties.CorsProperties; import com.xit.core.util.Checks; diff --git a/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java b/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java new file mode 100644 index 0000000..0dcc7c9 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java @@ -0,0 +1,81 @@ +package com.xit.biz.ctgy.v2.controller; + +import com.xit.biz.ctgy.dto.BoardDto; +import com.xit.biz.ctgy.service.IBoardService; +import com.xit.core.annotation.Secured; +import com.xit.core.annotation.SecurityPolicy; +import com.xit.core.api.IRestResponse; +import com.xit.core.api.RestResponse; +import com.xit.core.util.AssertUtils; +import com.xit.core.util.Checks; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Nonnull; + +@Tag(name = "BoardController", description = "게시글 관리") +@RestController +@RequestMapping("/api/v2/ctgy/board") +@Validated +@RequiredArgsConstructor +public class BoardController { + + private final IBoardService service; + + + // TODO :: 파라메터 정의 필요 + @Secured(policy = SecurityPolicy.TOKEN) + @Operation(summary = "게시글 목록 조회" , description = "게시글 목록 조회") + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "ciTitle", description = "제목", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "ciName", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), + @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") + }) + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findMinCivBoard680s( + @Parameter(hidden = true) + final BoardDto dto, + @Parameter(hidden = true) + final Pageable pageable) { + return RestResponse.of(service.findAll(dto, pageable)); + } + + @Secured(policy = SecurityPolicy.TOKEN) + @Operation(summary = "게시글 조회수 증가" , description = "게시글 조회수 증가") + @Parameters({ + @Parameter(in = ParameterIn.PATH, name = "ciCode", description = "게시글번호", required = true, example = "18"), + }) + @PutMapping(value = "/hit/{ciCode}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity modifyByCiCode(@PathVariable final Long ciCode) { + return RestResponse.of(service.modifyByCiCode(ciCode)); + } + + @Secured(policy = SecurityPolicy.TOKEN) + @Operation(summary = "게시글 등록" , description = "게시글 등록") + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity saveBoard(BoardDto dto) { + service.saveBoard(dto); + return RestResponse.of(HttpStatus.OK); + } + + @Secured(policy = SecurityPolicy.TOKEN) + @Operation(summary = "게시글 삭제", description = "게시글 삭제") + @PostMapping(value = "/{ciCode}") + public ResponseEntity removeBoard(@PathVariable @Nonnull final Long ciCode) { + AssertUtils.isTrue(!Checks.isEmpty(ciCode), "게시글이 선택되지 않았습니다."); + service.removeBoard(ciCode); + + return RestResponse.of(HttpStatus.OK); + } +} diff --git a/src/main/java/com/xit/core/api/CustomBeanNameGenerator.java b/src/main/java/com/xit/core/config/support/CustomBeanNameGenerator.java similarity index 97% rename from src/main/java/com/xit/core/api/CustomBeanNameGenerator.java rename to src/main/java/com/xit/core/config/support/CustomBeanNameGenerator.java index fc0bb2c..218e40c 100644 --- a/src/main/java/com/xit/core/api/CustomBeanNameGenerator.java +++ b/src/main/java/com/xit/core/config/support/CustomBeanNameGenerator.java @@ -1,4 +1,4 @@ -package com.xit.core.api; +package com.xit.core.config.support; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; diff --git a/src/main/java/com/xit/core/config/support/SpringDocApiConfig.java b/src/main/java/com/xit/core/config/support/SpringDocApiConfig.java index be9eb89..d17cc6a 100644 --- a/src/main/java/com/xit/core/config/support/SpringDocApiConfig.java +++ b/src/main/java/com/xit/core/config/support/SpringDocApiConfig.java @@ -76,6 +76,16 @@ public class SpringDocApiConfig { .build(); } + @Bean + public GroupedOpenApi ctgyBizApiV2() { + return GroupedOpenApi.builder() + .group("1-2. Ctgy-biz-API-v2") + .pathsToMatch( + "/api/v2/ctgy/**" + ) + .build(); + } + @Bean public GroupedOpenApi authorizeApi() { return GroupedOpenApi.builder()