From 1628207e200a5d2daf2b23d7dde0a4a5718d62ab Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 20 Aug 2024 15:13:28 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20url=20Service=EC=97=90=20Swagger=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=ED=95=9C=20=EB=AC=B8=EC=84=9C=ED=99=94=20?= =?UTF-8?q?=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/controller/UrlController.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index 28c1086f..35157526 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -3,6 +3,9 @@ import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; import JGS.CasperEvent.domain.url.service.UrlService; import JGS.CasperEvent.global.entity.BaseUser; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -26,21 +29,31 @@ public UrlController(UrlService urlService) { this.urlService = urlService; } - // 공유링크 생성 + @Operation(summary = "공유 링크 생성", description = "사용자가 공유할 URL을 단축 링크로 생성합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "공유 링크 생성 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터") + }) @PostMapping - public ResponseEntity generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + public ResponseEntity generateShortUrl(HttpServletRequest request) + throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); return ResponseEntity .status(HttpStatus.CREATED) .body(urlService.generateShortUrl(user)); } - // 공유링크 접속 + @Operation(summary = "공유 링크 접속", description = "단축 링크를 통해 원본 URL로 리다이렉트합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "302", description = "리다이렉트 성공"), + @ApiResponse(responseCode = "404", description = "짧은 링크가 존재하지 않음") + }) @GetMapping("/{encodedId}") - public ResponseEntity redirectOriginalUrl(@PathVariable String encodedId){ + public ResponseEntity redirectOriginalUrl(@PathVariable String encodedId) { + String originalUrl = urlService.getOriginalUrl(encodedId); return ResponseEntity .status(HttpStatus.FOUND) - .header("Location", urlService.getOriginalUrl(encodedId)) + .header("Location", originalUrl) .build(); } }