Fix: 원본 URL 단축 기능의 요청 구조 변경에 따른 Controller 수정

This commit is contained in:
Gyubin-Han
2025-06-30 17:57:27 +09:00
parent 04be6194e4
commit 947105ecef
2 changed files with 17 additions and 2 deletions

View File

@@ -9,9 +9,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.UriComponentsBuilder;
import be.gyu.urlShortener.dto.GenerateShortUrlRequestDto;
import be.gyu.urlShortener.service.MainService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -37,9 +39,9 @@ public class MainController {
*/
@PostMapping("/short")
@ResponseBody
public ResponseEntity<Map<String,String>> postGenerateShortUrl(HttpServletRequest request){
public ResponseEntity<Map<String,String>> postGenerateShortUrl(@RequestBody GenerateShortUrlRequestDto data, HttpServletRequest request){
// 서비스 로직 메소드 호출
Map<String,String> resultMap=mainService.generateShortUrl(request.getParameter("url"));
Map<String,String> resultMap=mainService.generateShortUrl(data.getOriginalUrl());
if(!resultMap.containsKey("status") || resultMap.get("status").equals("failed")){
resultMap.put("status","failed");

View File

@@ -0,0 +1,13 @@
package be.gyu.urlShortener.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
// @Setter
@NoArgsConstructor
@AllArgsConstructor
public class GenerateShortUrlRequestDto {
private String originalUrl;
}