diff --git a/src/main/java/com/ttubeog/domain/auth/application/CustomDefaultOAuth2UserService.java b/src/main/java/com/ttubeog/domain/auth/application/CustomDefaultOAuth2UserService.java index 7c690aa5..318adc6c 100644 --- a/src/main/java/com/ttubeog/domain/auth/application/CustomDefaultOAuth2UserService.java +++ b/src/main/java/com/ttubeog/domain/auth/application/CustomDefaultOAuth2UserService.java @@ -1,9 +1,9 @@ package com.ttubeog.domain.auth.application; -import com.ttubeog.domain.user.domain.Provider; -import com.ttubeog.domain.user.domain.Role; -import com.ttubeog.domain.user.domain.User; -import com.ttubeog.domain.user.domain.repository.UserRepository; +import com.ttubeog.domain.member.domain.Provider; +import com.ttubeog.domain.member.domain.Role; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.member.domain.repository.MemberRepository; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.auth.OAuth2UserInfo; import com.ttubeog.global.config.security.auth.OAuth2UserInfoFactory; @@ -21,7 +21,7 @@ @Service public class CustomDefaultOAuth2UserService extends DefaultOAuth2UserService{ - private final UserRepository userRepository; + private final MemberRepository memberRepository; @Override public OAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest) throws OAuth2AuthenticationException { @@ -38,21 +38,21 @@ private OAuth2User processOAuth2User(OAuth2UserRequest oAuth2UserRequest, OAuth2 OAuth2UserInfo oAuth2UserInfo = OAuth2UserInfoFactory.getOAuth2UserInfo(oAuth2UserRequest.getClientRegistration().getRegistrationId(), oAuth2User.getAttributes()); DefaultAssert.isAuthentication(!oAuth2UserInfo.getEmail().isEmpty()); - Optional userOptional = userRepository.findByEmail(oAuth2UserInfo.getEmail()); - User user; + Optional userOptional = memberRepository.findByEmail(oAuth2UserInfo.getEmail()); + Member member; if(userOptional.isPresent()) { - user = userOptional.get(); - DefaultAssert.isAuthentication(user.getProvider().equals(Provider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId()))); - user = updateExistingUser(user, oAuth2UserInfo); + member = userOptional.get(); + DefaultAssert.isAuthentication(member.getProvider().equals(Provider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId()))); + member = updateExistingUser(member, oAuth2UserInfo); } else { - user = registerNewUser(oAuth2UserRequest, oAuth2UserInfo); + member = registerNewUser(oAuth2UserRequest, oAuth2UserInfo); } - return UserPrincipal.create(user, oAuth2User.getAttributes()); + return UserPrincipal.create(member, oAuth2User.getAttributes()); } - private User registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo oAuth2UserInfo) { - User user = User.builder() + private Member registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo oAuth2UserInfo) { + Member member = Member.builder() .provider(Provider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId())) .providerId(oAuth2UserInfo.getId()) .name(oAuth2UserInfo.getName()) @@ -61,14 +61,14 @@ private User registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo .role(Role.USER) .build(); - return userRepository.save(user); + return memberRepository.save(member); } - private User updateExistingUser(User user, OAuth2UserInfo oAuth2UserInfo) { + private Member updateExistingUser(Member member, OAuth2UserInfo oAuth2UserInfo) { - user.updateName(oAuth2UserInfo.getName()); - user.updateImageUrl(oAuth2UserInfo.getImageUrl()); + member.updateName(oAuth2UserInfo.getName()); + member.updateImageUrl(oAuth2UserInfo.getImageUrl()); - return userRepository.save(user); + return memberRepository.save(member); } } diff --git a/src/main/java/com/ttubeog/domain/auth/application/CustomUserDetailsService.java b/src/main/java/com/ttubeog/domain/auth/application/CustomUserDetailsService.java index cf482169..59c10ed6 100644 --- a/src/main/java/com/ttubeog/domain/auth/application/CustomUserDetailsService.java +++ b/src/main/java/com/ttubeog/domain/auth/application/CustomUserDetailsService.java @@ -1,7 +1,7 @@ package com.ttubeog.domain.auth.application; -import com.ttubeog.domain.user.domain.User; -import com.ttubeog.domain.user.domain.repository.UserRepository; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.member.domain.repository.MemberRepository; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.token.UserPrincipal; import jakarta.transaction.Transactional; @@ -17,22 +17,22 @@ @Service public class CustomUserDetailsService implements UserDetailsService{ - private final UserRepository userRepository; + private final MemberRepository memberRepository; @Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { - User user = userRepository.findByEmail(email) + Member member = memberRepository.findByEmail(email) .orElseThrow(() -> new UsernameNotFoundException("유저 정보를 찾을 수 없습니다.") ); - return UserPrincipal.create(user); + return UserPrincipal.create(member); } @Transactional public UserDetails loadUserById(Long id) { - Optional user = userRepository.findById(id); + Optional user = memberRepository.findById(id); DefaultAssert.isOptionalPresent(user); return UserPrincipal.create(user.get()); diff --git a/src/main/java/com/ttubeog/domain/user/application/UserService.java b/src/main/java/com/ttubeog/domain/member/application/MemberService.java similarity index 52% rename from src/main/java/com/ttubeog/domain/user/application/UserService.java rename to src/main/java/com/ttubeog/domain/member/application/MemberService.java index dd8c2db9..943eee8f 100644 --- a/src/main/java/com/ttubeog/domain/user/application/UserService.java +++ b/src/main/java/com/ttubeog/domain/member/application/MemberService.java @@ -1,8 +1,8 @@ -package com.ttubeog.domain.user.application; +package com.ttubeog.domain.member.application; -import com.ttubeog.domain.user.dto.response.UserDetailRes; -import com.ttubeog.domain.user.domain.User; -import com.ttubeog.domain.user.domain.repository.UserRepository; +import com.ttubeog.domain.member.dto.response.MemberDetailRes; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.member.domain.repository.MemberRepository; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.token.UserPrincipal; import com.ttubeog.global.payload.ApiResponse; @@ -16,25 +16,25 @@ @RequiredArgsConstructor @Service @Transactional(readOnly = true) -public class UserService { - private final UserRepository userRepository; +public class MemberService { + private final MemberRepository memberRepository; // 현재 유저 조회 public ResponseEntity getCurrentUser(UserPrincipal userPrincipal){ - Optional checkUser = userRepository.findById(userPrincipal.getId()); + Optional checkUser = memberRepository.findById(userPrincipal.getId()); DefaultAssert.isOptionalPresent(checkUser); - User user = checkUser.get(); + Member member = checkUser.get(); - UserDetailRes userDetailRes = UserDetailRes.builder() - .id(user.getId()) - .email(user.getEmail()) - .name(user.getName()) - .ImgUrl(user.getImageUrl()) + MemberDetailRes memberDetailRes = MemberDetailRes.builder() + .id(member.getId()) + .email(member.getEmail()) + .name(member.getName()) + .ImgUrl(member.getImageUrl()) .build(); ApiResponse apiResponse = ApiResponse.builder() .check(true) - .information(userDetailRes) + .information(memberDetailRes) .build(); return ResponseEntity.ok(apiResponse); diff --git a/src/main/java/com/ttubeog/domain/user/domain/User.java b/src/main/java/com/ttubeog/domain/member/domain/Member.java similarity index 81% rename from src/main/java/com/ttubeog/domain/user/domain/User.java rename to src/main/java/com/ttubeog/domain/member/domain/Member.java index c851cc8e..2b2b3a1b 100644 --- a/src/main/java/com/ttubeog/domain/user/domain/User.java +++ b/src/main/java/com/ttubeog/domain/member/domain/Member.java @@ -1,4 +1,4 @@ -package com.ttubeog.domain.user.domain; +package com.ttubeog.domain.member.domain; import com.ttubeog.domain.common.BaseEntity; import jakarta.persistence.*; @@ -11,7 +11,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Getter -public class User extends BaseEntity { +public class Member extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -34,7 +34,7 @@ public class User extends BaseEntity { private String providerId; @Builder - public User(Long id, String name, String email, String imageUrl, Boolean emailVerified, String password, Provider provider, Role role, String providerId) { + public Member(Long id, String name, String email, String imageUrl, Boolean emailVerified, String password, Provider provider, Role role, String providerId) { this.id = id; this.name = name; this.email = email; diff --git a/src/main/java/com/ttubeog/domain/user/domain/Provider.java b/src/main/java/com/ttubeog/domain/member/domain/Provider.java similarity index 52% rename from src/main/java/com/ttubeog/domain/user/domain/Provider.java rename to src/main/java/com/ttubeog/domain/member/domain/Provider.java index 98a9a8ed..05baafc4 100644 --- a/src/main/java/com/ttubeog/domain/user/domain/Provider.java +++ b/src/main/java/com/ttubeog/domain/member/domain/Provider.java @@ -1,4 +1,4 @@ -package com.ttubeog.domain.user.domain; +package com.ttubeog.domain.member.domain; public enum Provider { kakao, diff --git a/src/main/java/com/ttubeog/domain/user/domain/Role.java b/src/main/java/com/ttubeog/domain/member/domain/Role.java similarity index 81% rename from src/main/java/com/ttubeog/domain/user/domain/Role.java rename to src/main/java/com/ttubeog/domain/member/domain/Role.java index 4278cfe6..74af748f 100644 --- a/src/main/java/com/ttubeog/domain/user/domain/Role.java +++ b/src/main/java/com/ttubeog/domain/member/domain/Role.java @@ -1,4 +1,4 @@ -package com.ttubeog.domain.user.domain; +package com.ttubeog.domain.member.domain; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java b/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java new file mode 100644 index 00000000..78b88eaa --- /dev/null +++ b/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java @@ -0,0 +1,15 @@ +package com.ttubeog.domain.member.domain.repository; + +import com.ttubeog.domain.member.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MemberRepository extends JpaRepository{ + + Optional findByEmail(String email); + Boolean existsByEmail(String email); + +} diff --git a/src/main/java/com/ttubeog/domain/member/dto/response/MemberDetailRes.java b/src/main/java/com/ttubeog/domain/member/dto/response/MemberDetailRes.java new file mode 100644 index 00000000..f8a1c519 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/member/dto/response/MemberDetailRes.java @@ -0,0 +1,32 @@ +package com.ttubeog.domain.member.dto.response; + +import com.ttubeog.domain.member.domain.Member; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class MemberDetailRes { + + private Long id; + + private String name; + + private String email; + + private String ImgUrl; + + public static MemberDetailRes toDto(Member member) { + return MemberDetailRes.builder() + .id(member.getId()) + .name(member.getName()) + .email(member.getEmail()) + .ImgUrl(member.getImageUrl()) + .build(); + } + +} diff --git a/src/main/java/com/ttubeog/domain/member/exception/InvalidMemberException.java b/src/main/java/com/ttubeog/domain/member/exception/InvalidMemberException.java new file mode 100644 index 00000000..c65365c1 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/member/exception/InvalidMemberException.java @@ -0,0 +1,9 @@ +package com.ttubeog.domain.member.exception; + +public class InvalidMemberException extends RuntimeException { + + public InvalidMemberException(){ + super("유저가 올바르지 않습니다."); + } + +} diff --git a/src/main/java/com/ttubeog/domain/user/presentation/UserController.java b/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java similarity index 76% rename from src/main/java/com/ttubeog/domain/user/presentation/UserController.java rename to src/main/java/com/ttubeog/domain/member/presentation/MemberController.java index c40014af..787d6a9d 100644 --- a/src/main/java/com/ttubeog/domain/user/presentation/UserController.java +++ b/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java @@ -1,7 +1,7 @@ -package com.ttubeog.domain.user.presentation; +package com.ttubeog.domain.member.presentation; -import com.ttubeog.domain.user.application.UserService; -import com.ttubeog.domain.user.dto.response.UserDetailRes; +import com.ttubeog.domain.member.application.MemberService; +import com.ttubeog.domain.member.dto.response.MemberDetailRes; import com.ttubeog.global.config.security.token.CurrentUser; import com.ttubeog.global.config.security.token.UserPrincipal; import com.ttubeog.global.payload.ErrorResponse; @@ -18,24 +18,24 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Tag(name = "Users", description = "Users API") +@Tag(name = "Member", description = "Member API") @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/users") -public class UserController { +@RequestMapping("/api/v1/member") +public class MemberController { - private final UserService testService; + private final MemberService memberService; @Operation(summary = "유저 정보 확인", description = "현재 접속된 유저정보를 확인합니다.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "유저 확인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = UserDetailRes.class) ) } ), + @ApiResponse(responseCode = "200", description = "유저 확인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = MemberDetailRes.class) ) } ), @ApiResponse(responseCode = "400", description = "유저 확인 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), }) @GetMapping public ResponseEntity getCurrentUser( @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal ) { - return testService.getCurrentUser(userPrincipal); + return memberService.getCurrentUser(userPrincipal); } } diff --git a/src/main/java/com/ttubeog/domain/user/domain/repository/UserRepository.java b/src/main/java/com/ttubeog/domain/user/domain/repository/UserRepository.java deleted file mode 100644 index ab14f5c7..00000000 --- a/src/main/java/com/ttubeog/domain/user/domain/repository/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.ttubeog.domain.user.domain.repository; - -import com.ttubeog.domain.user.domain.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.Optional; - -@Repository -public interface UserRepository extends JpaRepository{ - - Optional findByEmail(String email); - Boolean existsByEmail(String email); - -} diff --git a/src/main/java/com/ttubeog/domain/user/dto/response/UserDetailRes.java b/src/main/java/com/ttubeog/domain/user/dto/response/UserDetailRes.java deleted file mode 100644 index 436c97b1..00000000 --- a/src/main/java/com/ttubeog/domain/user/dto/response/UserDetailRes.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.ttubeog.domain.user.dto.response; - -import com.ttubeog.domain.user.domain.User; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -@Data -@RequiredArgsConstructor -@AllArgsConstructor -@Builder -public class UserDetailRes { - - private Long id; - - private String name; - - private String email; - - private String ImgUrl; - - public static UserDetailRes toDto(User user) { - return UserDetailRes.builder() - .id(user.getId()) - .name(user.getName()) - .email(user.getEmail()) - .ImgUrl(user.getImageUrl()) - .build(); - } - -} diff --git a/src/main/java/com/ttubeog/domain/user/exception/InvalidUserException.java b/src/main/java/com/ttubeog/domain/user/exception/InvalidUserException.java deleted file mode 100644 index fd2742f4..00000000 --- a/src/main/java/com/ttubeog/domain/user/exception/InvalidUserException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ttubeog.domain.user.exception; - -public class InvalidUserException extends RuntimeException { - - public InvalidUserException(){ - super("유저가 올바르지 않습니다."); - } - -} diff --git a/src/main/java/com/ttubeog/global/config/security/auth/OAuth2UserInfoFactory.java b/src/main/java/com/ttubeog/global/config/security/auth/OAuth2UserInfoFactory.java index 082e8270..182ab801 100644 --- a/src/main/java/com/ttubeog/global/config/security/auth/OAuth2UserInfoFactory.java +++ b/src/main/java/com/ttubeog/global/config/security/auth/OAuth2UserInfoFactory.java @@ -1,6 +1,6 @@ package com.ttubeog.global.config.security.auth; -import com.ttubeog.domain.user.domain.Provider; +import com.ttubeog.domain.member.domain.Provider; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.auth.company.Kakao; diff --git a/src/main/java/com/ttubeog/global/config/security/auth/company/Kakao.java b/src/main/java/com/ttubeog/global/config/security/auth/company/Kakao.java index f4cbf7ca..21749067 100644 --- a/src/main/java/com/ttubeog/global/config/security/auth/company/Kakao.java +++ b/src/main/java/com/ttubeog/global/config/security/auth/company/Kakao.java @@ -1,6 +1,6 @@ package com.ttubeog.global.config.security.auth.company; -import com.ttubeog.domain.user.domain.Provider; +import com.ttubeog.domain.member.domain.Provider; import com.ttubeog.global.config.security.auth.OAuth2UserInfo; import java.util.Map; diff --git a/src/main/java/com/ttubeog/global/config/security/token/UserPrincipal.java b/src/main/java/com/ttubeog/global/config/security/token/UserPrincipal.java index 21ec7a6d..afc6d046 100644 --- a/src/main/java/com/ttubeog/global/config/security/token/UserPrincipal.java +++ b/src/main/java/com/ttubeog/global/config/security/token/UserPrincipal.java @@ -1,6 +1,6 @@ package com.ttubeog.global.config.security.token; -import com.ttubeog.domain.user.domain.User; +import com.ttubeog.domain.member.domain.Member; import lombok.Getter; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -15,7 +15,7 @@ @Getter public class UserPrincipal implements OAuth2User, UserDetails{ - private final User user; + private final Member member; private final Long id; private final String email; @@ -23,27 +23,27 @@ public class UserPrincipal implements OAuth2User, UserDetails{ private final Collection authorities; private Map attributes; - public UserPrincipal(User user, Long id, String email, String password, Collection authorities) { - this.user = user; + public UserPrincipal(Member member, Long id, String email, String password, Collection authorities) { + this.member = member; this.id = id; this.email = email; this.password = password; this.authorities = authorities; } - public static UserPrincipal create(final User user) { - List authorities = Collections.singletonList(new SimpleGrantedAuthority(user.getRole().getValue())); + public static UserPrincipal create(final Member member) { + List authorities = Collections.singletonList(new SimpleGrantedAuthority(member.getRole().getValue())); return new UserPrincipal( - user, - user.getId(), - user.getEmail(), - user.getPassword(), + member, + member.getId(), + member.getEmail(), + member.getPassword(), authorities ); } - public static UserPrincipal create(User user, Map attributes) { - UserPrincipal userPrincipal = UserPrincipal.create(user); + public static UserPrincipal create(Member member, Map attributes) { + UserPrincipal userPrincipal = UserPrincipal.create(member); userPrincipal.setAttributes(attributes); return userPrincipal; }