Skip to content

Commit

Permalink
docs: url Service에 Swagger 적용한 문서화 진행
Browse files Browse the repository at this point in the history
  • Loading branch information
k000927 committed Aug 20, 2024
1 parent 212c3b6 commit 1628207
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ShortenUrlResponseDto> generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
public ResponseEntity<ShortenUrlResponseDto> 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<Void> redirectOriginalUrl(@PathVariable String encodedId){
public ResponseEntity<Void> redirectOriginalUrl(@PathVariable String encodedId) {
String originalUrl = urlService.getOriginalUrl(encodedId);
return ResponseEntity
.status(HttpStatus.FOUND)
.header("Location", urlService.getOriginalUrl(encodedId))
.header("Location", originalUrl)
.build();
}
}

0 comments on commit 1628207

Please sign in to comment.