From 2d61d1dd47740e2083ed1a1f8d9c8623f9d4c754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 16 Oct 2023 19:29:48 +0900 Subject: [PATCH] #1 [refactor] Web adapter Annotation Refactoring --- .../src/main/java/com/qdang/adapter/auth/AuthAdapter.java | 4 ++-- .../main/java/com/qdang/adapter/auth/AuthController.java | 2 -- .../main/java/com/qdang/adapter/match/MatchController.java | 2 -- .../main/java/com/qdang/adapter/match/MatchWebAdapter.java | 4 ++-- .../qdang/adapter/noticeboard/NoticeBoardController.java | 2 -- .../qdang/adapter/noticeboard/NoticeBoardWebAdapter.java | 4 ++-- .../main/java/com/qdang/adapter/post/PostController.java | 2 -- .../main/java/com/qdang/adapter/post/PostWebAdapter.java | 4 ++-- .../main/java/com/qdang/adapter/user/UserController.java | 2 -- .../main/java/com/qdang/adapter/user/UserWebAdapter.java | 4 ++-- .../src/main/java/com/qdang/global/http/WebAdapter.java | 7 +++++-- 11 files changed, 15 insertions(+), 22 deletions(-) diff --git a/adapter-web/src/main/java/com/qdang/adapter/auth/AuthAdapter.java b/adapter-web/src/main/java/com/qdang/adapter/auth/AuthAdapter.java index 2dc5b11..0b41f78 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/auth/AuthAdapter.java +++ b/adapter-web/src/main/java/com/qdang/adapter/auth/AuthAdapter.java @@ -5,6 +5,7 @@ import com.qdang.adapter.auth.response.TokenResponse; import com.qdang.application.user.domain.User; import com.qdang.global.argument.AuthUser; +import com.qdang.global.http.WebAdapter; import com.qdang.global.pathmatch.V1; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -17,10 +18,9 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; @V1 -@RequestMapping("/auth") +@WebAdapter(path = "/auth") @SecurityRequirement(name = "JWT Auth") @Tag(name = "Auth", description = "Auth API Document") public interface AuthAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/auth/AuthController.java b/adapter-web/src/main/java/com/qdang/adapter/auth/AuthController.java index cbe90e6..95a1df8 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/auth/AuthController.java +++ b/adapter-web/src/main/java/com/qdang/adapter/auth/AuthController.java @@ -5,7 +5,6 @@ import com.qdang.application.user.port.in.LogoutUseCase; import com.qdang.application.user.port.in.RefreshTokenUseCase; import com.qdang.global.http.HeaderTokenExtractor; -import com.qdang.global.http.WebAdapter; import com.qdang.global.response.HttpResponse; import com.qdang.global.response.SuccessType; import com.qdang.adapter.auth.request.LoginRequest; @@ -18,7 +17,6 @@ import org.springframework.http.ResponseEntity; @Slf4j -@WebAdapter @RequiredArgsConstructor public class AuthController implements AuthAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/match/MatchController.java b/adapter-web/src/main/java/com/qdang/adapter/match/MatchController.java index 69da6d7..e251025 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/match/MatchController.java +++ b/adapter-web/src/main/java/com/qdang/adapter/match/MatchController.java @@ -9,7 +9,6 @@ import com.qdang.application.match.port.in.RecordMatchProcessUseCase; import com.qdang.application.match.port.in.StartMatchUseCase; import com.qdang.application.user.domain.User; -import com.qdang.global.http.WebAdapter; import com.qdang.global.response.HttpResponse; import com.qdang.global.response.SuccessType; import com.qdang.adapter.match.request.StartMatchRequest; @@ -18,7 +17,6 @@ import org.springframework.http.ResponseEntity; @Slf4j -@WebAdapter @RequiredArgsConstructor public class MatchController implements MatchWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/match/MatchWebAdapter.java b/adapter-web/src/main/java/com/qdang/adapter/match/MatchWebAdapter.java index 173cc6c..bb6b1fb 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/match/MatchWebAdapter.java +++ b/adapter-web/src/main/java/com/qdang/adapter/match/MatchWebAdapter.java @@ -7,6 +7,7 @@ import com.qdang.adapter.match.response.StartMatchResponse; import com.qdang.application.user.domain.User; import com.qdang.global.argument.AuthUser; +import com.qdang.global.http.WebAdapter; import com.qdang.global.pathmatch.V1; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -18,10 +19,9 @@ 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.RequestMapping; @V1 -@RequestMapping("/matches") +@WebAdapter(path = "/matches") @SecurityRequirement(name = "JWT Auth") @Tag(name = "Match", description = "Match API Document") public interface MatchWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardController.java b/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardController.java index 39fed8c..2cbd59f 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardController.java +++ b/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardController.java @@ -5,7 +5,6 @@ import com.qdang.application.noticeboard.port.in.GetNoticeBoardPinnedListUseCase; import com.qdang.application.noticeboard.port.in.PinNoticeBoardUseCase; import com.qdang.application.user.domain.User; -import com.qdang.global.http.WebAdapter; import com.qdang.global.response.HttpResponse; import com.qdang.global.response.SuccessType; import lombok.RequiredArgsConstructor; @@ -13,7 +12,6 @@ import org.springframework.http.ResponseEntity; @Slf4j -@WebAdapter @RequiredArgsConstructor public class NoticeBoardController implements NoticeBoardWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardWebAdapter.java b/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardWebAdapter.java index c4ba4f1..5fd0177 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardWebAdapter.java +++ b/adapter-web/src/main/java/com/qdang/adapter/noticeboard/NoticeBoardWebAdapter.java @@ -4,6 +4,7 @@ import com.qdang.adapter.noticeboard.response.GetNoticeBoardListResponse; import com.qdang.application.user.domain.User; import com.qdang.global.argument.AuthUser; +import com.qdang.global.http.WebAdapter; import com.qdang.global.pathmatch.V1; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -14,10 +15,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; @V1 -@RequestMapping("/notice-boards") +@WebAdapter(path = "/notice-boards") @SecurityRequirement(name = "JWT Auth") @Tag(name = "Notice Board", description = "Notice Board API Document") public interface NoticeBoardWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/post/PostController.java b/adapter-web/src/main/java/com/qdang/adapter/post/PostController.java index b9c05ca..146b6e3 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/post/PostController.java +++ b/adapter-web/src/main/java/com/qdang/adapter/post/PostController.java @@ -1,11 +1,9 @@ package com.qdang.adapter.post; -import com.qdang.global.http.WebAdapter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @Slf4j -@WebAdapter @RequiredArgsConstructor public class PostController implements PostWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/post/PostWebAdapter.java b/adapter-web/src/main/java/com/qdang/adapter/post/PostWebAdapter.java index 5aa101d..22e9c29 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/post/PostWebAdapter.java +++ b/adapter-web/src/main/java/com/qdang/adapter/post/PostWebAdapter.java @@ -1,12 +1,12 @@ package com.qdang.adapter.post; +import com.qdang.global.http.WebAdapter; import com.qdang.global.pathmatch.V1; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.RequestMapping; @V1 -@RequestMapping("/posts") +@WebAdapter(path = "/posts") @SecurityRequirement(name = "JWT Auth") @Tag(name = "Post", description = "Post API Document") public interface PostWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/user/UserController.java b/adapter-web/src/main/java/com/qdang/adapter/user/UserController.java index d39758e..7c27861 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/user/UserController.java +++ b/adapter-web/src/main/java/com/qdang/adapter/user/UserController.java @@ -7,7 +7,6 @@ import com.qdang.application.user.domain.User; import com.qdang.application.user.port.in.GetUserProfileUseCase; import com.qdang.application.user.port.in.SearchUserByUsernameUseCase; -import com.qdang.global.http.WebAdapter; import com.qdang.global.response.HttpResponse; import com.qdang.global.response.SuccessType; import com.qdang.adapter.user.request.UpdateUserProfileRequest; @@ -19,7 +18,6 @@ import org.springframework.http.ResponseEntity; @Slf4j -@WebAdapter @RequiredArgsConstructor public class UserController implements UserWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/adapter/user/UserWebAdapter.java b/adapter-web/src/main/java/com/qdang/adapter/user/UserWebAdapter.java index d6b1f9c..f78b6a6 100644 --- a/adapter-web/src/main/java/com/qdang/adapter/user/UserWebAdapter.java +++ b/adapter-web/src/main/java/com/qdang/adapter/user/UserWebAdapter.java @@ -7,6 +7,7 @@ import com.qdang.adapter.user.response.UserValidationResponse; import com.qdang.application.user.domain.User; import com.qdang.global.argument.AuthUser; +import com.qdang.global.http.WebAdapter; import com.qdang.global.pathmatch.V1; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -17,11 +18,10 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @V1 -@RequestMapping("/users") +@WebAdapter(path = "/users") @SecurityRequirement(name = "JWT Auth") @Tag(name = "User", description = "User API Document") public interface UserWebAdapter { diff --git a/adapter-web/src/main/java/com/qdang/global/http/WebAdapter.java b/adapter-web/src/main/java/com/qdang/global/http/WebAdapter.java index bb160bc..d560fca 100644 --- a/adapter-web/src/main/java/com/qdang/global/http/WebAdapter.java +++ b/adapter-web/src/main/java/com/qdang/global/http/WebAdapter.java @@ -1,21 +1,24 @@ package com.qdang.global.http; -import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@Documented @Component @ResponseBody +@RequestMapping public @interface WebAdapter { @AliasFor(annotation = Component.class) String value() default ""; + + @AliasFor(annotation = RequestMapping.class, attribute = "path") + String path() default ""; }