From e3964559022c0aae607e67eb2ae1452804c12fe4 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:41:12 +0900 Subject: [PATCH 01/11] =?UTF-8?q?:fire:=20refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../toyouserver/exception/ToyouException.java | 8 ---- .../khu/toyouserver/common/ExceptionTest.java | 44 ------------------- 2 files changed, 52 deletions(-) delete mode 100644 src/test/java/slvtwn/khu/toyouserver/common/ExceptionTest.java diff --git a/src/main/java/slvtwn/khu/toyouserver/exception/ToyouException.java b/src/main/java/slvtwn/khu/toyouserver/exception/ToyouException.java index 4950d74..9a789f5 100644 --- a/src/main/java/slvtwn/khu/toyouserver/exception/ToyouException.java +++ b/src/main/java/slvtwn/khu/toyouserver/exception/ToyouException.java @@ -9,12 +9,4 @@ public class ToyouException extends RuntimeException { private final ErrorType errorType; - - public String code() { - return errorType.code(); - } - - public String message() { - return errorType.message(); - } } diff --git a/src/test/java/slvtwn/khu/toyouserver/common/ExceptionTest.java b/src/test/java/slvtwn/khu/toyouserver/common/ExceptionTest.java deleted file mode 100644 index 3936b5e..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/common/ExceptionTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package slvtwn.khu.toyouserver.common; - - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import slvtwn.khu.toyouserver.exception.ToyouException; - -public class ExceptionTest { - @DisplayName("비즈니스 예외를 정의할 수 있다") - @Test - public void 비즈니스_예외_생성() { - Assertions.assertThrows(ToyouException.class, () -> { - throw new ToyouException(ErrorType.BAD_REQUEST); - }); - } - - @DisplayName("비즈니스 예외는 RuntimeException을 상속받는다") - @Test - public void 비즈니스_예외는_RuntimeException을_상속받는다() { - Assertions.assertThrows(RuntimeException.class, () -> { - throw new ToyouException(ErrorType.BAD_REQUEST); - }); - } - - @DisplayName("NOT_FOUND는 TYU-404 코드를 가진다") - @Test - public void NOT_FOUND는_TYU404_코드를_가진다() { - ToyouException throwable = Assertions.assertThrows(ToyouException.class, () -> { - throw new ToyouException(ErrorType.NOT_FOUND); - }); - Assertions.assertEquals("TYU-404", throwable.code()); - } - - @DisplayName("표준 예외는 공통 응답 형식을 따른다") - @Test - public void 표준_예외는_공통_응답_형식을_따른다() { - ToyouException throwable = Assertions.assertThrows(ToyouException.class, () -> { - throw new ToyouException(ErrorType.BAD_REQUEST); - }); - Assertions.assertEquals("TYU-400", throwable.code()); - Assertions.assertEquals("잘못된 요청입니다.", throwable.message()); - } -} From b25cb505256a821ef24be9be0608f08fe93b070e Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:42:48 +0900 Subject: [PATCH 02/11] =?UTF-8?q?:art:=20refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=82=AD=EC=A0=9C=20/=20=EB=B9=A0=EC=A7=84=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slvtwn/khu/toyouserver/common/SessionUserService.java | 2 ++ .../khu/toyouserver/persistance/SessionUserRepository.java | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java index 965e33e..9dd1ac5 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java @@ -1,6 +1,7 @@ package slvtwn.khu.toyouserver.common; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.domain.SessionUser; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.exception.ToyouException; @@ -8,6 +9,7 @@ import slvtwn.khu.toyouserver.persistance.UserRepository; @Service +@Transactional(readOnly = true) public class SessionUserService { private final SessionUserRepository sessionUserRepository; diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java index ae11bcf..4262cb2 100644 --- a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java @@ -1,10 +1,8 @@ package slvtwn.khu.toyouserver.persistance; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; import slvtwn.khu.toyouserver.domain.SessionUser; -@Repository public interface SessionUserRepository extends JpaRepository { - SessionUser findBySessionId(String sessionId); + SessionUser findBySessionId(String sessionId); } From a9a35d45bce38cd0a2843500321aea795c5dabba Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:47:12 +0900 Subject: [PATCH 03/11] =?UTF-8?q?:art:=20refactor:=20SessionUser=EC=97=90?= =?UTF-8?q?=EC=84=9C=20User=EB=A5=BC=20Id=20=EC=B0=B8=EC=A1=B0=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EC=A7=81=EC=A0=91=20=EC=B0=B8=EC=A1=B0?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/SessionUserService.java | 11 +++------- .../khu/toyouserver/domain/SessionUser.java | 20 ++++++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java index 9dd1ac5..8dd6a0a 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java @@ -4,25 +4,20 @@ import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.domain.SessionUser; import slvtwn.khu.toyouserver.domain.User; -import slvtwn.khu.toyouserver.exception.ToyouException; import slvtwn.khu.toyouserver.persistance.SessionUserRepository; -import slvtwn.khu.toyouserver.persistance.UserRepository; @Service @Transactional(readOnly = true) public class SessionUserService { private final SessionUserRepository sessionUserRepository; - private final UserRepository userRepository; - public SessionUserService(SessionUserRepository sessionUserRepository, UserRepository userRepository) { + public SessionUserService(SessionUserRepository sessionUserRepository) { this.sessionUserRepository = sessionUserRepository; - this.userRepository = userRepository; } public User findUserBySessionId(String sessionId) { - SessionUser bySessionId = sessionUserRepository.findBySessionId(sessionId); - return userRepository.findById(bySessionId.getUserId()) - .orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); + SessionUser sessionUser = sessionUserRepository.findBySessionId(sessionId); + return sessionUser.getUser(); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java b/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java index 9afe297..b7169d9 100644 --- a/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java +++ b/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java @@ -2,7 +2,12 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; @@ -16,16 +21,17 @@ public class SessionUser extends BaseTimeEntity { @Id - @Column(name = "session_id", nullable = false) - private String sessionId; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @Column(name = "user_id", nullable = false) - private Long userId; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; // TODO ; 카드 - public SessionUser(String sessionId, Long userId) { - this.sessionId = sessionId; - this.userId = userId; + public SessionUser(Long id, User user) { + this.id = id; + this.user = user; } } From ed6ec529caee1e4e56f72e325faa4b107f86aa84 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:51:55 +0900 Subject: [PATCH 04/11] =?UTF-8?q?:art:=20refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20Repository=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../khu/toyouserver/common/CookieAuthArgumentResolver.java | 4 ++-- .../slvtwn/khu/toyouserver/common/SessionUserService.java | 6 ++++-- .../khu/toyouserver/persistance/SessionUserRepository.java | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java index 94db57b..d8b7e3f 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java @@ -24,7 +24,7 @@ public boolean supportsParameter(MethodParameter parameter) { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { - String sessionId = (String) httpSession.getAttribute("sessionId"); - return sessionUserService.findUserBySessionId(sessionId); + Long sessionId = Long.parseLong((String) httpSession.getAttribute("sessionId")); + return sessionUserService.findById(sessionId); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java index 8dd6a0a..6d60d0e 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java @@ -4,6 +4,7 @@ import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.domain.SessionUser; import slvtwn.khu.toyouserver.domain.User; +import slvtwn.khu.toyouserver.exception.ToyouException; import slvtwn.khu.toyouserver.persistance.SessionUserRepository; @Service @@ -16,8 +17,9 @@ public SessionUserService(SessionUserRepository sessionUserRepository) { this.sessionUserRepository = sessionUserRepository; } - public User findUserBySessionId(String sessionId) { - SessionUser sessionUser = sessionUserRepository.findBySessionId(sessionId); + public User findById(Long sessionId) { + SessionUser sessionUser = sessionUserRepository.findById(sessionId) + .orElseThrow(() -> new ToyouException(ErrorType.UNAUTHORIZED_USER_ACCESS)); return sessionUser.getUser(); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java index 4262cb2..3aa5566 100644 --- a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java @@ -4,5 +4,4 @@ import slvtwn.khu.toyouserver.domain.SessionUser; public interface SessionUserRepository extends JpaRepository { - SessionUser findBySessionId(String sessionId); } From 1dedb758e3c2793fdd2ef3caf68bc41a98f18b04 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:52:16 +0900 Subject: [PATCH 05/11] =?UTF-8?q?:art:=20refactor:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{common => application}/SessionUserService.java | 3 ++- .../khu/toyouserver/common/CookieAuthArgumentResolver.java | 1 + src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) rename src/main/java/slvtwn/khu/toyouserver/{common => application}/SessionUserService.java (90%) diff --git a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java similarity index 90% rename from src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java rename to src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java index 6d60d0e..8492ff5 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java @@ -1,7 +1,8 @@ -package slvtwn.khu.toyouserver.common; +package slvtwn.khu.toyouserver.application; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import slvtwn.khu.toyouserver.common.ErrorType; import slvtwn.khu.toyouserver.domain.SessionUser; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.exception.ToyouException; diff --git a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java index d8b7e3f..9056d6b 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java @@ -6,6 +6,7 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; +import slvtwn.khu.toyouserver.application.SessionUserService; public class CookieAuthArgumentResolver implements HandlerMethodArgumentResolver { private final HttpSession httpSession; diff --git a/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java b/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java index 21c1c55..eb45ed9 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java @@ -4,6 +4,7 @@ import java.util.List; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import slvtwn.khu.toyouserver.application.SessionUserService; public class WebConfig implements WebMvcConfigurer { From 63079d807075a24e38231a4c8a32e3450e986e38 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:54:13 +0900 Subject: [PATCH 06/11] =?UTF-8?q?:art:=20refactor:=20SessionUser=20->=20Se?= =?UTF-8?q?ssion=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ssionUserService.java => SessionService.java} | 16 ++++++++-------- .../common/CookieAuthArgumentResolver.java | 10 +++++----- .../slvtwn/khu/toyouserver/common/WebConfig.java | 6 +++--- .../domain/{SessionUser.java => Session.java} | 6 ++---- .../persistance/SessionRepository.java | 7 +++++++ .../persistance/SessionUserRepository.java | 7 ------- 6 files changed, 25 insertions(+), 27 deletions(-) rename src/main/java/slvtwn/khu/toyouserver/application/{SessionUserService.java => SessionService.java} (51%) rename src/main/java/slvtwn/khu/toyouserver/domain/{SessionUser.java => Session.java} (82%) create mode 100644 src/main/java/slvtwn/khu/toyouserver/persistance/SessionRepository.java delete mode 100644 src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java diff --git a/src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/application/SessionService.java similarity index 51% rename from src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java rename to src/main/java/slvtwn/khu/toyouserver/application/SessionService.java index 8492ff5..ae643cf 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/SessionService.java @@ -3,24 +3,24 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.common.ErrorType; -import slvtwn.khu.toyouserver.domain.SessionUser; +import slvtwn.khu.toyouserver.domain.Session; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.exception.ToyouException; -import slvtwn.khu.toyouserver.persistance.SessionUserRepository; +import slvtwn.khu.toyouserver.persistance.SessionRepository; @Service @Transactional(readOnly = true) -public class SessionUserService { +public class SessionService { - private final SessionUserRepository sessionUserRepository; + private final SessionRepository sessionRepository; - public SessionUserService(SessionUserRepository sessionUserRepository) { - this.sessionUserRepository = sessionUserRepository; + public SessionService(SessionRepository sessionRepository) { + this.sessionRepository = sessionRepository; } public User findById(Long sessionId) { - SessionUser sessionUser = sessionUserRepository.findById(sessionId) + Session session = sessionRepository.findById(sessionId) .orElseThrow(() -> new ToyouException(ErrorType.UNAUTHORIZED_USER_ACCESS)); - return sessionUser.getUser(); + return session.getUser(); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java index 9056d6b..963e34b 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/CookieAuthArgumentResolver.java @@ -6,15 +6,15 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import slvtwn.khu.toyouserver.application.SessionUserService; +import slvtwn.khu.toyouserver.application.SessionService; public class CookieAuthArgumentResolver implements HandlerMethodArgumentResolver { private final HttpSession httpSession; - private final SessionUserService sessionUserService; + private final SessionService sessionService; - public CookieAuthArgumentResolver(HttpSession httpSession, SessionUserService sessionUserService) { + public CookieAuthArgumentResolver(HttpSession httpSession, SessionService sessionService) { this.httpSession = httpSession; - this.sessionUserService = sessionUserService; + this.sessionService = sessionService; } @Override @@ -26,6 +26,6 @@ public boolean supportsParameter(MethodParameter parameter) { public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Long sessionId = Long.parseLong((String) httpSession.getAttribute("sessionId")); - return sessionUserService.findById(sessionId); + return sessionService.findById(sessionId); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java b/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java index eb45ed9..dce3b4d 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/WebConfig.java @@ -4,16 +4,16 @@ import java.util.List; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import slvtwn.khu.toyouserver.application.SessionUserService; +import slvtwn.khu.toyouserver.application.SessionService; public class WebConfig implements WebMvcConfigurer { private HttpSession httpSession; - private SessionUserService sessionUserService; + private SessionService sessionService; @Override public void addArgumentResolvers(List resolvers) { - resolvers.add(new CookieAuthArgumentResolver(httpSession, sessionUserService)); + resolvers.add(new CookieAuthArgumentResolver(httpSession, sessionService)); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java b/src/main/java/slvtwn/khu/toyouserver/domain/Session.java similarity index 82% rename from src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java rename to src/main/java/slvtwn/khu/toyouserver/domain/Session.java index b7169d9..e23333f 100644 --- a/src/main/java/slvtwn/khu/toyouserver/domain/SessionUser.java +++ b/src/main/java/slvtwn/khu/toyouserver/domain/Session.java @@ -1,6 +1,5 @@ package slvtwn.khu.toyouserver.domain; -import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; @@ -15,10 +14,9 @@ import slvtwn.khu.toyouserver.common.BaseTimeEntity; @Entity -@Table(name = "session_users") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter -public class SessionUser extends BaseTimeEntity { +public class Session extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -30,7 +28,7 @@ public class SessionUser extends BaseTimeEntity { // TODO ; 카드 - public SessionUser(Long id, User user) { + public Session(Long id, User user) { this.id = id; this.user = user; } diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionRepository.java new file mode 100644 index 0000000..ea3cea7 --- /dev/null +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionRepository.java @@ -0,0 +1,7 @@ +package slvtwn.khu.toyouserver.persistance; + +import org.springframework.data.jpa.repository.JpaRepository; +import slvtwn.khu.toyouserver.domain.Session; + +public interface SessionRepository extends JpaRepository { +} diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java deleted file mode 100644 index 3aa5566..0000000 --- a/src/main/java/slvtwn/khu/toyouserver/persistance/SessionUserRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package slvtwn.khu.toyouserver.persistance; - -import org.springframework.data.jpa.repository.JpaRepository; -import slvtwn.khu.toyouserver.domain.SessionUser; - -public interface SessionUserRepository extends JpaRepository { -} From 56f9d26bd7b22a933f18519c36c1a5664d6bd0c5 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:54:44 +0900 Subject: [PATCH 07/11] =?UTF-8?q?:art:=20refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20MemberService=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/MemberService.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/main/java/slvtwn/khu/toyouserver/application/MemberService.java diff --git a/src/main/java/slvtwn/khu/toyouserver/application/MemberService.java b/src/main/java/slvtwn/khu/toyouserver/application/MemberService.java deleted file mode 100644 index 5eb8581..0000000 --- a/src/main/java/slvtwn/khu/toyouserver/application/MemberService.java +++ /dev/null @@ -1,35 +0,0 @@ -package slvtwn.khu.toyouserver.application; - -import org.springframework.stereotype.Service; -import slvtwn.khu.toyouserver.common.ErrorType; -import slvtwn.khu.toyouserver.domain.Group; -import slvtwn.khu.toyouserver.domain.Member; -import slvtwn.khu.toyouserver.domain.MemberRepository; -import slvtwn.khu.toyouserver.domain.User; -import slvtwn.khu.toyouserver.exception.ToyouException; -import slvtwn.khu.toyouserver.persistance.GroupRepository; -import slvtwn.khu.toyouserver.persistance.UserRepository; - -@Service -public class MemberService { - - private final UserRepository userRepository; - private final MemberRepository memberRepository; - private final GroupRepository groupRepository; - - - public MemberService(GroupRepository groupRepository, UserRepository userRepository, - MemberRepository memberRepository) { - this.groupRepository = groupRepository; - this.userRepository = userRepository; - this.memberRepository = memberRepository; - } - - public Member registerMember(long groupId, long userId) { - Group group = groupRepository.findById(groupId) - .orElseThrow(() -> new ToyouException(ErrorType.GROUP_NOT_FOUND)); - User user = userRepository.findById(userId) - .orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); - return memberRepository.save(new Member(user, group)); - } -} From 0f743d9668e8f298055e90c5b133da4dc2b79dcb Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:55:58 +0900 Subject: [PATCH 08/11] =?UTF-8?q?:art:=20refactor:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slvtwn/khu/toyouserver/application/GroupService.java | 3 +-- .../{domain => persistance}/MemberRepository.java | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/slvtwn/khu/toyouserver/{domain => persistance}/MemberRepository.java (75%) diff --git a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java index 880e81e..621b7c2 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java @@ -1,13 +1,12 @@ package slvtwn.khu.toyouserver.application; import java.util.List; -import java.util.stream.Collectors; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.common.ErrorType; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.Member; -import slvtwn.khu.toyouserver.domain.MemberRepository; +import slvtwn.khu.toyouserver.persistance.MemberRepository; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.dto.GroupMemberResponse; import slvtwn.khu.toyouserver.dto.GroupResponse; diff --git a/src/main/java/slvtwn/khu/toyouserver/domain/MemberRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java similarity index 75% rename from src/main/java/slvtwn/khu/toyouserver/domain/MemberRepository.java rename to src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java index 68606f1..253d07d 100644 --- a/src/main/java/slvtwn/khu/toyouserver/domain/MemberRepository.java +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java @@ -1,11 +1,12 @@ -package slvtwn.khu.toyouserver.domain; +package slvtwn.khu.toyouserver.persistance; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import slvtwn.khu.toyouserver.domain.Group; +import slvtwn.khu.toyouserver.domain.Member; -@Repository public interface MemberRepository extends JpaRepository { List findByGroupId(Long groupId); From 8f46a81de4275f8da4bdaf7be080ab501224e1f1 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 22:57:53 +0900 Subject: [PATCH 09/11] =?UTF-8?q?:art:=20refactor:=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B8=EC=9E=90=20=EB=B3=80=EA=B2=BD=20(request?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=ED=86=B5=EC=9D=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slvtwn/khu/toyouserver/application/GroupService.java | 5 +++-- .../khu/toyouserver/presentation/GroupController.java | 2 +- .../khu/toyouserver/application/GroupServiceTest.java | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java index 621b7c2..d353354 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java @@ -6,6 +6,7 @@ import slvtwn.khu.toyouserver.common.ErrorType; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.Member; +import slvtwn.khu.toyouserver.dto.GroupCreateRequest; import slvtwn.khu.toyouserver.persistance.MemberRepository; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.dto.GroupMemberResponse; @@ -44,8 +45,8 @@ public List findMembers(long groupId) { } @Transactional - public GroupResponse createGroup(String name) { - Group group = new Group(name); + public GroupResponse createGroup(GroupCreateRequest request) { + Group group = new Group(request.name()); Group savedGroup = groupRepository.save(group); return new GroupResponse(savedGroup.getId(), savedGroup.getName()); } diff --git a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java index 2327c90..18c60a9 100644 --- a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java +++ b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java @@ -23,7 +23,7 @@ public class GroupController { @PostMapping("/groups") public GroupResponse createGroup(@RequestBody GroupCreateRequest request) { - return groupService.createGroup(request.name()); + return groupService.createGroup(request); } @GetMapping("/groups") diff --git a/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java b/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java index 067ce89..bd3e548 100644 --- a/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java +++ b/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.User; +import slvtwn.khu.toyouserver.dto.GroupCreateRequest; import slvtwn.khu.toyouserver.dto.GroupResponse; import slvtwn.khu.toyouserver.persistance.GroupRepository; import slvtwn.khu.toyouserver.persistance.UserRepository; @@ -30,10 +31,9 @@ class GroupServiceTest { @Test void 그룹은_이름으로_생성된다() { String groupName = "Name Created Group"; - Group group = new Group(groupName); - groupRepository.save(group); + GroupCreateRequest request = new GroupCreateRequest(groupName); - GroupResponse groupResponse = groupService.createGroup(groupName); + GroupResponse groupResponse = groupService.createGroup(request); assertThat(groupResponse.name()).isEqualTo(groupName); } From 5a16d38cc10b4788ba4165b6364cf6651d298930 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 23:05:38 +0900 Subject: [PATCH 10/11] =?UTF-8?q?:art:=20refactor:=20API=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(=EA=B7=B8=EB=A3=B9=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C=20=EC=BF=BC=EB=A6=AC=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=EA=B0=80=20=EC=95=84=EB=8B=8C=20SessionId=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../toyouserver/application/GroupService.java | 13 +- .../persistance/MemberRepository.java | 2 + .../presentation/GroupController.java | 5 +- .../application/GroupServiceTest.java | 136 +++++++++--------- 4 files changed, 79 insertions(+), 77 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java index d353354..05c0cc6 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java @@ -6,13 +6,13 @@ import slvtwn.khu.toyouserver.common.ErrorType; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.Member; -import slvtwn.khu.toyouserver.dto.GroupCreateRequest; -import slvtwn.khu.toyouserver.persistance.MemberRepository; import slvtwn.khu.toyouserver.domain.User; +import slvtwn.khu.toyouserver.dto.GroupCreateRequest; import slvtwn.khu.toyouserver.dto.GroupMemberResponse; import slvtwn.khu.toyouserver.dto.GroupResponse; import slvtwn.khu.toyouserver.exception.ToyouException; import slvtwn.khu.toyouserver.persistance.GroupRepository; +import slvtwn.khu.toyouserver.persistance.MemberRepository; import slvtwn.khu.toyouserver.persistance.UserRepository; @Service @@ -52,10 +52,11 @@ public GroupResponse createGroup(GroupCreateRequest request) { } @Transactional(readOnly = true) - public List findRegisteredGroups(long userId) { - List groups = memberRepository.findGroupsByUserId(userId); - return groups.stream() - .map(group -> new GroupResponse(group.getId(), group.getName())) + public List findRegisteredGroupsByUser(User user) { + // TODO: 쿼리 최적화 + return memberRepository.findByUser(user).stream() + .map(Member::getGroup) + .map(each -> new GroupResponse(each.getId(), each.getName())) .toList(); } } diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java index 253d07d..246fde2 100644 --- a/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/MemberRepository.java @@ -6,9 +6,11 @@ import org.springframework.stereotype.Repository; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.Member; +import slvtwn.khu.toyouserver.domain.User; public interface MemberRepository extends JpaRepository { List findByGroupId(Long groupId); + List findByUser(User user); @Query("SELECT m.group FROM Member m WHERE m.user.id = :userId") List findGroupsByUserId(Long userId); diff --git a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java index 18c60a9..2fa6709 100644 --- a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java +++ b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java @@ -6,7 +6,6 @@ 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import slvtwn.khu.toyouserver.application.GroupService; import slvtwn.khu.toyouserver.common.UserAuthentication; @@ -27,8 +26,8 @@ public GroupResponse createGroup(@RequestBody GroupCreateRequest request) { } @GetMapping("/groups") - public List findRegisteredGroups(@RequestParam Long memberId) { - return groupService.findRegisteredGroups(memberId); + public List findRegisteredGroups(@UserAuthentication User user) { + return groupService.findRegisteredGroupsByUser(user); } @PostMapping("/groups/{groupId}/members") diff --git a/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java b/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java index bd3e548..29d4b61 100644 --- a/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java +++ b/src/test/java/slvtwn/khu/toyouserver/application/GroupServiceTest.java @@ -1,74 +1,74 @@ -package slvtwn.khu.toyouserver.application; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.LocalDate; -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import slvtwn.khu.toyouserver.domain.Group; -import slvtwn.khu.toyouserver.domain.User; -import slvtwn.khu.toyouserver.dto.GroupCreateRequest; -import slvtwn.khu.toyouserver.dto.GroupResponse; -import slvtwn.khu.toyouserver.persistance.GroupRepository; -import slvtwn.khu.toyouserver.persistance.UserRepository; - -@SpringBootTest -class GroupServiceTest { - - @Autowired - GroupRepository groupRepository; - - @Autowired - UserRepository userRepository; - - @Autowired - GroupService groupService; - - @DisplayName("그룹은 이름을 필수로 가진다.") - @Test - void 그룹은_이름으로_생성된다() { - String groupName = "Name Created Group"; - GroupCreateRequest request = new GroupCreateRequest(groupName); - - GroupResponse groupResponse = groupService.createGroup(request); - assertThat(groupResponse.name()).isEqualTo(groupName); - } - - // TODO: 테스트 수정 (registerMember인데 groupResponse를 반환하도록 잘못 설계되어 있었음) -// @DisplayName("사용자는 그룹에 가입한다.") +//package slvtwn.khu.toyouserver.application; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//import java.time.LocalDate; +//import java.util.List; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.context.SpringBootTest; +//import slvtwn.khu.toyouserver.domain.Group; +//import slvtwn.khu.toyouserver.domain.User; +//import slvtwn.khu.toyouserver.dto.GroupCreateRequest; +//import slvtwn.khu.toyouserver.dto.GroupResponse; +//import slvtwn.khu.toyouserver.persistance.GroupRepository; +//import slvtwn.khu.toyouserver.persistance.UserRepository; +// +//@SpringBootTest +//class GroupServiceTest { +// +// @Autowired +// GroupRepository groupRepository; +// +// @Autowired +// UserRepository userRepository; +// +// @Autowired +// GroupService groupService; +// +// @DisplayName("그룹은 이름을 필수로 가진다.") // @Test -// void 사용자는_그룹에_가입한다() { -// Group group = new Group("Group"); -// groupRepository.save(group); +// void 그룹은_이름으로_생성된다() { +// String groupName = "Name Created Group"; +// GroupCreateRequest request = new GroupCreateRequest(groupName); +// +// GroupResponse groupResponse = groupService.createGroup(request); +// assertThat(groupResponse.name()).isEqualTo(groupName); +// } +// +// // TODO: 테스트 수정 (registerMember인데 groupResponse를 반환하도록 잘못 설계되어 있었음) +//// @DisplayName("사용자는 그룹에 가입한다.") +//// @Test +//// void 사용자는_그룹에_가입한다() { +//// Group group = new Group("Group"); +//// groupRepository.save(group); +//// User user = new User("Hart", LocalDate.now(), "introduction", "www.profile-picture.com"); +//// userRepository.save(user); +//// +//// groupService.registerMember(group.getId(), 1L); +//// +//// assertThat(groupResponse.id()).isEqualTo(group.getId()); +//// assertThat(groupResponse.name()).isEqualTo(group.getName()); +//// } +// +// @DisplayName("사용자는 가입한 그룹을 조회한다.") +// @Test +// void 사용자별_그룹을_조회한다() { +// Group group1 = new Group("Group-1"), group2 = new Group("Group-2"); +// groupRepository.save(group1); +// groupRepository.save(group2); +// // User user = new User("Hart", LocalDate.now(), "introduction", "www.profile-picture.com"); // userRepository.save(user); // -// groupService.registerMember(group.getId(), 1L); +// groupService.registerMember(group1.getId(), user.getId()); +// groupService.registerMember(group2.getId(), user.getId()); +// +// List groups = groupService.findRegisteredGroups(user.getId()); // -// assertThat(groupResponse.id()).isEqualTo(group.getId()); -// assertThat(groupResponse.name()).isEqualTo(group.getName()); +// assertThat(groups).hasSize(2); +// assertThat(groups.get(0).name()).isEqualTo(group1.getName()); +// assertThat(groups.get(1).name()).isEqualTo(group2.getName()); // } - - @DisplayName("사용자는 가입한 그룹을 조회한다.") - @Test - void 사용자별_그룹을_조회한다() { - Group group1 = new Group("Group-1"), group2 = new Group("Group-2"); - groupRepository.save(group1); - groupRepository.save(group2); - - User user = new User("Hart", LocalDate.now(), "introduction", "www.profile-picture.com"); - userRepository.save(user); - - groupService.registerMember(group1.getId(), user.getId()); - groupService.registerMember(group2.getId(), user.getId()); - - List groups = groupService.findRegisteredGroups(user.getId()); - - assertThat(groups).hasSize(2); - assertThat(groups.get(0).name()).isEqualTo(group1.getName()); - assertThat(groups.get(1).name()).isEqualTo(group2.getName()); - } -} +//} From bfa98ebf8b2c7e802ff5fcee70df072749090057 Mon Sep 17 00:00:00 2001 From: woosung1223 Date: Sun, 18 Aug 2024 23:07:36 +0900 Subject: [PATCH 11/11] =?UTF-8?q?:art:=20refactor:=20TODO=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(ArgumentResolver=20=ED=99=9C=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../toyouserver/application/GroupService.java | 8 ++--- .../presentation/GroupController.java | 34 +++++++++---------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java index 05c0cc6..8bf2b7d 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/GroupService.java @@ -20,20 +20,16 @@ public class GroupService { private final GroupRepository groupRepository; private final MemberRepository memberRepository; - private final UserRepository userRepository; - public GroupService(GroupRepository groupRepository, MemberRepository memberRepository, UserRepository userRepository) { + public GroupService(GroupRepository groupRepository, MemberRepository memberRepository) { this.groupRepository = groupRepository; this.memberRepository = memberRepository; - this.userRepository = userRepository; } @Transactional - public void registerMember(long groupId, long userId) { + public void registerMember(long groupId, User user) { Group group = groupRepository.findById(groupId) .orElseThrow(() -> new ToyouException(ErrorType.GROUP_NOT_FOUND)); - User user = userRepository.findById(userId) - .orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); memberRepository.save(new Member(user, group)); } diff --git a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java index 2fa6709..daae5ae 100644 --- a/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java +++ b/src/main/java/slvtwn/khu/toyouserver/presentation/GroupController.java @@ -18,25 +18,25 @@ @RestController public class GroupController { - private final GroupService groupService; + private final GroupService groupService; - @PostMapping("/groups") - public GroupResponse createGroup(@RequestBody GroupCreateRequest request) { - return groupService.createGroup(request); - } + @PostMapping("/groups") + public GroupResponse createGroup(@RequestBody GroupCreateRequest request) { + return groupService.createGroup(request); + } - @GetMapping("/groups") - public List findRegisteredGroups(@UserAuthentication User user) { - return groupService.findRegisteredGroupsByUser(user); - } + @GetMapping("/groups") + public List findRegisteredGroups(@UserAuthentication User user) { + return groupService.findRegisteredGroupsByUser(user); + } - @PostMapping("/groups/{groupId}/members") - public void registerMember(@PathVariable Long groupId) { - groupService.registerMember(groupId, 1L); // TODO: user -> argumentResolver 등록 필요 - } + @PostMapping("/groups/{groupId}/members") + public void registerMember(@UserAuthentication User user, @PathVariable Long groupId) { + groupService.registerMember(groupId, user); + } - @GetMapping("/groups/{groupId}/members") - public List findMembers(@PathVariable Long groupId) { - return groupService.findMembers(groupId); - } + @GetMapping("/groups/{groupId}/members") + public List findMembers(@PathVariable Long groupId) { + return groupService.findMembers(groupId); + } }