Skip to content

Commit

Permalink
Chore: Member 도메인 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
choeun7 committed Jan 15, 2024
1 parent 8b13091 commit 63a999f
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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<User> userOptional = userRepository.findByEmail(oAuth2UserInfo.getEmail());
User user;
Optional<Member> 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())
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> user = userRepository.findById(id);
Optional<Member> user = memberRepository.findById(id);
DefaultAssert.isOptionalPresent(user);

return UserPrincipal.create(user.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<User> checkUser = userRepository.findById(userPrincipal.getId());
Optional<Member> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ttubeog.domain.user.domain;
package com.ttubeog.domain.member.domain;

public enum Provider {
kakao,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ttubeog.domain.user.domain;
package com.ttubeog.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Member,Long>{

Optional<Member> findByEmail(String email);
Boolean existsByEmail(String email);

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ttubeog.domain.member.exception;

public class InvalidMemberException extends RuntimeException {

public InvalidMemberException(){
super("유저가 올바르지 않습니다.");
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 63a999f

Please sign in to comment.