diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/config/AuthConfig.java b/src/main/java/org/swmaestro/repl/gifthub/auth/config/AuthConfig.java index d008a1d0..a3b80b4b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/config/AuthConfig.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/config/AuthConfig.java @@ -1,6 +1,9 @@ package org.swmaestro.repl.gifthub.auth.config; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; import lombok.Getter; @@ -12,5 +15,9 @@ @Setter public class AuthConfig { private String defaultNickname; - private String defaultPassword; + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java index 43645d9b..aa968dd4 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java @@ -9,6 +9,7 @@ import org.swmaestro.repl.gifthub.auth.dto.JwtTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.service.AuthService; import org.swmaestro.repl.gifthub.auth.service.RefreshTokenService; @@ -161,12 +162,13 @@ public ResponseEntity appleSignIn(HttpServletRequest request, @RequestB @ApiResponse(responseCode = "200", description = "로그인 성공"), @ApiResponse(responseCode = "400(401)", description = "존재하지 않는 사용자") }) - public ResponseEntity signOut(HttpServletRequest request) { + public ResponseEntity signOut(HttpServletRequest request, @RequestBody SignOutDto signOutDto) { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - authService.signOut(username); + authService.signOut(username, signOutDto); return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) + .data(null) .build()); } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/UserController.java b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/UserController.java index 5de41036..b475f05d 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/UserController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/UserController.java @@ -12,9 +12,9 @@ import org.swmaestro.repl.gifthub.auth.dto.MemberDeleteResponseDto; import org.swmaestro.repl.gifthub.auth.dto.MemberUpdateRequestDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.service.OAuthService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.JwtProvider; @@ -34,7 +34,7 @@ @RequiredArgsConstructor @Tag(name = "Users", description = "사용자 관련 API") public class UserController { - private final MemberService memberService; + private final UserService userService; private final OAuthService oAuthService; private final JwtProvider jwtProvider; @@ -46,7 +46,7 @@ public class UserController { @ApiResponse(responseCode = "400(404-2)", description = "이미 삭제된 회원 아이디 입력") }) public ResponseEntity deleteMember(HttpServletRequest request, @PathVariable Long userId) { - MemberDeleteResponseDto deletedMember = memberService.delete(userId); + MemberDeleteResponseDto deletedMember = userService.delete(userId); return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) @@ -66,7 +66,7 @@ public ResponseEntity updateMember(HttpServletRequest request, @PathVar return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) - .data(memberService.update(username, userId, memberUpdateRequestDto)) + .data(userService.update(username, userId, memberUpdateRequestDto)) .build()); } @@ -80,7 +80,7 @@ public ResponseEntity readMember(HttpServletRequest request, @PathVaria return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) - .data(memberService.read(userId)) + .data(userService.read(userId)) .build()); } @@ -103,8 +103,8 @@ public ResponseEntity createOAuthInfo(HttpServletRequest request, @Path } String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - Member member = memberService.read(username); - memberService.createOAuthInfo(member, oAuthPlatform, oAuthTokenDto); + User user = userService.read(username); + userService.createOAuthInfo(user, oAuthPlatform, oAuthTokenDto); return ResponseEntity.ok(SuccessMessage.builder() .path(request.getRequestURI()) .build()); @@ -128,8 +128,8 @@ public ResponseEntity deleteOAuthInfo(HttpServletRequest request, @Path } String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - Member member = memberService.read(username); - memberService.deleteOAuthInfo(member, oAuthPlatform); + User user = userService.read(username); + userService.deleteOAuthInfo(user, oAuthPlatform); return ResponseEntity.ok(SuccessMessage.builder() .path(request.getRequestURI()) .build()); diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/DeviceToken.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/DeviceToken.java index 2390a1dc..e1f070de 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/DeviceToken.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/DeviceToken.java @@ -23,16 +23,16 @@ public class DeviceToken extends BaseTimeEntity { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) - private Member member; + @JoinColumn(name = "user_id", nullable = false) + private User user; @Column(length = 200) private String token; @Builder - public DeviceToken(Long id, Member member, String token) { + public DeviceToken(Long id, User user, String token) { this.id = id; - this.member = member; + this.user = user; this.token = token; } } \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/Member.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/Member.java deleted file mode 100644 index fe951eaa..00000000 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/Member.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.swmaestro.repl.gifthub.auth.entity; - -import java.time.LocalDateTime; - -import org.swmaestro.repl.gifthub.util.BaseTimeEntity; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Entity -@Getter -@Setter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Member extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(length = 60, nullable = false, unique = true) - private String username; - - @Column(length = 60) - private String password; - - @Column(length = 12, nullable = false) - private String nickname; - - @Column - private LocalDateTime deletedAt; - - @Builder - public Member(Long id, String username, String password, String nickname) { - this.id = id; - this.username = username; - this.password = password; - this.nickname = nickname; - } -} diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/OAuth.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/OAuth.java index c180e2b0..714407c8 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/OAuth.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/OAuth.java @@ -40,17 +40,17 @@ public class OAuth { @JoinColumn(name = "member_id", nullable = false) @ManyToOne - private Member member; + private User user; @Column private LocalDateTime deletedAt; @Builder - public OAuth(OAuthPlatform platform, String platformId, String email, String nickname, Member member) { + public OAuth(OAuthPlatform platform, String platformId, String email, String nickname, User user) { this.platform = platform; this.platformId = platformId; this.email = email; this.nickname = nickname; - this.member = member; + this.user = user; } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java new file mode 100644 index 00000000..9ece44e8 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java @@ -0,0 +1,95 @@ +package org.swmaestro.repl.gifthub.auth.entity; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.swmaestro.repl.gifthub.auth.type.Role; +import org.swmaestro.repl.gifthub.util.BaseTimeEntity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Transient; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class User extends BaseTimeEntity implements UserDetails { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(length = 60, nullable = false, unique = true) + private String username; + + @Column(length = 60) + private String password; + + @Column(length = 12, nullable = false) + private String nickname; + + @Column + private LocalDateTime deletedAt; + + @Transient + private Collection authorities; + + @Column(columnDefinition = "TINYINT", nullable = false) + private Role role; + + @Builder + public User(Long id, String username, String password, String nickname, Role role) { + this.id = id; + this.username = username; + this.password = password; + this.nickname = nickname; + this.role = role; + } + + @Override + public Collection getAuthorities() { + Collection authorities = new ArrayList<>(); + + for (String role : role.getValue().split(",")) { + authorities.add(new SimpleGrantedAuthority(role)); + } + return authorities; + } + + @Override + public String getUsername() { + return this.username; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java index 0a8f44d5..d6302f64 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java @@ -5,12 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.swmaestro.repl.gifthub.auth.entity.DeviceToken; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; public interface DeviceTokenRepository extends JpaRepository { Optional findByToken(String token); - Optional findByMemberAndToken(Member member, String token); + Optional findByUserAndToken(User user, String token); - List findAllByMember(Member member); + List findAllByUser(User user); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java deleted file mode 100644 index 712d0ab4..00000000 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.swmaestro.repl.gifthub.auth.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.swmaestro.repl.gifthub.auth.entity.Member; - -public interface MemberRepository extends JpaRepository { - - Member findByUsername(String username); - - Member findByNickname(String nickname); -} diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/OAuthRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/OAuthRepository.java index e3e91e8d..e44c25bf 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/OAuthRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/OAuthRepository.java @@ -3,14 +3,14 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; public interface OAuthRepository extends JpaRepository { - Optional findByMemberAndPlatform(Member member, OAuthPlatform platform); + Optional findByUserAndPlatform(User user, OAuthPlatform platform); Optional findByPlatformAndPlatformId(OAuthPlatform platform, String platformId); - Optional deleteByMemberAndPlatform(Member member, OAuthPlatform platform); + Optional deleteByUserAndPlatform(User user, OAuthPlatform platform); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java new file mode 100644 index 00000000..5f62009a --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java @@ -0,0 +1,11 @@ +package org.swmaestro.repl.gifthub.auth.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.swmaestro.repl.gifthub.auth.entity.User; + +public interface UserRepository extends JpaRepository { + + User findByUsername(String username); + + User findByNickname(String nickname); +} diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AppleService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AppleService.java index aa35e34b..8824651e 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AppleService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AppleService.java @@ -15,8 +15,8 @@ import org.swmaestro.repl.gifthub.auth.config.AppleConfig; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.repository.OAuthRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -96,8 +96,8 @@ public OAuthUserInfoDto getUserInfo(OAuthTokenDto oAuthTokenDto) { } @Override - public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { - if (isExists(member)) { + public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { + if (isExists(user)) { throw new BusinessException("이미 연동된 계정이 존재하는 플랫폼입니다.", StatusEnum.CONFLICT); } @@ -106,7 +106,7 @@ public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(member) + .user(user) .platform(OAuthPlatform.APPLE) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) @@ -129,8 +129,8 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { } @Override - public OAuth delete(Member member) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.APPLE).orElseThrow( + public OAuth delete(User user) { + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.APPLE).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -138,8 +138,8 @@ public OAuth delete(Member member) { } @Override - public boolean isExists(Member member) { - return oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.APPLE).isPresent(); + public boolean isExists(User user) { + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.APPLE).isPresent(); } @Override diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java index 8a8da216..92273e74 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java @@ -7,11 +7,13 @@ import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.repository.UserRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; +import org.swmaestro.repl.gifthub.auth.type.Role; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.JwtProvider; import org.swmaestro.repl.gifthub.util.StatusEnum; @@ -22,11 +24,11 @@ @Service @RequiredArgsConstructor public class AuthService { - private final MemberService memberService; + private final UserService userService; private final PasswordEncoder passwordEncoder; private final JwtProvider jwtProvider; private final OAuthService oAuthService; - private final MemberRepository memberRepository; + private final UserRepository userRepository; private final RefreshTokenService refreshTokenService; private final DeviceTokenService deviceTokenService; private final AuthConfig authConfig; @@ -36,14 +38,15 @@ public class AuthService { * @param signUpDto */ public JwtTokenDto signUp(SignUpDto signUpDto) { - Member member = Member.builder() + User user = User.builder() .username(signUpDto.getUsername()) .password(passwordEncoder.encode(signUpDto.getPassword())) .nickname(signUpDto.getNickname()) + .role(Role.USER) .build(); - Member savedMember = memberService.create(member); - return generateJwtTokenDto(savedMember); + User savedUser = userService.create(user); + return generateJwtTokenDto(savedUser); } /** @@ -51,18 +54,18 @@ public JwtTokenDto signUp(SignUpDto signUpDto) { * @param signInDto */ public JwtTokenDto signIn(SignInDto signInDto) { - Member member = memberService.read(signInDto.getUsername()); + User user = userService.read(signInDto.getUsername()); - if (member == null) { + if (user == null) { throw new BusinessException("존재하지 않는 아이디입니다.", StatusEnum.BAD_REQUEST); } - if (!passwordEncoder.matches(signInDto.getPassword(), member.getPassword())) { + if (!passwordEncoder.matches(signInDto.getPassword(), user.getPassword())) { throw new BusinessException("비밀번호가 일치하지 않습니다.", StatusEnum.BAD_REQUEST); } - String accessToken = jwtProvider.generateToken(member.getUsername(), member.getId()); - String refreshToken = jwtProvider.generateRefreshToken(member.getUsername(), member.getId()); + String accessToken = jwtProvider.generateToken(user.getUsername(), user.getId()); + String refreshToken = jwtProvider.generateRefreshToken(user.getUsername(), user.getId()); JwtTokenDto jwtTokenDto = JwtTokenDto.builder() .accessToken(accessToken) @@ -87,50 +90,48 @@ public JwtTokenDto signIn(OAuthTokenDto oAuthTokenDto, OAuthPlatform platform) { oAuth = oAuthService.read(userInfo, platform); } else { // 존재하지 않을 경우 -> 회원 가입 -> 로그인 - Member newMember = Member.builder() - .username(memberService.generateOAuthUsername()) + User newUser = User.builder() + .username(userService.generateOAuthUsername()) .nickname(authConfig.getDefaultNickname()) - .password(passwordEncoder.encode(authConfig.getDefaultPassword())) .build(); // 회원 정보 저장 - Member member = memberService.create(newMember); + User user = userService.create(newUser); // oauth 정보 저장 - oAuth = oAuthService.create(member, userInfo, platform); + oAuth = oAuthService.create(user, userInfo, platform); } - return generateJwtTokenDto(oAuth.getMember()); + return generateJwtTokenDto(oAuth.getUser()); } /** * JWT 토큰 생성 - * @param member + * @param user * @return */ - private JwtTokenDto generateJwtTokenDto(Member member) { - String accessToken = jwtProvider.generateToken(member.getUsername(), member.getId()); - String refreshToken = jwtProvider.generateRefreshToken(member.getUsername(), member.getId()); + private JwtTokenDto generateJwtTokenDto(User user) { + String accessToken = jwtProvider.generateToken(user.getUsername(), user.getId()); + String refreshToken = jwtProvider.generateRefreshToken(user.getUsername(), user.getId()); JwtTokenDto jwtTokenDto = JwtTokenDto.builder() .accessToken(accessToken) .refreshToken(refreshToken) .build(); - refreshTokenService.storeRefreshToken(jwtTokenDto, member.getUsername()); - return jwtTokenDto; } /** * 로그아웃 * @param username + * @param signOutDto */ @Transactional - public void signOut(String username) { - Member member = memberRepository.findByUsername(username); - System.out.println("member = " + member.getUsername()); - if (member == null) { + public void signOut(String username, SignOutDto signOutDto) { + User user = userRepository.findByUsername(username); + if (user == null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } refreshTokenService.deleteRefreshToken(username); + deviceTokenService.delete(signOutDto.getDeviceToken()); } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/DeviceTokenService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/DeviceTokenService.java index 67129e93..daaaae8b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/DeviceTokenService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/DeviceTokenService.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.dto.MemberReadResponseDto; import org.swmaestro.repl.gifthub.auth.entity.DeviceToken; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.repository.DeviceTokenRepository; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.StatusEnum; @@ -17,15 +17,15 @@ @RequiredArgsConstructor public class DeviceTokenService { private final DeviceTokenRepository deviceTokenRepository; - private final MemberService memberService; + private final UserService userService; /* * DeviceToken 저장 메서드 */ public void save(String username, String token) { - Member member = memberService.read(username); + User user = userService.read(username); - if (member == null) { + if (user == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -36,7 +36,7 @@ public void save(String username, String token) { DeviceToken deviceToken; if (!isExist(token)) { deviceToken = DeviceToken.builder() - .member(member) + .user(user) .token(token) .build(); @@ -58,10 +58,10 @@ public boolean isExist(String deviceToken) { * DeviceToken 존재 여부 반환 메서드 (회원 아이디와 토큰으로) */ public boolean isExist(Long memberId, String deviceToken) { - MemberReadResponseDto memberDto = memberService.read(memberId); - Member member = memberService.read(memberDto.getUsername()); + MemberReadResponseDto memberDto = userService.read(memberId); + User user = userService.read(memberDto.getUsername()); - return deviceTokenRepository.findByMemberAndToken(member, deviceToken).isPresent(); + return deviceTokenRepository.findByUserAndToken(user, deviceToken).isPresent(); } /** @@ -75,9 +75,9 @@ public List list() { * DeviceToken 전체 조회 메서드(memberId) */ public List list(Long memberId) { - MemberReadResponseDto memberDto = memberService.read(memberId); - Member member = memberService.read(memberDto.getUsername()); - return deviceTokenRepository.findAllByMember(member); + MemberReadResponseDto memberDto = userService.read(memberId); + User user = userService.read(memberDto.getUsername()); + return deviceTokenRepository.findAllByUser(user); } /* @@ -99,9 +99,9 @@ public DeviceToken read(Long deviceTokenId) { /* * DeviceToken 삭제 메서드 */ - public void delete(Member member, String token) { + public void delete(User user, String token) { DeviceToken deviceToken = read(token); - if (!deviceToken.getMember().equals(member)) { + if (!deviceToken.getUser().equals(user)) { throw new BusinessException("토큰을 삭제할 권한이 없습니다.", StatusEnum.FORBIDDEN); } deviceTokenRepository.delete(deviceToken); diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/GoogleService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/GoogleService.java index 10d24300..8e90d5e6 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/GoogleService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/GoogleService.java @@ -13,8 +13,8 @@ import org.swmaestro.repl.gifthub.auth.config.GoogleConfig; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.repository.OAuthRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -78,8 +78,8 @@ public OAuthUserInfoDto getUserInfo(OAuthTokenDto oAuthTokenDto) { } @Override - public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { - if (isExists(member)) { + public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { + if (isExists(user)) { throw new BusinessException("이미 연동된 계정이 존재하는 플랫폼입니다.", StatusEnum.CONFLICT); } @@ -88,7 +88,7 @@ public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(member) + .user(user) .platform(OAuthPlatform.GOOGLE) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) @@ -111,8 +111,8 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { } @Override - public OAuth delete(Member member) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.GOOGLE).orElseThrow( + public OAuth delete(User user) { + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.GOOGLE).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -120,8 +120,8 @@ public OAuth delete(Member member) { } @Override - public boolean isExists(Member member) { - return oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.GOOGLE).isPresent(); + public boolean isExists(User user) { + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.GOOGLE).isPresent(); } @Override diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/KakaoService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/KakaoService.java index ee503e33..ef9a1851 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/KakaoService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/KakaoService.java @@ -13,8 +13,8 @@ import org.swmaestro.repl.gifthub.auth.config.KakaoConfig; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.repository.OAuthRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -76,8 +76,8 @@ public OAuthUserInfoDto getUserInfo(OAuthTokenDto oAuthTokenDto) { } @Override - public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { - if (isExists(member)) { + public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { + if (isExists(user)) { throw new BusinessException("이미 연동된 계정이 존재하는 플랫폼입니다.", StatusEnum.CONFLICT); } @@ -86,7 +86,7 @@ public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(member) + .user(user) .platform(OAuthPlatform.KAKAO) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) @@ -109,8 +109,8 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { } @Override - public OAuth delete(Member member) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.KAKAO).orElseThrow( + public OAuth delete(User user) { + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.KAKAO).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -118,8 +118,8 @@ public OAuth delete(Member member) { } @Override - public boolean isExists(Member member) { - return oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.KAKAO).isPresent(); + public boolean isExists(User user) { + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.KAKAO).isPresent(); } @Override @@ -129,6 +129,6 @@ public boolean isExists(OAuthUserInfoDto oAuthUserInfoDto) { private String getStringOrNull(JsonElement element, String fieldName) { JsonElement fieldElement = element.getAsJsonObject().get(fieldName); - return fieldElement != null ? fieldElement.getAsString() : null; + return !fieldElement.isJsonNull() ? fieldElement.getAsString() : null; } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/NaverService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/NaverService.java index 38aa30e4..fb7910a4 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/NaverService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/NaverService.java @@ -13,8 +13,8 @@ import org.swmaestro.repl.gifthub.auth.config.NaverConfig; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.repository.OAuthRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -81,8 +81,8 @@ public OAuthUserInfoDto getUserInfo(OAuthTokenDto oAuthTokenDto) { } @Override - public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { - if (isExists(member)) { + public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { + if (isExists(user)) { throw new BusinessException("이미 연동된 계정이 존재하는 플랫폼입니다.", StatusEnum.CONFLICT); } @@ -91,7 +91,7 @@ public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(member) + .user(user) .platform(OAuthPlatform.NAVER) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) @@ -114,8 +114,8 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { } @Override - public OAuth delete(Member member) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.NAVER).orElseThrow( + public OAuth delete(User user) { + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.NAVER).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -123,8 +123,8 @@ public OAuth delete(Member member) { } @Override - public boolean isExists(Member member) { - return oAuthRepository.findByMemberAndPlatform(member, OAuthPlatform.NAVER).isPresent(); + public boolean isExists(User user) { + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.NAVER).isPresent(); } @Override diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuth2Service.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuth2Service.java index 58de66c3..5aa106fb 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuth2Service.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuth2Service.java @@ -2,8 +2,8 @@ import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; /** * OAuth2 인증을 위한 인터페이스 @@ -18,12 +18,12 @@ public interface OAuth2Service { /** * OAuth 플랫폼 정보를 저장한다. - * @param member + * @param user * @param oAuthUserInfoDto * @return */ - OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto); + OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto); /** * OAuth 플랫폼 정보를 가져온다. @@ -34,17 +34,17 @@ public interface OAuth2Service { /** * 연동된 OAuth 계정 정보를 삭제한다. - * @param member + * @param user * @return */ - OAuth delete(Member member); + OAuth delete(User user); /** * OAuth 플랫폼 존재 여부를 확인한다. - * @param member + * @param user * @return */ - boolean isExists(Member member); + boolean isExists(User user); /** * OAuth 플랫폼 존재 여부를 확인한다. diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuthService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuthService.java index 3aa0ff12..44556d7c 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuthService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/OAuthService.java @@ -3,8 +3,8 @@ import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.StatusEnum; @@ -32,22 +32,22 @@ public OAuthUserInfoDto getUserInfo(OAuthTokenDto oAuthTokenDto, OAuthPlatform p }; } - public OAuth create(Member member, OAuthUserInfoDto oAuthUserInfoDto, OAuthPlatform platform) { + public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto, OAuthPlatform platform) { return switch (platform) { - case NAVER -> naverService.create(member, oAuthUserInfoDto); - case KAKAO -> kakaoService.create(member, oAuthUserInfoDto); - case GOOGLE -> googleService.create(member, oAuthUserInfoDto); - case APPLE -> appleService.create(member, oAuthUserInfoDto); + case NAVER -> naverService.create(user, oAuthUserInfoDto); + case KAKAO -> kakaoService.create(user, oAuthUserInfoDto); + case GOOGLE -> googleService.create(user, oAuthUserInfoDto); + case APPLE -> appleService.create(user, oAuthUserInfoDto); default -> throw new BusinessException("지원하지 않는 OAuth 플랫폼입니다.", StatusEnum.INTERNAL_SERVER_ERROR); }; } - public OAuth delete(Member member, OAuthPlatform platform) { + public OAuth delete(User user, OAuthPlatform platform) { return switch (platform) { - case NAVER -> naverService.delete(member); - case KAKAO -> kakaoService.delete(member); - case GOOGLE -> googleService.delete(member); - case APPLE -> appleService.delete(member); + case NAVER -> naverService.delete(user); + case KAKAO -> kakaoService.delete(user); + case GOOGLE -> googleService.delete(user); + case APPLE -> appleService.delete(user); default -> throw new BusinessException("지원하지 않는 OAuth 플랫폼입니다.", StatusEnum.INTERNAL_SERVER_ERROR); }; } @@ -62,12 +62,12 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto, OAuthPlatform platform) { }; } - public boolean isExists(Member member, OAuthPlatform platform) { + public boolean isExists(User user, OAuthPlatform platform) { return switch (platform) { - case NAVER -> naverService.isExists(member); - case KAKAO -> kakaoService.isExists(member); - case GOOGLE -> googleService.isExists(member); - case APPLE -> appleService.isExists(member); + case NAVER -> naverService.isExists(user); + case KAKAO -> kakaoService.isExists(user); + case GOOGLE -> googleService.isExists(user); + case APPLE -> appleService.isExists(user); default -> throw new BusinessException("지원하지 않는 OAuth 플랫폼입니다.", StatusEnum.INTERNAL_SERVER_ERROR); }; } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java similarity index 62% rename from src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java rename to src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java index a846ca39..cfabcb1b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java @@ -7,6 +7,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.dto.MemberDeleteResponseDto; @@ -15,9 +18,9 @@ import org.swmaestro.repl.gifthub.auth.dto.MemberUpdateResponseDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.repository.UserRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.StatusEnum; @@ -26,36 +29,37 @@ @Service @RequiredArgsConstructor -public class MemberService { - private final MemberRepository memberRepository; +public class UserService implements UserDetailsService { + private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final OAuthService oAuthService; - public Member passwordEncryption(Member member) { - return Member.builder() - .username(member.getUsername()) - .password(passwordEncoder.encode(member.getPassword())) - .nickname(member.getNickname()) + public User passwordEncryption(User user) { + return User.builder() + .username(user.getUsername()) + .password(passwordEncoder.encode(user.getPassword())) + .nickname(user.getNickname()) + .role(user.getRole()) .build(); } - public Member create(Member member) { - if (isDuplicateUsername(member.getUsername())) { + public User create(User user) { + if (isDuplicateUsername(user.getUsername())) { throw new BusinessException("이미 존재하는 아이디입니다.", StatusEnum.CONFLICT); } - if (!isValidatePassword(member.getPassword())) { + if (!isValidatePassword(user.getPassword())) { throw new BusinessException("비밀번호는 영문, 숫자, 특수문자를 포함한 8자리 이상이어야 합니다.", StatusEnum.BAD_REQUEST); } - if (member.getNickname().length() >= 12) { + if (user.getNickname().length() >= 12) { throw new BusinessException("닉네임은 12자리 이하이어야 합니다.", StatusEnum.BAD_REQUEST); } - Member encodedMember = passwordEncryption(member); - return memberRepository.save(encodedMember); + User encodedUser = passwordEncryption(user); + return userRepository.save(encodedUser); } public boolean isDuplicateUsername(String username) { - return memberRepository.findByUsername(username) != null; + return userRepository.findByUsername(username) != null; } public boolean isValidatePassword(String password) { @@ -66,16 +70,16 @@ public boolean isValidatePassword(String password) { return matcher.matches(); } - public Member read(String username) { - Member member = memberRepository.findByUsername(username); - if (member == null) { + public User read(String username) { + User user = userRepository.findByUsername(username); + if (user == null) { return null; } - return member; + return user; } public MemberReadResponseDto read(Long id) { - Optional member = memberRepository.findById(id); + Optional member = userRepository.findById(id); if (member.isEmpty()) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -87,54 +91,54 @@ public MemberReadResponseDto read(Long id) { } public int count() { - return (int)memberRepository.count(); + return (int)userRepository.count(); } - public List list() { - return memberRepository.findAll(); + public List list() { + return userRepository.findAll(); } public MemberUpdateResponseDto update(String username, Long userId, MemberUpdateRequestDto memberUpdateRequestDto) { - Member member = memberRepository.findByUsername(username); - if (member == null) { + User user = userRepository.findByUsername(username); + if (user == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } - if (!member.getId().equals(userId)) { + if (!user.getId().equals(userId)) { throw new BusinessException("수정 권한이 없습니다.", StatusEnum.FORBIDDEN); } if (memberUpdateRequestDto.getNickname() != null) { if (isDuplicateNickname(memberUpdateRequestDto.getNickname())) { throw new BusinessException("이미 존재하는 닉네임입니다.", StatusEnum.CONFLICT); } - member.setNickname(memberUpdateRequestDto.getNickname()); + user.setNickname(memberUpdateRequestDto.getNickname()); } if (memberUpdateRequestDto.getPassword() != null) { if (!isValidatePassword(memberUpdateRequestDto.getPassword())) { throw new BusinessException("비밀번호는 영문, 숫자, 특수문자를 포함한 8자리 이상이어야 합니다.", StatusEnum.BAD_REQUEST); } - member.setPassword(passwordEncoder.encode(memberUpdateRequestDto.getPassword())); + user.setPassword(passwordEncoder.encode(memberUpdateRequestDto.getPassword())); } - memberRepository.save(member); + userRepository.save(user); return MemberUpdateResponseDto.builder() - .id(member.getId()) - .nickname(member.getNickname()) + .id(user.getId()) + .nickname(user.getNickname()) .build(); } public boolean isDuplicateNickname(String nickname) { - return memberRepository.findByNickname(nickname) != null; + return userRepository.findByNickname(nickname) != null; } public MemberDeleteResponseDto delete(Long id) { - Member member = memberRepository.findById(id) + User user = userRepository.findById(id) .orElseThrow(() -> new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND)); - if (!member.getDeletedAt().equals(null)) { + if (!user.getDeletedAt().equals(null)) { throw new BusinessException("이미 삭제된 회원입니다.", StatusEnum.NOT_FOUND); } - member.setDeletedAt(LocalDateTime.now()); - memberRepository.save(member); + user.setDeletedAt(LocalDateTime.now()); + userRepository.save(user); return MemberDeleteResponseDto.builder() .id(id) @@ -144,13 +148,18 @@ public MemberDeleteResponseDto delete(Long id) { public String generateOAuthUsername() { return UUID.randomUUID().toString(); } - - public OAuth createOAuthInfo(Member member, OAuthPlatform oAuthPlatform, OAuthTokenDto oAuthTokenDto) { + + public OAuth createOAuthInfo(User user, OAuthPlatform oAuthPlatform, OAuthTokenDto oAuthTokenDto) { OAuthUserInfoDto oAuthUserInfoDto = oAuthService.getUserInfo(oAuthTokenDto, oAuthPlatform); - return oAuthService.create(member, oAuthUserInfoDto, oAuthPlatform); + return oAuthService.create(user, oAuthUserInfoDto, oAuthPlatform); + } + + public OAuth deleteOAuthInfo(User user, OAuthPlatform oAuthPlatform) { + return oAuthService.delete(user, oAuthPlatform); } - public OAuth deleteOAuthInfo(Member member, OAuthPlatform oAuthPlatform) { - return oAuthService.delete(member, oAuthPlatform); - } + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return null; + } } \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/type/Role.java b/src/main/java/org/swmaestro/repl/gifthub/auth/type/Role.java new file mode 100644 index 00000000..70bd6729 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/type/Role.java @@ -0,0 +1,14 @@ +package org.swmaestro.repl.gifthub.auth.type; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Role { + ADMIN("ROLE_ADMIN,ROLE_USER,ROLE_TEMPORARY"), + USER("ROLE_USER,ROLE_TEMPORARY"), + TEMPORARY("ROLE_TEMPORARY"); + + private String value; +} diff --git a/src/main/java/org/swmaestro/repl/gifthub/config/SecurityConfig.java b/src/main/java/org/swmaestro/repl/gifthub/config/SecurityConfig.java index 609d5c11..90fa0f48 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/config/SecurityConfig.java +++ b/src/main/java/org/swmaestro/repl/gifthub/config/SecurityConfig.java @@ -8,8 +8,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.access.AccessDeniedHandler; @@ -85,9 +83,4 @@ public void commence(HttpServletRequest request, HttpServletResponse response, A return httpSecurity.build(); } - - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationController.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationController.java index 39b94f74..eaa28dea 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationController.java @@ -11,8 +11,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.swmaestro.repl.gifthub.auth.entity.Member; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.notifications.dto.DeviceTokenRequestDto; import org.swmaestro.repl.gifthub.notifications.dto.NoticeNotificationDto; import org.swmaestro.repl.gifthub.notifications.dto.NotificationReadResponseDto; @@ -36,7 +36,7 @@ public class NotificationController { private final NotificationService notificationService; private final FCMNotificationService fcmNotificationService; - private final MemberService memberService; + private final UserService userService; private final JwtProvider jwtProvider; @GetMapping @@ -87,8 +87,8 @@ public ResponseEntity deleteDeviceToken( @RequestHeader("Authorization") String accessToken, @RequestBody DeviceTokenRequestDto deviceTokenRequestDto) { String username = jwtProvider.getUsername(accessToken.substring(7)); - Member member = memberService.read(username); - notificationService.deleteDeviceToken(member, deviceTokenRequestDto.getToken()); + User user = userService.read(username); + notificationService.deleteDeviceToken(user, deviceTokenRequestDto.getToken()); return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/dto/FCMNotificationRequestDto.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/dto/FCMNotificationRequestDto.java index fa2a4e24..71428375 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/dto/FCMNotificationRequestDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/dto/FCMNotificationRequestDto.java @@ -1,6 +1,6 @@ package org.swmaestro.repl.gifthub.notifications.dto; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.vouchers.entity.Voucher; import lombok.Builder; @@ -10,14 +10,14 @@ @Getter @NoArgsConstructor public class FCMNotificationRequestDto { - private Member targetMember; + private User targetUser; private Voucher targetVoucher; private String title; private String body; @Builder - public FCMNotificationRequestDto(Member targetMember, Voucher targetVoucher, String title, String body) { - this.targetMember = targetMember; + public FCMNotificationRequestDto(User targetUser, Voucher targetVoucher, String title, String body) { + this.targetUser = targetUser; this.targetVoucher = targetVoucher; this.title = title; this.body = body; diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/entity/Notification.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/entity/Notification.java index 3f2f1e2b..a7514b36 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/entity/Notification.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/entity/Notification.java @@ -4,7 +4,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.notifications.NotificationType; import org.swmaestro.repl.gifthub.vouchers.entity.Voucher; @@ -34,7 +34,7 @@ public class Notification { @ManyToOne @JoinColumn(name = "receiver_id", nullable = false) - private Member receiver; + private User receiver; @ManyToOne(optional = true) @JoinColumn(name = "voucher_id", nullable = true) @@ -56,7 +56,7 @@ public class Notification { private LocalDateTime checkedAt; @Builder - public Notification(Long id, Member receiver, Voucher voucher, NotificationType type, String message, LocalDateTime deletedAt, LocalDateTime checkedAt) { + public Notification(Long id, User receiver, Voucher voucher, NotificationType type, String message, LocalDateTime deletedAt, LocalDateTime checkedAt) { this.id = id; this.receiver = receiver; this.voucher = voucher; diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/FCMNotificationService.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/FCMNotificationService.java index 5480482e..3ad6a8a5 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/FCMNotificationService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/FCMNotificationService.java @@ -4,9 +4,9 @@ import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.entity.DeviceToken; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.service.DeviceTokenService; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.notifications.NotificationType; import org.swmaestro.repl.gifthub.notifications.dto.FCMNotificationRequestDto; import org.swmaestro.repl.gifthub.notifications.dto.NoticeNotificationDto; @@ -24,10 +24,10 @@ public class FCMNotificationService { private final FirebaseMessaging firebaseMessaging; private final DeviceTokenService deviceTokenService; private final NotificationService notificationService; - private final MemberService memberService; + private final UserService userService; public void sendNotificationByToken(FCMNotificationRequestDto requestDto) { - List deviceTokenList = deviceTokenService.list(requestDto.getTargetMember().getId()); + List deviceTokenList = deviceTokenService.list(requestDto.getTargetUser().getId()); for (DeviceToken deviceToken : deviceTokenList) { Notification notification = Notification.builder() @@ -36,7 +36,7 @@ public void sendNotificationByToken(FCMNotificationRequestDto requestDto) { .build(); org.swmaestro.repl.gifthub.notifications.entity.Notification savedNotification - = notificationService.save(requestDto.getTargetMember(), requestDto.getTargetVoucher(), NotificationType.EXPIRATION, requestDto.getBody()); + = notificationService.save(requestDto.getTargetUser(), requestDto.getTargetVoucher(), NotificationType.EXPIRATION, requestDto.getBody()); Message message = Message.builder() .setToken(deviceToken.getToken()) @@ -67,7 +67,7 @@ public void sendNotification(NoticeNotificationDto noticeNotificationDto) { .build(); org.swmaestro.repl.gifthub.notifications.entity.Notification savedNotification - = notificationService.save(deviceToken.getMember(), null, NotificationType.NOTICE, noticeNotificationDto.getBody()); + = notificationService.save(deviceToken.getUser(), null, NotificationType.NOTICE, noticeNotificationDto.getBody()); Message message = Message.builder() .setToken(deviceToken.getToken()) @@ -87,14 +87,14 @@ public void sendNotification(NoticeNotificationDto noticeNotificationDto) { * title과 body를 받아서 특정 회원에게 알림을 보내는 메서드(username으로 검색) */ public void sendNotification(String title, String body, String username) { - Member member = memberService.read(username); + User user = userService.read(username); NoticeNotificationDto noticeNotificationDto = NoticeNotificationDto.builder() .title(title) .body(body) .build(); - List deviceTokenList = deviceTokenService.list(member.getId()); + List deviceTokenList = deviceTokenService.list(user.getId()); for (DeviceToken deviceToken : deviceTokenList) { Notification notification = Notification.builder() diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/NotificationService.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/NotificationService.java index 7a82f46c..6a1f6098 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/NotificationService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/NotificationService.java @@ -5,9 +5,9 @@ import java.util.List; import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.auth.service.DeviceTokenService; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.notifications.NotificationType; import org.swmaestro.repl.gifthub.notifications.dto.NotificationReadResponseDto; @@ -22,13 +22,13 @@ @Service @RequiredArgsConstructor public class NotificationService { - private final MemberService memberService; + private final UserService userService; private final NotificationRepository notificationRepository; private final DeviceTokenService deviceTokenService; private final VoucherService voucherService; public List list(String username) { - if (memberService.read(username) == null) { + if (userService.read(username) == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } List notifications = notificationRepository.findAllByReceiverUsername(username); @@ -69,9 +69,9 @@ public boolean saveDeviceToken(String username, String deviceToken) { } - public boolean deleteDeviceToken(Member member, String deviceToken) { + public boolean deleteDeviceToken(User user, String deviceToken) { try { - deviceTokenService.delete(member, deviceToken); + deviceTokenService.delete(user, deviceToken); return true; } catch (Exception e) { throw new BusinessException("디바이스 토큰 삭제에 실패하였습니다.", StatusEnum.BAD_REQUEST); @@ -81,9 +81,9 @@ public boolean deleteDeviceToken(Member member, String deviceToken) { /** * Notification 저장 메서드 */ - public Notification save(Member member, Voucher voucher, NotificationType type, String message) { + public Notification save(User user, Voucher voucher, NotificationType type, String message) { Notification notification = Notification.builder() - .receiver(member) + .receiver(user) .type(type) .message(message) .voucher(voucher) @@ -96,7 +96,7 @@ public Notification save(Member member, Voucher voucher, NotificationType type, * Notification 상세 조회 메서드 */ public NotificationReadResponseDto read(Long id, String username) { - if (memberService.read(username) == null) { + if (userService.read(username) == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } Notification notification = notificationRepository.findById(id).orElseThrow(() -> new BusinessException("존재하지 않는 알림입니다.", StatusEnum.NOT_FOUND)); diff --git a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/ScheduledTasks.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/ScheduledTasks.java index 2f820223..2482d20d 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/notifications/service/ScheduledTasks.java +++ b/src/main/java/org/swmaestro/repl/gifthub/notifications/service/ScheduledTasks.java @@ -40,7 +40,7 @@ public void sendExpirationNotification() { if (daysDifference <= 3) { FCMNotificationRequestDto requestDto = FCMNotificationRequestDto.builder() - .targetMember(voucher.getMember()) + .targetUser(voucher.getUser()) .targetVoucher(voucher) .title(NotificationType.EXPIRATION.getDescription()) .body(voucher.getBrand().getName() + "에서 사용할 수 있는 기프티콘 기한이 " + daysDifference + "일 남았습니다.") diff --git a/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java b/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java deleted file mode 100644 index cbbb89db..00000000 --- a/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.swmaestro.repl.gifthub.security; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.swmaestro.repl.gifthub.auth.entity.Member; - -import java.util.Collection; - -public class CustomUserDetails implements UserDetails { - private final Member member; - - public CustomUserDetails(Member member) { - this.member = member; - } - - public final Member getMember() { - return member; - } - - @Override - public Collection getAuthorities() { - return null; - } - - @Override - public String getPassword() { - return member.getPassword(); - } - - @Override - public String getUsername() { - return member.getUsername(); - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } -} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java deleted file mode 100644 index d782400d..00000000 --- a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.swmaestro.repl.gifthub.security; - -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.entity.Member; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; - -@Service -@RequiredArgsConstructor -public class JpaUserDetailsService implements UserDetailsService { - private final MemberRepository memberRepository; - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - Member member = memberRepository.findByUsername(username); - if (member != null) { - return new CustomUserDetails(member); - } else { - return (UserDetails) new UsernameNotFoundException("User not found with username: " + username); - } - - } -} diff --git a/src/main/java/org/swmaestro/repl/gifthub/util/JwtProvider.java b/src/main/java/org/swmaestro/repl/gifthub/util/JwtProvider.java index d50f5be1..087b003a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/util/JwtProvider.java +++ b/src/main/java/org/swmaestro/repl/gifthub/util/JwtProvider.java @@ -12,8 +12,8 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; import org.swmaestro.repl.gifthub.auth.repository.RefreshTokenRepository; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.exception.BusinessException; -import org.swmaestro.repl.gifthub.security.JpaUserDetailsService; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jws; @@ -26,16 +26,16 @@ public class JwtProvider { private final String secretKey; private final long expiration; private final String issuer; - private final JpaUserDetailsService userDetailsService; + private final UserService userService; private final RefreshTokenRepository refreshTokenRepository; public JwtProvider(@Value("${jwt.secret-key}") String secretKey, @Value("${jwt.expiration-time}") long expiration, - @Value("${issuer}") String issuer, JpaUserDetailsService userDetailsService, + @Value("${issuer}") String issuer, UserService userService, RefreshTokenRepository refreshTokenRepository) { this.secretKey = secretKey; this.expiration = expiration; this.issuer = issuer; - this.userDetailsService = userDetailsService; + this.userService = userService; this.refreshTokenRepository = refreshTokenRepository; } @@ -95,7 +95,7 @@ public String resolveToken(HttpServletRequest request) { * @return 인증 정보 */ public Authentication getAuthentication(String token) { - UserDetails userDetails = userDetailsService.loadUserByUsername(this.getUsername(token)); + UserDetails userDetails = userService.loadUserByUsername(this.getUsername(token)); return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/PendingVoucher.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/PendingVoucher.java index 2147580d..69ed0179 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/PendingVoucher.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/PendingVoucher.java @@ -4,7 +4,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -29,16 +29,16 @@ public class PendingVoucher { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) - private Member member; + @JoinColumn(name = "user_id", nullable = false) + private User user; @CreatedDate @Column(nullable = false) private LocalDateTime createdAt; @Builder - public PendingVoucher(Long id, Member member) { + public PendingVoucher(Long id, User user) { this.id = id; - this.member = member; + this.user = user; } -} +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java index 1015e17c..22085bae 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java @@ -3,7 +3,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.util.BaseTimeEntity; import jakarta.persistence.Column; @@ -49,22 +49,22 @@ public class Voucher extends BaseTimeEntity { private String imageUrl; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) - private Member member; + @JoinColumn(name = "user_id", nullable = false) + private User user; @Column private LocalDateTime deletedAt; @Builder public Voucher(Long id, Brand brand, Product product, String barcode, Integer balance, LocalDate expiresAt, - String imageUrl, Member member) { + String imageUrl, User user) { this.id = id; this.brand = brand; this.product = product; this.barcode = barcode; this.balance = balance; this.expiresAt = expiresAt; - this.member = member; + this.user = user; this.imageUrl = imageUrl; } } \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/VoucherUsageHistory.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/VoucherUsageHistory.java index ba808b65..56612927 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/VoucherUsageHistory.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/VoucherUsageHistory.java @@ -4,7 +4,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -29,8 +29,8 @@ public class VoucherUsageHistory { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) - private Member member; + @JoinColumn(name = "user_id", nullable = false) + private User user; @ManyToOne @JoinColumn(name = "voucher_id", nullable = false) @@ -46,13 +46,13 @@ public class VoucherUsageHistory { private LocalDateTime createdAt; @Builder - public VoucherUsageHistory(Long id, Member member, Voucher voucher, Integer amount, String place, + public VoucherUsageHistory(Long id, User user, Voucher voucher, Integer amount, String place, LocalDateTime createdAt) { this.id = id; - this.member = member; + this.user = user; this.voucher = voucher; this.amount = amount; this.place = place; this.createdAt = createdAt; } -} +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/PendingVoucherRepository.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/PendingVoucherRepository.java index 4db1f00e..bda520c8 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/PendingVoucherRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/PendingVoucherRepository.java @@ -4,7 +4,7 @@ import org.swmaestro.repl.gifthub.vouchers.entity.PendingVoucher; public interface PendingVoucherRepository extends JpaRepository { - PendingVoucher findByMemberId(Long memberId); + PendingVoucher findByUserId(Long memberId); - int countByMemberId(Long memberId); -} + int countByUserId(Long memberId); +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/VoucherRepository.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/VoucherRepository.java index 8ca3644a..ee2e2a3d 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/VoucherRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/VoucherRepository.java @@ -6,8 +6,8 @@ import org.swmaestro.repl.gifthub.vouchers.entity.Voucher; public interface VoucherRepository extends JpaRepository { - List findAllByMemberUsername(String username); + List findAllByUserUsername(String username); - List findAllByMemberId(Long memberId); + List findAllByUserId(Long memberId); -} +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/PendingVoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/PendingVoucherService.java index af65bfb9..21ea98dd 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/PendingVoucherService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/PendingVoucherService.java @@ -1,7 +1,7 @@ package org.swmaestro.repl.gifthub.vouchers.service; import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.StatusEnum; import org.swmaestro.repl.gifthub.vouchers.entity.PendingVoucher; @@ -14,15 +14,15 @@ public class PendingVoucherService { private final PendingVoucherRepository pendingVoucherRepository; - public void create(Member member) { + public void create(User member) { PendingVoucher pendingVoucher = PendingVoucher.builder() - .member(member) + .user(member) .build(); pendingVoucherRepository.save(pendingVoucher); } - public void delete(Member member) { - PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(member.getId()); + public void delete(User user) { + PendingVoucher pendingVoucher = pendingVoucherRepository.findByUserId(user.getId()); //예외 처리 if (pendingVoucher == null) { throw new BusinessException("PendingVoucher가 존재하지 않습니다.", StatusEnum.NOT_FOUND); @@ -31,6 +31,6 @@ public void delete(Member member) { } public int count(Long memberId) { - return pendingVoucherRepository.countByMemberId(memberId); + return pendingVoucherRepository.countByUserId(memberId); } -} +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java index 2c840365..3d6250b8 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java @@ -3,7 +3,7 @@ import java.io.IOException; import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.notifications.NotificationType; import org.swmaestro.repl.gifthub.notifications.service.FCMNotificationService; @@ -33,11 +33,11 @@ public class VoucherSaveService { private final QueryTemplateReader queryTemplateReader; private final ProductNameProcessor productNameProcessor; private final NotificationService notificationService; - private final MemberService memberService; + private final UserService userService; private final PendingVoucherService pendingVoucherService; public void execute(OCRDto ocrDto, String username) throws IOException { - pendingVoucherService.create(memberService.read(username)); + pendingVoucherService.create(userService.read(username)); handleGptResponse(ocrDto, username) .flatMap(voucherSaveRequestDto -> handleSearchResponse(voucherSaveRequestDto, username)) .flatMap(voucherSaveRequestDto -> handleVoucherSaving(voucherSaveRequestDto, username)) @@ -46,24 +46,24 @@ public void execute(OCRDto ocrDto, String username) throws IOException { voucherSaveResponseDto -> { System.out.println("등록 성공"); //notification 저장(알림 성공 저장) - notificationService.save(memberService.read(username), voucherService.read(voucherSaveResponseDto.getId()), + notificationService.save(userService.read(username), voucherService.read(voucherSaveResponseDto.getId()), NotificationType.REGISTERED, "기프티콘 등록에 성공했습니다."); fcmNotificationService.sendNotification("기프티콘 등록 성공", "기프티콘 등록에 성공했습니다!", username); // 처리 완료 - pendingVoucherService.delete(memberService.read(username)); + pendingVoucherService.delete(userService.read(username)); }, // onError throwable -> { System.out.println("등록 실패"); throwable.printStackTrace(); // notification 저장(알림 실패 저장) - notificationService.save(memberService.read(username), null, + notificationService.save(userService.read(username), null, NotificationType.REGISTERED, "기프티콘 등록에 실패했습니다."); fcmNotificationService.sendNotification("기프티콘 등록 실패", "기프티콘 등록에 실패했습니다.", username); // 처리 완료 - pendingVoucherService.delete(memberService.read(username)); + pendingVoucherService.delete(userService.read(username)); }); } @@ -128,4 +128,3 @@ private String createQuery(VoucherSaveRequestDto voucherSaveRequestDto) { } } - diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index 64dac2ca..8c5ca8bf 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java @@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.exception.BusinessException; import org.swmaestro.repl.gifthub.util.DateConverter; import org.swmaestro.repl.gifthub.util.StatusEnum; @@ -36,7 +36,7 @@ public class VoucherService { private final BrandService brandService; private final ProductService productService; private final VoucherRepository voucherRepository; - private final MemberService memberService; + private final UserService userService; private final PendingVoucherService pendingVoucherService; private final VoucherUsageHistoryService voucherUsageHistoryService; @@ -75,7 +75,7 @@ public VoucherSaveResponseDto save(String username, VoucherSaveRequestDto vouche .expiresAt(DateConverter.stringToLocalDate(voucherSaveRequestDto.getExpiresAt())) .imageUrl(imageUrl) .balance(product.getPrice()) - .member(memberService.read(username)) + .user(userService.read(username)) .build(); return VoucherSaveResponseDto.builder() @@ -96,7 +96,7 @@ public Voucher read(Long id) { */ public VoucherReadResponseDto read(Long id, String username) { Optional voucher = voucherRepository.findById(id); - List vouchers = voucherRepository.findAllByMemberUsername(username); + List vouchers = voucherRepository.findAllByUserUsername(username); if (voucher.isEmpty()) { throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); @@ -120,11 +120,11 @@ public List list() { 사용자 별 기프티콘 목록 조회 메서드(userId로 조회, username으로 권한 대조) */ public VoucherListResponseDto list(Long userId, String username) { - if (!memberService.read(userId).getUsername().equals(username)) { + if (!userService.read(userId).getUsername().equals(username)) { throw new BusinessException("상품권을 조회할 권한이 없습니다.", StatusEnum.FORBIDDEN); } - List vouchers = voucherRepository.findAllByMemberId(userId); + List vouchers = voucherRepository.findAllByUserId(userId); List voucherIdList = new ArrayList<>(); for (Voucher voucher : vouchers) { // 삭제된 기프티콘은 조회되지 않도록 함 @@ -144,7 +144,7 @@ public VoucherListResponseDto list(Long userId, String username) { 사용자 별 기프티콘 목록 조회 메서드(username으로 조회) */ public List list(String username) { - List vouchers = voucherRepository.findAllByMemberUsername(username); + List vouchers = voucherRepository.findAllByUserUsername(username); List voucherIdList = new ArrayList<>(); for (Voucher voucher : vouchers) { voucherIdList.add(voucher.getId()); @@ -227,7 +227,7 @@ public VoucherUseResponseDto use(String username, Long voucherId, VoucherUseRequ */ public boolean delete(String username, Long voucherId) { Optional voucher = voucherRepository.findById(voucherId); - List vouchers = voucherRepository.findAllByMemberUsername(username); + List vouchers = voucherRepository.findAllByUserUsername(username); if (voucher.isEmpty()) { throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); @@ -266,7 +266,7 @@ public VoucherReadResponseDto mapToDto(Voucher voucher) { * 사용자 별 중복 기프티콘 검사 메서드 */ public boolean isDuplicateVoucher(String username, String barcode) { - List vouchers = voucherRepository.findAllByMemberUsername(username); + List vouchers = voucherRepository.findAllByUserUsername(username); for (Voucher voucher : vouchers) { if (voucher.getBarcode().equals(barcode)) { return true; @@ -333,7 +333,7 @@ private Voucher getValidVoucherForUser(String username, Long voucherId) { } Voucher voucher = optionalVoucher.get(); - if (!voucherRepository.findAllByMemberUsername(username).contains(voucher)) { + if (!voucherRepository.findAllByUserUsername(username).contains(voucher)) { throw new BusinessException("상품권을 사용할 권한이 없습니다.", StatusEnum.FORBIDDEN); } if (voucher.getBalance() != null && voucher.getBalance() == 0) { @@ -378,13 +378,15 @@ public Product updateProduct(VoucherUpdateRequestDto voucherUpdateRequestDto, Br Optional optionalProduct = productService.read(brand.getId(), voucherUpdateRequestDto.getProductName()); if (optionalProduct.isEmpty()) { - Brand otherBrand = brandService.read("기타").orElseThrow(() -> new BusinessException("해당 상품이 존재하지 않습니다.", StatusEnum.NOT_FOUND)); + Brand otherBrand = brandService.read("기타").orElseThrow( + () -> new BusinessException("해당 상품이 존재하지 않습니다.", StatusEnum.NOT_FOUND)); optionalProduct = productService.read(otherBrand.getId(), voucherUpdateRequestDto.getProductName()); } return optionalProduct.orElseGet(() -> { Product newProduct = Product.builder() - .brand(brandService.read("기타").orElseThrow(() -> new BusinessException("기타 브랜드를 찾을 수 없습니다.", StatusEnum.NOT_FOUND))) + .brand(brandService.read("기타").orElseThrow( + () -> new BusinessException("기타 브랜드를 찾을 수 없습니다.", StatusEnum.NOT_FOUND))) .name(voucherUpdateRequestDto.getProductName()) .isReusable(1) .price(oldProduct.getPrice()) @@ -404,4 +406,4 @@ public Brand updateBrand(VoucherUpdateRequestDto voucherUpdateRequestDto) { }); return brand; } -} +} \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java index e9d9ba7f..b1645319 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java @@ -1,7 +1,7 @@ package org.swmaestro.repl.gifthub.vouchers.service; import org.springframework.stereotype.Service; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.entity.Voucher; import org.swmaestro.repl.gifthub.vouchers.entity.VoucherUsageHistory; @@ -13,14 +13,14 @@ @RequiredArgsConstructor public class VoucherUsageHistoryService { private final VoucherUsageHistoryRepository voucherUsageHistoryRepository; - private final MemberService memberService; + private final UserService userService; /** * 사용 내역 저장 메서드 */ public Long create(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto, String username) { VoucherUsageHistory voucherUsageHistory = VoucherUsageHistory.builder() - .member(memberService.read(username)) + .user(userService.read(username)) .voucher(voucher) .amount(voucherUseRequestDto.getAmount()) .place(voucherUseRequestDto.getPlace()) @@ -28,4 +28,4 @@ public Long create(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto, S voucherUsageHistoryRepository.save(voucherUsageHistory); return voucherUsageHistory.getId(); } -} +} \ No newline at end of file diff --git a/src/main/resources/gpt/question.txt b/src/main/resources/gpt/question.txt index 1614de21..a2b2c125 100644 --- a/src/main/resources/gpt/question.txt +++ b/src/main/resources/gpt/question.txt @@ -11,4 +11,4 @@ If you can't categorize it, return an empty value in the JSON structure below. {"brand_name" : "product_name" : "expires_at" : -"barcode": } +"barcode": } \ No newline at end of file diff --git a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/UserControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/UserControllerTest.java index 6d45026e..983df143 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/UserControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/UserControllerTest.java @@ -17,9 +17,9 @@ import org.swmaestro.repl.gifthub.auth.dto.MemberUpdateRequestDto; import org.swmaestro.repl.gifthub.auth.dto.MemberUpdateResponseDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; -import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.entity.OAuth; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.util.JwtProvider; @@ -32,7 +32,7 @@ class UserControllerTest { private MockMvc mockMvc; @MockBean - private MemberService memberService; + private UserService userService; @MockBean private JwtProvider jwtProvider; @@ -51,7 +51,7 @@ void deleteMember() throws Exception { // when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); when(jwtProvider.getUsername(anyString())).thenReturn("이진우"); - when(memberService.delete(1L)).thenReturn(userDeleteResponseDto); + when(userService.delete(1L)).thenReturn(userDeleteResponseDto); // then mockMvc.perform(delete("/users/1") @@ -76,7 +76,7 @@ void updateMember() throws Exception { //when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); when(jwtProvider.getUsername(anyString())).thenReturn("이진우"); - when(memberService.update(anyString(), anyLong(), any(MemberUpdateRequestDto.class))).thenReturn(memberUpdateResponseDto); + when(userService.update(anyString(), anyLong(), any(MemberUpdateRequestDto.class))).thenReturn(memberUpdateResponseDto); //then mockMvc.perform(patch("/users/1") @@ -97,7 +97,7 @@ void readMember() throws Exception { .nickname("이진우") .build(); //when - when(memberService.read(anyLong())).thenReturn(memberReadResponseDto); + when(userService.read(anyLong())).thenReturn(memberReadResponseDto); //then mockMvc.perform(get("/users/1") @@ -109,7 +109,7 @@ void readMember() throws Exception { @WithMockUser(username = "이진우", roles = "USER") void createOAuthInfo() throws Exception { // given - Member member = Member.builder() + User user = User.builder() .username("my_username") .nickname("my_nickname") .password("my_password") @@ -118,7 +118,7 @@ void createOAuthInfo() throws Exception { OAuth oAuth = OAuth.builder() .platform(OAuthPlatform.NAVER) .platformId("my_naver_unique_id") - .member(member) + .user(user) .email("my_naver_email") .nickname("my_naver_nickname") .build(); @@ -129,7 +129,7 @@ void createOAuthInfo() throws Exception { // when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); - when(memberService.createOAuthInfo(any(Member.class), any(OAuthPlatform.class), any(OAuthTokenDto.class))).thenReturn(oAuth); + when(userService.createOAuthInfo(any(User.class), any(OAuthPlatform.class), any(OAuthTokenDto.class))).thenReturn(oAuth); // then mockMvc.perform(post("/users/oauth/naver") @@ -142,7 +142,7 @@ void createOAuthInfo() throws Exception { @WithMockUser(username = "이진우", roles = "USER") void deleteOAuthInfo() throws Exception { // given - Member member = Member.builder() + User user = User.builder() .username("my_username") .nickname("my_nickname") .password("my_password") @@ -151,14 +151,14 @@ void deleteOAuthInfo() throws Exception { OAuth oAuth = OAuth.builder() .platform(OAuthPlatform.NAVER) .platformId("my_naver_unique_id") - .member(member) + .user(user) .email("my_naver_email") .nickname("my_naver_nickname") .build(); // when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); - when(memberService.deleteOAuthInfo(any(Member.class), any(OAuthPlatform.class))).thenReturn(oAuth); + when(userService.deleteOAuthInfo(any(User.class), any(OAuthPlatform.class))).thenReturn(oAuth); // then mockMvc.perform(delete("/users/oauth/naver") diff --git a/src/test/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationControllerTest.java index 19076f2c..77542fbf 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationControllerTest.java @@ -16,8 +16,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; -import org.swmaestro.repl.gifthub.auth.entity.Member; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.service.UserService; import org.swmaestro.repl.gifthub.notifications.dto.DeviceTokenRequestDto; import org.swmaestro.repl.gifthub.notifications.dto.NotificationReadResponseDto; import org.swmaestro.repl.gifthub.notifications.service.NotificationService; @@ -41,7 +41,7 @@ public class NotificationControllerTest { private NotificationService notificationService; @MockBean - private MemberService memberService; + private UserService userService; /** * 알림 목록 조회 테스트 @@ -130,12 +130,12 @@ void deleteDeviceToken() throws Exception { String accessToken = "my.access.token"; String username = "이진우"; DeviceTokenRequestDto deviceTokenRequestDto = DeviceTokenRequestDto.builder().token("my.device.token").build(); - Member member = Member.builder().username(username).build(); + User user = User.builder().username(username).build(); when(jwtProvider.resolveToken(any())).thenReturn(accessToken); when(jwtProvider.getUsername(anyString())).thenReturn(username); - when(memberService.read(username)).thenReturn(member); - when(notificationService.deleteDeviceToken(member, deviceTokenRequestDto.getToken())).thenReturn(true); + when(userService.read(username)).thenReturn(user); + when(notificationService.deleteDeviceToken(user, deviceTokenRequestDto.getToken())).thenReturn(true); mockMvc.perform(delete("/notifications/device").header("Authorization", "Bearer " + accessToken) .contentType("application/json") diff --git a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java index 188749eb..365005b6 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java @@ -291,4 +291,4 @@ void saveVoucher() throws Exception { .content(objectMapper.writeValueAsString(ocrDto))) .andExpect(status().isOk()); } -} +} \ No newline at end of file