From 11d67fc87b8a15e0f12206a44e00aad443cd2083 Mon Sep 17 00:00:00 2001 From: Seokmyung Ham Date: Thu, 1 Aug 2024 18:06:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor(AttendeeController):=20HttpServletResp?= =?UTF-8?q?onse=20=EB=8C=80=EC=8B=A0=20ResponseEntity=EA=B0=80=20=EC=A0=9C?= =?UTF-8?q?=EA=B3=B5=ED=95=98=EB=8A=94=20API=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=BF=A0=ED=82=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attendee/AttendeeController.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java b/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java index a2fc5f346..d6fa0c1e2 100644 --- a/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java +++ b/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java @@ -1,11 +1,12 @@ package kr.momo.controller.attendee; -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import kr.momo.service.attendee.AttendeeService; import kr.momo.service.attendee.dto.AttendeeLoginRequest; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseCookie; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,21 +21,21 @@ public class AttendeeController { private final AttendeeService attendeeService; @PostMapping("/api/v1/meetings/{uuid}/login") - public void login( - @PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request, HttpServletResponse response - ) { + public ResponseEntity login(@PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request) { String token = attendeeService.login(uuid, request); String path = String.format("/api/v1/meetings/%s/", uuid); - Cookie cookie = createCookie(token, path); - response.addCookie(cookie); + return ResponseEntity.ok() + .header(HttpHeaders.SET_COOKIE, createCookie(token, path)) + .build(); } - private Cookie createCookie(String value, String path) { - Cookie cookie = new Cookie(ACCESS_TOKEN, value); - cookie.setHttpOnly(true); - cookie.setSecure(true); - cookie.setPath(path); - return cookie; + private String createCookie(String value, String path) { + return ResponseCookie.from(ACCESS_TOKEN, value) + .httpOnly(true) + .secure(true) + .path(path) + .build() + .toString(); } }