Merge pull request #14 from Gyubin-Han/feature/url-short
Fix: 원본 URL 단축 기능의 요청 구조 변경에 따른 Controller 수정
This commit is contained in:
@@ -9,9 +9,11 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import be.gyu.urlShortener.dto.GenerateShortUrlRequestDto;
|
||||||
import be.gyu.urlShortener.service.MainService;
|
import be.gyu.urlShortener.service.MainService;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
@@ -37,9 +39,9 @@ public class MainController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/short")
|
@PostMapping("/short")
|
||||||
@ResponseBody
|
@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")){
|
if(!resultMap.containsKey("status") || resultMap.get("status").equals("failed")){
|
||||||
resultMap.put("status","failed");
|
resultMap.put("status","failed");
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user