From 09a431c7446085bfa2d79d65c77d96fad1c868fc Mon Sep 17 00:00:00 2001 From: jiinkyung Date: Sun, 18 Feb 2024 03:02:24 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MainPageController.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java b/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java index a463d94..35cb5dc 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java @@ -2,8 +2,12 @@ import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO; import com.trendithon.timetris.domain.mainpage.service.MainPageService; +import com.trendithon.timetris.global.auth.jwt.TokenProvider; import com.trendithon.timetris.global.exception.ApiResponse; +import com.trendithon.timetris.global.exception.CustomException; +import com.trendithon.timetris.global.exception.enums.ErrorStatus; import com.trendithon.timetris.global.exception.enums.SuccessStatus; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.GetMapping; @@ -19,13 +23,25 @@ public class MainPageController { private final MainPageService mainPageService; + private final TokenProvider tokenProvider; @GetMapping("/{userId}") public ApiResponse getMainPage(Authentication authentication, - @PathVariable long userId) - { + @PathVariable long userId) { MainPageDTO mainPageDTO = mainPageService.getMainPage(userId); return ApiResponse.success(SuccessStatus.OK, mainPageDTO); } + + @GetMapping + public ApiResponse MainForTest(HttpServletRequest request) { + String userName = (String) request.getSession().getAttribute("name"); + + if (userName == null) { + return ApiResponse.of("LOGIN", "로그인 하세요"); + } else { + return ApiResponse.success(SuccessStatus.OK, userName); + } + + } }