From d76f6da5f896c6c3e42ce38e3815ee7f61ba2fde Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 12 Oct 2023 15:47:43 +0900 Subject: [PATCH 01/11] feat: implement user-roles --- .../gifthub/auth/entity/{Member.java => User.java} | 0 .../org/swmaestro/repl/gifthub/auth/type/Role.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+) rename src/main/java/org/swmaestro/repl/gifthub/auth/entity/{Member.java => User.java} (100%) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/auth/type/Role.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/Member.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java similarity index 100% rename from src/main/java/org/swmaestro/repl/gifthub/auth/entity/Member.java rename to src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java 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; +} From 7346d860b08fbdbaf7dd3d2b0f61cf3e79700849 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 12 Oct 2023 15:53:01 +0900 Subject: [PATCH 02/11] chore: rename member to user --- .../auth/controller/UserController.java | 10 +-- .../repl/gifthub/auth/entity/DeviceToken.java | 6 +- .../repl/gifthub/auth/entity/OAuth.java | 6 +- .../repl/gifthub/auth/entity/User.java | 55 +++++++++++++- .../repository/DeviceTokenRepository.java | 6 +- .../auth/repository/MemberRepository.java | 8 +-- .../auth/repository/OAuthRepository.java | 6 +- .../gifthub/auth/service/AppleService.java | 16 ++--- .../gifthub/auth/service/AuthService.java | 38 +++++----- .../auth/service/DeviceTokenService.java | 20 +++--- .../gifthub/auth/service/GoogleService.java | 16 ++--- .../gifthub/auth/service/KakaoService.java | 16 ++--- .../gifthub/auth/service/MemberService.java | 72 +++++++++---------- .../gifthub/auth/service/NaverService.java | 16 ++--- .../gifthub/auth/service/OAuth2Service.java | 14 ++-- .../gifthub/auth/service/OAuthService.java | 32 ++++----- .../controller/NotificationController.java | 6 +- .../dto/FCMNotificationRequestDto.java | 8 +-- .../notifications/entity/Notification.java | 6 +- .../service/FCMNotificationService.java | 12 ++-- .../service/NotificationService.java | 10 +-- .../notifications/service/ScheduledTasks.java | 2 +- .../gifthub/security/CustomUserDetails.java | 20 +++--- .../security/JpaUserDetailsService.java | 13 ++-- .../vouchers/entity/PendingVoucher.java | 8 +-- .../repl/gifthub/vouchers/entity/Voucher.java | 8 +-- .../vouchers/entity/VoucherUsageHistory.java | 10 +-- .../service/PendingVoucherService.java | 10 +-- .../vouchers/service/VoucherService.java | 4 +- src/main/resources/gpt/question.txt | 14 ---- .../auth/controller/UserControllerTest.java | 14 ++-- .../NotificationControllerTest.java | 8 +-- 32 files changed, 264 insertions(+), 226 deletions(-) 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..5c931366 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,7 +12,7 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.service.MemberService; import org.swmaestro.repl.gifthub.auth.service.OAuthService; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; @@ -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 = memberService.read(username); + memberService.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 = memberService.read(username); + memberService.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..2301a72d 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 @@ -24,15 +24,15 @@ public class DeviceToken extends BaseTimeEntity { @ManyToOne @JoinColumn(name = "member_id", nullable = false) - private Member member; + 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/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 index fe951eaa..9621f147 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java @@ -1,14 +1,23 @@ 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.EnumType; +import jakarta.persistence.Enumerated; 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; @@ -19,7 +28,7 @@ @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Member extends BaseTimeEntity { +public class User extends BaseTimeEntity implements UserDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -36,11 +45,53 @@ public class Member extends BaseTimeEntity { @Column private LocalDateTime deletedAt; + @Transient + private Collection authorities; + + @Enumerated(EnumType.ORDINAL) + @Column(columnDefinition = "TINYINT", nullable = false) + private Role role; + @Builder - public Member(Long id, String username, String password, String nickname) { + public User(Long id, String username, String password, String nickname) { this.id = id; this.username = username; this.password = password; this.nickname = nickname; } + + @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..5efff734 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 findByMemberAndToken(User user, String token); - List findAllByMember(Member member); + List findAllByMember(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 index 712d0ab4..60c45a79 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java @@ -1,11 +1,11 @@ package org.swmaestro.repl.gifthub.auth.repository; import org.springframework.data.jpa.repository.JpaRepository; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; -public interface MemberRepository extends JpaRepository { +public interface MemberRepository extends JpaRepository { - Member findByUsername(String username); + User findByUsername(String username); - Member findByNickname(String nickname); + User 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..74adab8b 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 findByMemberAndPlatform(User user, OAuthPlatform platform); Optional findByPlatformAndPlatformId(OAuthPlatform platform, String platformId); - Optional deleteByMemberAndPlatform(Member member, OAuthPlatform platform); + Optional deleteByMemberAndPlatform(User user, OAuthPlatform platform); } 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..4f383b22 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) + .member(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.findByMemberAndPlatform(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.findByMemberAndPlatform(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 7f31de2c..827af2cd 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 @@ -9,8 +9,8 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -37,14 +37,14 @@ 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()) .build(); - Member savedMember = memberService.create(member); - return generateJwtTokenDto(savedMember); + User savedUser = memberService.create(user); + return generateJwtTokenDto(savedUser); } /** @@ -52,18 +52,18 @@ public JwtTokenDto signUp(SignUpDto signUpDto) { * @param signInDto */ public JwtTokenDto signIn(SignInDto signInDto) { - Member member = memberService.read(signInDto.getUsername()); + User user = memberService.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) @@ -88,27 +88,27 @@ public JwtTokenDto signIn(OAuthTokenDto oAuthTokenDto, OAuthPlatform platform) { oAuth = oAuthService.read(userInfo, platform); } else { // 존재하지 않을 경우 -> 회원 가입 -> 로그인 - Member newMember = Member.builder() + User newUser = User.builder() .username(memberService.generateOAuthUsername()) .nickname(authConfig.getDefaultNickname()) .build(); // 회원 정보 저장 - Member member = memberService.create(newMember); + User user = memberService.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) @@ -125,8 +125,8 @@ private JwtTokenDto generateJwtTokenDto(Member member) { */ @Transactional public void signOut(String username, SignOutDto signOutDto) { - Member member = memberRepository.findByUsername(username); - if (member == null) { + User user = memberRepository.findByUsername(username); + if (user == null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } refreshTokenService.deleteRefreshToken(username); 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..d956540d 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; @@ -23,9 +23,9 @@ public class DeviceTokenService { * DeviceToken 저장 메서드 */ public void save(String username, String token) { - Member member = memberService.read(username); + User user = memberService.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) + .member(user) .token(token) .build(); @@ -59,9 +59,9 @@ public boolean isExist(String deviceToken) { */ public boolean isExist(Long memberId, String deviceToken) { MemberReadResponseDto memberDto = memberService.read(memberId); - Member member = memberService.read(memberDto.getUsername()); + User user = memberService.read(memberDto.getUsername()); - return deviceTokenRepository.findByMemberAndToken(member, deviceToken).isPresent(); + return deviceTokenRepository.findByMemberAndToken(user, deviceToken).isPresent(); } /** @@ -76,8 +76,8 @@ public List list() { */ public List list(Long memberId) { MemberReadResponseDto memberDto = memberService.read(memberId); - Member member = memberService.read(memberDto.getUsername()); - return deviceTokenRepository.findAllByMember(member); + User user = memberService.read(memberDto.getUsername()); + return deviceTokenRepository.findAllByMember(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..3d3add92 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) + .member(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.findByMemberAndPlatform(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.findByMemberAndPlatform(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 65361801..c8989ed9 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) + .member(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.findByMemberAndPlatform(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.findByMemberAndPlatform(user, OAuthPlatform.KAKAO).isPresent(); } @Override diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java index a846ca39..7bbfd810 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/MemberService.java @@ -15,8 +15,8 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -31,27 +31,27 @@ public class MemberService { 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()) .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 memberRepository.save(encodedUser); } public boolean isDuplicateUsername(String username) { @@ -66,16 +66,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 = memberRepository.findByUsername(username); + if (user == null) { return null; } - return member; + return user; } public MemberReadResponseDto read(Long id) { - Optional member = memberRepository.findById(id); + Optional member = memberRepository.findById(id); if (member.isEmpty()) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -90,34 +90,34 @@ public int count() { return (int)memberRepository.count(); } - public List list() { + public List list() { return memberRepository.findAll(); } public MemberUpdateResponseDto update(String username, Long userId, MemberUpdateRequestDto memberUpdateRequestDto) { - Member member = memberRepository.findByUsername(username); - if (member == null) { + User user = memberRepository.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); + memberRepository.save(user); return MemberUpdateResponseDto.builder() - .id(member.getId()) - .nickname(member.getNickname()) + .id(user.getId()) + .nickname(user.getNickname()) .build(); } @@ -126,15 +126,15 @@ public boolean isDuplicateNickname(String nickname) { } public MemberDeleteResponseDto delete(Long id) { - Member member = memberRepository.findById(id) + User user = memberRepository.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()); + memberRepository.save(user); return MemberDeleteResponseDto.builder() .id(id) @@ -144,13 +144,13 @@ 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(Member member, OAuthPlatform oAuthPlatform) { - return oAuthService.delete(member, oAuthPlatform); - } + public OAuth deleteOAuthInfo(User user, OAuthPlatform oAuthPlatform) { + return oAuthService.delete(user, oAuthPlatform); + } } \ No newline at end of file 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..bb9d771c 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) + .member(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.findByMemberAndPlatform(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.findByMemberAndPlatform(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/notifications/controller/NotificationController.java b/src/main/java/org/swmaestro/repl/gifthub/notifications/controller/NotificationController.java index 39b94f74..be52b093 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,7 +11,7 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.service.MemberService; import org.swmaestro.repl.gifthub.notifications.dto.DeviceTokenRequestDto; import org.swmaestro.repl.gifthub.notifications.dto.NoticeNotificationDto; @@ -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 = memberService.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..43bccc57 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,7 +4,7 @@ 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.notifications.NotificationType; @@ -27,7 +27,7 @@ public class FCMNotificationService { private final MemberService memberService; 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 = memberService.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..544135a2 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,7 +5,7 @@ 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.exception.BusinessException; @@ -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) 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 index cbbb89db..a2a572fa 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java +++ b/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java @@ -1,20 +1,20 @@ package org.swmaestro.repl.gifthub.security; +import java.util.Collection; + 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; +import org.swmaestro.repl.gifthub.auth.entity.User; public class CustomUserDetails implements UserDetails { - private final Member member; + private final User user; - public CustomUserDetails(Member member) { - this.member = member; + public CustomUserDetails(User user) { + this.user = user; } - public final Member getMember() { - return member; + public final User getMember() { + return user; } @Override @@ -24,12 +24,12 @@ public Collection getAuthorities() { @Override public String getPassword() { - return member.getPassword(); + return user.getPassword(); } @Override public String getUsername() { - return member.getUsername(); + return user.getUsername(); } @Override diff --git a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java index d782400d..aaacd9a5 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java @@ -1,13 +1,14 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +import lombok.RequiredArgsConstructor; + @Service @RequiredArgsConstructor public class JpaUserDetailsService implements UserDetailsService { @@ -15,11 +16,11 @@ public class JpaUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - Member member = memberRepository.findByUsername(username); - if (member != null) { - return new CustomUserDetails(member); + User user = memberRepository.findByUsername(username); + if (user != null) { + return new CustomUserDetails(user); } else { - return (UserDetails) new UsernameNotFoundException("User not found with username: " + username); + return (UserDetails)new UsernameNotFoundException("User not found with username: " + username); } } 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..81665fd4 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; @@ -30,15 +30,15 @@ public class PendingVoucher { @ManyToOne @JoinColumn(name = "member_id", nullable = false) - private Member member; + 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; } } 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..143dad8f 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; @@ -50,21 +50,21 @@ public class Voucher extends BaseTimeEntity { @ManyToOne @JoinColumn(name = "member_id", nullable = false) - private Member member; + 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 d4cec546..18cbbf0a 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 @@ -3,7 +3,7 @@ import java.time.LocalDateTime; import org.springframework.data.annotation.CreatedDate; -import org.swmaestro.repl.gifthub.auth.entity.Member; +import org.swmaestro.repl.gifthub.auth.entity.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -27,7 +27,7 @@ public class VoucherUsageHistory { @ManyToOne @JoinColumn(name = "member_id", nullable = false) - private Member member; + private User user; @ManyToOne @JoinColumn(name = "voucher_id", nullable = false) @@ -42,10 +42,10 @@ public class VoucherUsageHistory { private LocalDateTime createdAt; @Builder - public VoucherUsageHistory(Long id, Member member, Voucher voucher, int amount, String place, - LocalDateTime createdAt) { + public VoucherUsageHistory(Long id, User user, Voucher voucher, int amount, String place, + LocalDateTime createdAt) { this.id = id; - this.member = member; + this.user = user; this.voucher = voucher; this.amount = amount; this.place = place; 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..04a5da3d 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 user) { PendingVoucher pendingVoucher = PendingVoucher.builder() - .member(member) + .user(user) .build(); pendingVoucherRepository.save(pendingVoucher); } - public void delete(Member member) { - PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(member.getId()); + public void delete(User user) { + PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(user.getId()); //예외 처리 if (pendingVoucher == null) { throw new BusinessException("PendingVoucher가 존재하지 않습니다.", StatusEnum.NOT_FOUND); 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 5bf91d24..999875e7 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 @@ -76,7 +76,7 @@ public VoucherSaveResponseDto save(String username, VoucherSaveRequestDto vouche .expiresAt(DateConverter.stringToLocalDate(voucherSaveRequestDto.getExpiresAt())) .imageUrl(imageUrl) .balance(product.getPrice()) - .member(memberService.read(username)) + .user(memberService.read(username)) .build(); return VoucherSaveResponseDto.builder() @@ -227,7 +227,7 @@ public VoucherUseResponseDto use(String username, Long voucherId, VoucherUseRequ } VoucherUsageHistory voucherUsageHistory = VoucherUsageHistory.builder() - .member(memberService.read(username)) + .user(memberService.read(username)) .voucher(voucher.get()) .amount(voucherUseRequestDto.getAmount()) .place(voucherUseRequestDto.getPlace()) diff --git a/src/main/resources/gpt/question.txt b/src/main/resources/gpt/question.txt index 1614de21..e69de29b 100644 --- a/src/main/resources/gpt/question.txt +++ b/src/main/resources/gpt/question.txt @@ -1,14 +0,0 @@ -Please categorize them into 4 categories: brand name(where to use products or gift certificates), product name(gift certificates to use), expiration date, and barcode number. -But please keep this format and return it based on Korean. -However, you don't have to choose only one category from the given strings, you can combine the given strings to categorize them. -For example, given the string ["Iced Café Americano T2", "+ Mascarpone Tiramisu", "Say", "THANKS"], categorize "Iced Café Americano T2 + Mascarpone Tiramisu" as product_name. - -The contents of the strings in the list in the given texts json should not be changed, only the strings in the list themselves should be sorted. -And Return the expiration date in this format, where year is a 4-digit number and month and day are 2-digit numbers. -And the barcode number has 12 digits. Remove any hyphens or spaces and return it as 12 consecutive digits. -If you can't categorize it, return an empty value in the JSON structure below. -"year-month-day" -{"brand_name" : -"product_name" : -"expires_at" : -"barcode": } 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..fb321033 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,8 +17,8 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.service.MemberService; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.util.JwtProvider; @@ -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) + .member(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(memberService.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) + .member(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(memberService.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..955a7ab4 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,7 +16,7 @@ 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.entity.User; import org.swmaestro.repl.gifthub.auth.service.MemberService; import org.swmaestro.repl.gifthub.notifications.dto.DeviceTokenRequestDto; import org.swmaestro.repl.gifthub.notifications.dto.NotificationReadResponseDto; @@ -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(memberService.read(username)).thenReturn(user); + when(notificationService.deleteDeviceToken(user, deviceTokenRequestDto.getToken())).thenReturn(true); mockMvc.perform(delete("/notifications/device").header("Authorization", "Bearer " + accessToken) .contentType("application/json") From 75ca104219e5750ae886b188ead6d0bc02c284bc Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 12 Oct 2023 15:58:39 +0900 Subject: [PATCH 03/11] chore: rename member to user --- ...berRepository.java => UserRepository.java} | 2 +- .../{MemberService.java => UserService.java} | 10 +++- .../gifthub/security/CustomUserDetails.java | 54 ------------------- .../security/JpaUserDetailsService.java | 12 ++++- 4 files changed, 20 insertions(+), 58 deletions(-) rename src/main/java/org/swmaestro/repl/gifthub/auth/repository/{MemberRepository.java => UserRepository.java} (78%) rename src/main/java/org/swmaestro/repl/gifthub/auth/service/{MemberService.java => UserService.java} (93%) delete mode 100644 src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java similarity index 78% rename from src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java rename to src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java index 60c45a79..5f62009a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/MemberRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.swmaestro.repl.gifthub.auth.entity.User; -public interface MemberRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { User findByUsername(String username); 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 93% 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 7bbfd810..8f90f1ab 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; @@ -26,7 +29,7 @@ @Service @RequiredArgsConstructor -public class MemberService { +public class UserService implements UserDetailsService { private final MemberRepository memberRepository; private final PasswordEncoder passwordEncoder; private final OAuthService oAuthService; @@ -153,4 +156,9 @@ public OAuth createOAuthInfo(User user, OAuthPlatform oAuthPlatform, OAuthTokenD public OAuth deleteOAuthInfo(User user, OAuthPlatform oAuthPlatform) { return oAuthService.delete(user, 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/security/CustomUserDetails.java b/src/main/java/org/swmaestro/repl/gifthub/security/CustomUserDetails.java deleted file mode 100644 index a2a572fa..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 java.util.Collection; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.swmaestro.repl.gifthub.auth.entity.User; - -public class CustomUserDetails implements UserDetails { - private final User user; - - public CustomUserDetails(User user) { - this.user = user; - } - - public final User getMember() { - return user; - } - - @Override - public Collection getAuthorities() { - return null; - } - - @Override - public String getPassword() { - return user.getPassword(); - } - - @Override - public String getUsername() { - return user.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 index aaacd9a5..0ea5cecb 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java @@ -8,9 +8,11 @@ import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; @Service @RequiredArgsConstructor +@Slf4j public class JpaUserDetailsService implements UserDetailsService { private final MemberRepository memberRepository; @@ -18,9 +20,15 @@ public class JpaUserDetailsService implements UserDetailsService { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = memberRepository.findByUsername(username); if (user != null) { - return new CustomUserDetails(user); + log.info("user: {}", user); + return User.builder() + .id(user.getId()) + .username(user.getUsername()) + .password(user.getPassword()) + .nickname(user.getNickname()) + .build(); } else { - return (UserDetails)new UsernameNotFoundException("User not found with username: " + username); + return null; } } From cc4c556c9207533cd6193116dedf60762d1cba9b Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 12 Oct 2023 16:09:40 +0900 Subject: [PATCH 04/11] chore: rename member-service to user-service --- .../auth/controller/UserController.java | 18 ++++++------- .../gifthub/auth/service/AppleService.java | 2 +- .../gifthub/auth/service/AuthService.java | 8 +++--- .../auth/service/DeviceTokenService.java | 14 +++++----- .../gifthub/auth/service/GoogleService.java | 2 +- .../gifthub/auth/service/KakaoService.java | 2 +- .../gifthub/auth/service/NaverService.java | 2 +- .../gifthub/auth/service/UserService.java | 26 +++++++++---------- .../controller/NotificationController.java | 6 ++--- .../service/FCMNotificationService.java | 6 ++--- .../service/NotificationService.java | 8 +++--- .../security/JpaUserDetailsService.java | 6 ++--- .../vouchers/service/VoucherSaveService.java | 14 +++++----- .../vouchers/service/VoucherService.java | 10 +++---- .../auth/controller/UserControllerTest.java | 18 ++++++------- 15 files changed, 71 insertions(+), 71 deletions(-) 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 5c931366..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 @@ -13,8 +13,8 @@ import org.swmaestro.repl.gifthub.auth.dto.MemberUpdateRequestDto; import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.service.MemberService; 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)); - User user = memberService.read(username); - memberService.createOAuthInfo(user, 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)); - User user = memberService.read(username); - memberService.deleteOAuthInfo(user, 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/service/AppleService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AppleService.java index 4f383b22..42297e8c 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 @@ -106,7 +106,7 @@ public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(user) + .user(user) .platform(OAuthPlatform.APPLE) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) 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 827af2cd..543b133a 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 @@ -11,7 +11,7 @@ import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.entity.OAuth; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +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.JwtProvider; @@ -23,11 +23,11 @@ @Service @RequiredArgsConstructor public class AuthService { - private final MemberService memberService; + private final UserService memberService; 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; @@ -125,7 +125,7 @@ private JwtTokenDto generateJwtTokenDto(User user) { */ @Transactional public void signOut(String username, SignOutDto signOutDto) { - User user = memberRepository.findByUsername(username); + User user = userRepository.findByUsername(username); if (user == null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } 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 d956540d..7d79877e 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 @@ -17,13 +17,13 @@ @RequiredArgsConstructor public class DeviceTokenService { private final DeviceTokenRepository deviceTokenRepository; - private final MemberService memberService; + private final UserService userService; /* * DeviceToken 저장 메서드 */ public void save(String username, String token) { - User user = memberService.read(username); + User user = userService.read(username); 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(user) + .user(user) .token(token) .build(); @@ -58,8 +58,8 @@ public boolean isExist(String deviceToken) { * DeviceToken 존재 여부 반환 메서드 (회원 아이디와 토큰으로) */ public boolean isExist(Long memberId, String deviceToken) { - MemberReadResponseDto memberDto = memberService.read(memberId); - User user = memberService.read(memberDto.getUsername()); + MemberReadResponseDto memberDto = userService.read(memberId); + User user = userService.read(memberDto.getUsername()); return deviceTokenRepository.findByMemberAndToken(user, deviceToken).isPresent(); } @@ -75,8 +75,8 @@ public List list() { * DeviceToken 전체 조회 메서드(memberId) */ public List list(Long memberId) { - MemberReadResponseDto memberDto = memberService.read(memberId); - User user = memberService.read(memberDto.getUsername()); + MemberReadResponseDto memberDto = userService.read(memberId); + User user = userService.read(memberDto.getUsername()); return deviceTokenRepository.findAllByMember(user); } 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 3d3add92..3375425c 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 @@ -88,7 +88,7 @@ public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(user) + .user(user) .platform(OAuthPlatform.GOOGLE) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) 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 c8989ed9..945d745a 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 @@ -86,7 +86,7 @@ public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(user) + .user(user) .platform(OAuthPlatform.KAKAO) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) 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 bb9d771c..47a01671 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 @@ -91,7 +91,7 @@ public OAuth create(User user, OAuthUserInfoDto oAuthUserInfoDto) { } OAuth oAuth = OAuth.builder() - .member(user) + .user(user) .platform(OAuthPlatform.NAVER) .platformId(oAuthUserInfoDto.getId()) .email(oAuthUserInfoDto.getEmail()) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java index 8f90f1ab..45391f11 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java @@ -20,7 +20,7 @@ import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto; import org.swmaestro.repl.gifthub.auth.entity.OAuth; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +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; @@ -30,7 +30,7 @@ @Service @RequiredArgsConstructor public class UserService implements UserDetailsService { - private final MemberRepository memberRepository; + private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final OAuthService oAuthService; @@ -54,11 +54,11 @@ public User create(User user) { } User encodedUser = passwordEncryption(user); - return memberRepository.save(encodedUser); + return userRepository.save(encodedUser); } public boolean isDuplicateUsername(String username) { - return memberRepository.findByUsername(username) != null; + return userRepository.findByUsername(username) != null; } public boolean isValidatePassword(String password) { @@ -70,7 +70,7 @@ public boolean isValidatePassword(String password) { } public User read(String username) { - User user = memberRepository.findByUsername(username); + User user = userRepository.findByUsername(username); if (user == null) { return null; } @@ -78,7 +78,7 @@ public User read(String username) { } public MemberReadResponseDto read(Long id) { - Optional member = memberRepository.findById(id); + Optional member = userRepository.findById(id); if (member.isEmpty()) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -90,15 +90,15 @@ public MemberReadResponseDto read(Long id) { } public int count() { - return (int)memberRepository.count(); + return (int)userRepository.count(); } public List list() { - return memberRepository.findAll(); + return userRepository.findAll(); } public MemberUpdateResponseDto update(String username, Long userId, MemberUpdateRequestDto memberUpdateRequestDto) { - User user = memberRepository.findByUsername(username); + User user = userRepository.findByUsername(username); if (user == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -117,7 +117,7 @@ public MemberUpdateResponseDto update(String username, Long userId, MemberUpdate } user.setPassword(passwordEncoder.encode(memberUpdateRequestDto.getPassword())); } - memberRepository.save(user); + userRepository.save(user); return MemberUpdateResponseDto.builder() .id(user.getId()) .nickname(user.getNickname()) @@ -125,11 +125,11 @@ public MemberUpdateResponseDto update(String username, Long userId, MemberUpdate } public boolean isDuplicateNickname(String nickname) { - return memberRepository.findByNickname(nickname) != null; + return userRepository.findByNickname(nickname) != null; } public MemberDeleteResponseDto delete(Long id) { - User user = memberRepository.findById(id) + User user = userRepository.findById(id) .orElseThrow(() -> new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND)); if (!user.getDeletedAt().equals(null)) { @@ -137,7 +137,7 @@ public MemberDeleteResponseDto delete(Long id) { } user.setDeletedAt(LocalDateTime.now()); - memberRepository.save(user); + userRepository.save(user); return MemberDeleteResponseDto.builder() .id(id) 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 be52b093..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 @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +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,7 +87,7 @@ public ResponseEntity deleteDeviceToken( @RequestHeader("Authorization") String accessToken, @RequestBody DeviceTokenRequestDto deviceTokenRequestDto) { String username = jwtProvider.getUsername(accessToken.substring(7)); - User user = memberService.read(username); + User user = userService.read(username); notificationService.deleteDeviceToken(user, deviceTokenRequestDto.getToken()); return ResponseEntity.ok( SuccessMessage.builder() 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 43bccc57..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 @@ -6,7 +6,7 @@ import org.swmaestro.repl.gifthub.auth.entity.DeviceToken; 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,7 +24,7 @@ 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.getTargetUser().getId()); @@ -87,7 +87,7 @@ public void sendNotification(NoticeNotificationDto noticeNotificationDto) { * title과 body를 받아서 특정 회원에게 알림을 보내는 메서드(username으로 검색) */ public void sendNotification(String title, String body, String username) { - User user = memberService.read(username); + User user = userService.read(username); NoticeNotificationDto noticeNotificationDto = NoticeNotificationDto.builder() .title(title) 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 544135a2..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 @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; 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); @@ -96,7 +96,7 @@ public Notification save(User user, Voucher voucher, NotificationType type, Stri * 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/security/JpaUserDetailsService.java b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java index 0ea5cecb..483c98ff 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java @@ -5,7 +5,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; +import org.swmaestro.repl.gifthub.auth.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,11 +14,11 @@ @RequiredArgsConstructor @Slf4j public class JpaUserDetailsService implements UserDetailsService { - private final MemberRepository memberRepository; + private final UserRepository userRepository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - User user = memberRepository.findByUsername(username); + User user = userRepository.findByUsername(username); if (user != null) { log.info("user: {}", user); return User.builder() 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..f3eeb2aa 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)); }); } 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 999875e7..80ef1cac 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; @@ -38,7 +38,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 VoucherUsageHistoryRepository voucherUsageHistoryRepository; private final PendingVoucherService pendingVoucherService; @@ -76,7 +76,7 @@ public VoucherSaveResponseDto save(String username, VoucherSaveRequestDto vouche .expiresAt(DateConverter.stringToLocalDate(voucherSaveRequestDto.getExpiresAt())) .imageUrl(imageUrl) .balance(product.getPrice()) - .user(memberService.read(username)) + .user(userService.read(username)) .build(); return VoucherSaveResponseDto.builder() @@ -121,7 +121,7 @@ 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); } @@ -227,7 +227,7 @@ public VoucherUseResponseDto use(String username, Long voucherId, VoucherUseRequ } VoucherUsageHistory voucherUsageHistory = VoucherUsageHistory.builder() - .user(memberService.read(username)) + .user(userService.read(username)) .voucher(voucher.get()) .amount(voucherUseRequestDto.getAmount()) .place(voucherUseRequestDto.getPlace()) 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 fb321033..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 @@ -19,7 +19,7 @@ import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto; import org.swmaestro.repl.gifthub.auth.entity.OAuth; import org.swmaestro.repl.gifthub.auth.entity.User; -import org.swmaestro.repl.gifthub.auth.service.MemberService; +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") @@ -118,7 +118,7 @@ void createOAuthInfo() throws Exception { OAuth oAuth = OAuth.builder() .platform(OAuthPlatform.NAVER) .platformId("my_naver_unique_id") - .member(user) + .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(User.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") @@ -151,14 +151,14 @@ void deleteOAuthInfo() throws Exception { OAuth oAuth = OAuth.builder() .platform(OAuthPlatform.NAVER) .platformId("my_naver_unique_id") - .member(user) + .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(User.class), any(OAuthPlatform.class))).thenReturn(oAuth); + when(userService.deleteOAuthInfo(any(User.class), any(OAuthPlatform.class))).thenReturn(oAuth); // then mockMvc.perform(delete("/users/oauth/naver") From 6f521b80b4a40c649f2113c8dfc24a92d64e3c0a Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 12 Oct 2023 20:50:26 +0900 Subject: [PATCH 05/11] chore: rename member to user --- .../auth/repository/DeviceTokenRepository.java | 4 ++-- .../gifthub/auth/repository/OAuthRepository.java | 4 ++-- .../repl/gifthub/auth/service/AppleService.java | 4 ++-- .../repl/gifthub/auth/service/AuthService.java | 10 +++++----- .../gifthub/auth/service/DeviceTokenService.java | 4 ++-- .../repl/gifthub/auth/service/GoogleService.java | 4 ++-- .../repl/gifthub/auth/service/KakaoService.java | 4 ++-- .../repl/gifthub/auth/service/NaverService.java | 4 ++-- .../repository/PendingVoucherRepository.java | 4 ++-- .../vouchers/repository/VoucherRepository.java | 4 ++-- .../vouchers/service/PendingVoucherService.java | 4 ++-- .../gifthub/vouchers/service/VoucherService.java | 12 ++++++------ 12 files changed, 31 insertions(+), 31 deletions(-) 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 5efff734..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 @@ -10,7 +10,7 @@ public interface DeviceTokenRepository extends JpaRepository { Optional findByToken(String token); - Optional findByMemberAndToken(User user, String token); + Optional findByUserAndToken(User user, String token); - List findAllByMember(User user); + List findAllByUser(User user); } 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 74adab8b..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 @@ -8,9 +8,9 @@ import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; public interface OAuthRepository extends JpaRepository { - Optional findByMemberAndPlatform(User user, OAuthPlatform platform); + Optional findByUserAndPlatform(User user, OAuthPlatform platform); Optional findByPlatformAndPlatformId(OAuthPlatform platform, String platformId); - Optional deleteByMemberAndPlatform(User user, OAuthPlatform platform); + Optional deleteByUserAndPlatform(User user, OAuthPlatform platform); } 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 42297e8c..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 @@ -130,7 +130,7 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { @Override public OAuth delete(User user) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.APPLE).orElseThrow( + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.APPLE).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -139,7 +139,7 @@ public OAuth delete(User user) { @Override public boolean isExists(User user) { - return oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.APPLE).isPresent(); + 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 543b133a..3980c90b 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 @@ -23,7 +23,7 @@ @Service @RequiredArgsConstructor public class AuthService { - private final UserService memberService; + private final UserService userService; private final PasswordEncoder passwordEncoder; private final JwtProvider jwtProvider; private final OAuthService oAuthService; @@ -43,7 +43,7 @@ public JwtTokenDto signUp(SignUpDto signUpDto) { .nickname(signUpDto.getNickname()) .build(); - User savedUser = memberService.create(user); + User savedUser = userService.create(user); return generateJwtTokenDto(savedUser); } @@ -52,7 +52,7 @@ public JwtTokenDto signUp(SignUpDto signUpDto) { * @param signInDto */ public JwtTokenDto signIn(SignInDto signInDto) { - User user = memberService.read(signInDto.getUsername()); + User user = userService.read(signInDto.getUsername()); if (user == null) { throw new BusinessException("존재하지 않는 아이디입니다.", StatusEnum.BAD_REQUEST); @@ -89,11 +89,11 @@ public JwtTokenDto signIn(OAuthTokenDto oAuthTokenDto, OAuthPlatform platform) { } else { // 존재하지 않을 경우 -> 회원 가입 -> 로그인 User newUser = User.builder() - .username(memberService.generateOAuthUsername()) + .username(userService.generateOAuthUsername()) .nickname(authConfig.getDefaultNickname()) .build(); // 회원 정보 저장 - User user = memberService.create(newUser); + User user = userService.create(newUser); // oauth 정보 저장 oAuth = oAuthService.create(user, userInfo, platform); } 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 7d79877e..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 @@ -61,7 +61,7 @@ public boolean isExist(Long memberId, String deviceToken) { MemberReadResponseDto memberDto = userService.read(memberId); User user = userService.read(memberDto.getUsername()); - return deviceTokenRepository.findByMemberAndToken(user, deviceToken).isPresent(); + return deviceTokenRepository.findByUserAndToken(user, deviceToken).isPresent(); } /** @@ -77,7 +77,7 @@ public List list() { public List list(Long memberId) { MemberReadResponseDto memberDto = userService.read(memberId); User user = userService.read(memberDto.getUsername()); - return deviceTokenRepository.findAllByMember(user); + return deviceTokenRepository.findAllByUser(user); } /* 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 3375425c..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 @@ -112,7 +112,7 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { @Override public OAuth delete(User user) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.GOOGLE).orElseThrow( + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.GOOGLE).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -121,7 +121,7 @@ public OAuth delete(User user) { @Override public boolean isExists(User user) { - return oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.GOOGLE).isPresent(); + 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 945d745a..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 @@ -110,7 +110,7 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { @Override public OAuth delete(User user) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.KAKAO).orElseThrow( + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.KAKAO).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -119,7 +119,7 @@ public OAuth delete(User user) { @Override public boolean isExists(User user) { - return oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.KAKAO).isPresent(); + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.KAKAO).isPresent(); } @Override 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 47a01671..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 @@ -115,7 +115,7 @@ public OAuth read(OAuthUserInfoDto oAuthUserInfoDto) { @Override public OAuth delete(User user) { - OAuth oAuth = oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.NAVER).orElseThrow( + OAuth oAuth = oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.NAVER).orElseThrow( () -> new BusinessException("존재하지 않는 OAuth 계정입니다.", StatusEnum.NOT_FOUND) ); oAuth.setDeletedAt(LocalDateTime.now()); @@ -124,7 +124,7 @@ public OAuth delete(User user) { @Override public boolean isExists(User user) { - return oAuthRepository.findByMemberAndPlatform(user, OAuthPlatform.NAVER).isPresent(); + return oAuthRepository.findByUserAndPlatform(user, OAuthPlatform.NAVER).isPresent(); } @Override 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..fd7cd0fc 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 userId); - int countByMemberId(Long memberId); + int countByUserId(Long userId); } 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..7dbefae2 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 userId); } 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 04a5da3d..79e5ebd4 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 @@ -22,7 +22,7 @@ public void create(User user) { } public void delete(User user) { - PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(user.getId()); + PendingVoucher pendingVoucher = pendingVoucherRepository.findByUserId(user.getId()); //예외 처리 if (pendingVoucher == null) { throw new BusinessException("PendingVoucher가 존재하지 않습니다.", StatusEnum.NOT_FOUND); @@ -31,6 +31,6 @@ public void delete(User user) { } public int count(Long memberId) { - return pendingVoucherRepository.countByMemberId(memberId); + return pendingVoucherRepository.countByUserId(memberId); } } 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 80ef1cac..b886d062 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 @@ -97,7 +97,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); @@ -125,7 +125,7 @@ public VoucherListResponseDto list(Long userId, String username) { throw new BusinessException("상품권을 조회할 권한이 없습니다.", StatusEnum.FORBIDDEN); } - List vouchers = voucherRepository.findAllByMemberId(userId); + List vouchers = voucherRepository.findAllByUserId(userId); List voucherIdList = new ArrayList<>(); for (Voucher voucher : vouchers) { // 삭제된 기프티콘은 조회되지 않도록 함 @@ -145,7 +145,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()); @@ -201,7 +201,7 @@ public VoucherUseResponseDto use(String username, Long voucherId, VoucherUseRequ throw new BusinessException("사용처를 입력해주세요.", StatusEnum.BAD_REQUEST); } Optional voucher = voucherRepository.findById(voucherId); - List vouchers = voucherRepository.findAllByMemberUsername(username); + List vouchers = voucherRepository.findAllByUserUsername(username); List voucherUsageHistories = voucherUsageHistoryRepository.findAllByVoucherId(voucherId); if (voucher.isEmpty()) { @@ -251,7 +251,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); @@ -290,7 +290,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; From 3745f205efbc99f9177f6e6ee91cca74eec728e3 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Fri, 13 Oct 2023 14:18:23 +0900 Subject: [PATCH 06/11] feat: add default role --- .../java/org/swmaestro/repl/gifthub/auth/entity/User.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 index 9621f147..5500eab0 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; +import org.hibernate.annotations.ColumnDefault; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -50,14 +51,16 @@ public class User extends BaseTimeEntity implements UserDetails { @Enumerated(EnumType.ORDINAL) @Column(columnDefinition = "TINYINT", nullable = false) - private Role role; + @ColumnDefault("1") + private Role role = Role.USER; @Builder - public User(Long id, String username, String password, String nickname) { + 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 From 37559a1b8ce12437f5c1a55a2ed39a589a1822f8 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Sat, 14 Oct 2023 17:54:31 +0900 Subject: [PATCH 07/11] fix: remove jpa-user-details-service --- .../security/JpaUserDetailsService.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java 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 483c98ff..00000000 --- a/src/main/java/org/swmaestro/repl/gifthub/security/JpaUserDetailsService.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.swmaestro.repl.gifthub.security; - -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.User; -import org.swmaestro.repl.gifthub.auth.repository.UserRepository; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Service -@RequiredArgsConstructor -@Slf4j -public class JpaUserDetailsService implements UserDetailsService { - private final UserRepository userRepository; - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - User user = userRepository.findByUsername(username); - if (user != null) { - log.info("user: {}", user); - return User.builder() - .id(user.getId()) - .username(user.getUsername()) - .password(user.getPassword()) - .nickname(user.getNickname()) - .build(); - } else { - return null; - } - - } -} From 229dc965984dd9d8fd56dd99140c7985871c6fc0 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Sat, 14 Oct 2023 17:55:45 +0900 Subject: [PATCH 08/11] refactor: modifiy jwt-util --- .../org/swmaestro/repl/gifthub/util/JwtProvider.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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()); } From 9bf85562b88d1e3e047e2e21c23a69a18effa0ea Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Sat, 14 Oct 2023 18:01:13 +0900 Subject: [PATCH 09/11] fix: modify column-name member_id to user_id --- .../org/swmaestro/repl/gifthub/auth/entity/DeviceToken.java | 2 +- .../org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java | 2 +- .../repl/gifthub/vouchers/entity/VoucherUsageHistory.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 2301a72d..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,7 +23,7 @@ public class DeviceToken extends BaseTimeEntity { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @Column(length = 200) 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 143dad8f..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 @@ -49,7 +49,7 @@ public class Voucher extends BaseTimeEntity { private String imageUrl; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @Column 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 18cbbf0a..faee5b4d 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 @@ -26,7 +26,7 @@ public class VoucherUsageHistory { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @ManyToOne From 71fbd9ab7f35a2120c6186b5047bee351add8ed5 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Sat, 14 Oct 2023 18:38:46 +0900 Subject: [PATCH 10/11] fix: resolve conflict --- .../controller/VoucherController.java | 8 +- .../gifthub/vouchers/dto/GptResponseDto.java | 6 + .../vouchers/dto/SearchResponseDto.java | 6 + .../vouchers/dto/VoucherUseResponseDto.java | 4 +- .../vouchers/entity/PendingVoucher.java | 4 +- .../vouchers/entity/VoucherUsageHistory.java | 10 +- .../repository/PendingVoucherRepository.java | 6 +- .../repository/VoucherRepository.java | 6 +- .../service/PendingVoucherService.java | 10 +- .../vouchers/service/VoucherSaveService.java | 1 - .../vouchers/service/VoucherService.java | 246 +++++++++++++----- .../service/VoucherUsageHistoryService.java | 31 +++ src/main/resources/gpt/question.txt | 14 + .../controller/VoucherControllerTest.java | 77 +++++- 14 files changed, 334 insertions(+), 95 deletions(-) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java index e987bdb5..952726e7 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java @@ -64,8 +64,8 @@ public ResponseEntity saveVoucherImage(HttpServletRequest request) thro .build()); } - @PostMapping - @Operation(summary = "Voucher 등록 메서드", description = "클라이언트에서 요청한 기프티콘 정보를 저장하기 위한 메서드입니다.") + @PostMapping("/manual") + @Operation(summary = "Voucher 등록 메서드", description = "클라이언트에서 요청한 기프티콘 정보를 수동 저장하기 위한 메서드입니다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "기프티콘 등록 성공"), @ApiResponse(responseCode = "400(404-1)", description = "존재하지 않는 브랜드 입력"), @@ -172,8 +172,8 @@ public ResponseEntity deleteVoucher(HttpServletRequest request, @PathVa .build()); } - @PostMapping("/test") - @Operation(summary = "Voucher 등록 확장 메서드", description = "기존 기능의 확장으로, 기프티콘 정보를 저장하기 위한 메서드입니다. 비동기 방식으로 처리되며 현재는 테스트 버전입니다.") + @PostMapping + @Operation(summary = "Voucher 등록 확장 메서드", description = "클라이언트에서 요청한 기프티콘 자동 등록을 위한 메서드입니다. 비동기 방식으로 처리됩니다. 처리가 완료되면 FCM에 처리 완료 알림 요청을 보냅니다.") @ApiResponses({ @ApiResponse(responseCode = "200(202)", description = "기프티콘 등록 요청"), }) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/GptResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/GptResponseDto.java index 3caa4571..5fc812da 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/GptResponseDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/GptResponseDto.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -30,4 +31,9 @@ public static class Message { private String content; } } + + @Builder + public GptResponseDto(List choices) { + this.choices = choices; + } } \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/SearchResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/SearchResponseDto.java index f24d1d74..9fd2f14c 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/SearchResponseDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/SearchResponseDto.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -43,4 +44,9 @@ public static class Source { private Long productId; } + + @Builder + public SearchResponseDto(Hits hits) { + this.hits = hits; + } } \ No newline at end of file diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUseResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUseResponseDto.java index 2a7b6430..78fe6b5a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUseResponseDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUseResponseDto.java @@ -15,10 +15,10 @@ public class VoucherUseResponseDto { private Long usageId; private Long voucherId; private int balance; - private int price; + private Integer price; @Builder - public VoucherUseResponseDto(Long usageId, Long voucherId, int balance, int price) { + public VoucherUseResponseDto(Long usageId, Long voucherId, int balance, Integer price) { this.usageId = usageId; this.voucherId = voucherId; this.balance = balance; 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 81665fd4..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 @@ -29,7 +29,7 @@ public class PendingVoucher { private Long id; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @CreatedDate @@ -41,4 +41,4 @@ public PendingVoucher(Long id, User user) { this.id = id; this.user = user; } -} +} \ 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 faee5b4d..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 @@ -3,10 +3,12 @@ import java.time.LocalDateTime; import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.swmaestro.repl.gifthub.auth.entity.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -19,6 +21,7 @@ @Entity @Getter +@EntityListeners(AuditingEntityListener.class) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class VoucherUsageHistory { @Id @@ -33,7 +36,8 @@ public class VoucherUsageHistory { @JoinColumn(name = "voucher_id", nullable = false) private Voucher voucher; - private int amount; + @Column(nullable = true) + private Integer amount; private String place; @@ -42,7 +46,7 @@ public class VoucherUsageHistory { private LocalDateTime createdAt; @Builder - public VoucherUsageHistory(Long id, User user, Voucher voucher, int amount, String place, + public VoucherUsageHistory(Long id, User user, Voucher voucher, Integer amount, String place, LocalDateTime createdAt) { this.id = id; this.user = user; @@ -51,4 +55,4 @@ public VoucherUsageHistory(Long id, User user, Voucher voucher, int amount, Stri 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 fd7cd0fc..5d3e784f 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 findByUserId(Long userId); + PendingVoucher findByMemberId(Long memberId); - int countByUserId(Long userId); -} + int countByMemberId(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 7dbefae2..84023f3f 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 findAllByUserUsername(String username); + List findAllByMemberUsername(String username); - List findAllByUserId(Long userId); + List findAllByMemberId(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 79e5ebd4..678d3fbb 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 @@ -14,15 +14,15 @@ public class PendingVoucherService { private final PendingVoucherRepository pendingVoucherRepository; - public void create(User user) { + public void create(User member) { PendingVoucher pendingVoucher = PendingVoucher.builder() - .user(user) + .user(member) .build(); pendingVoucherRepository.save(pendingVoucher); } public void delete(User user) { - PendingVoucher pendingVoucher = pendingVoucherRepository.findByUserId(user.getId()); + PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(user.getId()); //예외 처리 if (pendingVoucher == null) { throw new BusinessException("PendingVoucher가 존재하지 않습니다.", StatusEnum.NOT_FOUND); @@ -31,6 +31,6 @@ public void delete(User user) { } public int count(Long memberId) { - return pendingVoucherRepository.countByUserId(memberId); + return pendingVoucherRepository.countByMemberId(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 f3eeb2aa..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 @@ -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 b886d062..824f7789 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 @@ -23,9 +23,7 @@ import org.swmaestro.repl.gifthub.vouchers.entity.Brand; import org.swmaestro.repl.gifthub.vouchers.entity.Product; import org.swmaestro.repl.gifthub.vouchers.entity.Voucher; -import org.swmaestro.repl.gifthub.vouchers.entity.VoucherUsageHistory; import org.swmaestro.repl.gifthub.vouchers.repository.VoucherRepository; -import org.swmaestro.repl.gifthub.vouchers.repository.VoucherUsageHistoryRepository; import lombok.RequiredArgsConstructor; @@ -39,8 +37,8 @@ public class VoucherService { private final ProductService productService; private final VoucherRepository voucherRepository; private final UserService userService; - private final VoucherUsageHistoryRepository voucherUsageHistoryRepository; private final PendingVoucherService pendingVoucherService; + private final VoucherUsageHistoryService voucherUsageHistoryService; /* 기프티콘 저장 메서드 @@ -56,6 +54,7 @@ public VoucherSaveResponseDto save(String username, VoucherSaveRequestDto vouche .brand(brand) .name(voucherSaveRequestDto.getProductName()) .imageUrl(storageService.getDefaultImagePath(voucherDirName)) + .isReusable(1) .build(); return productService.save(newProduct); }); @@ -97,7 +96,7 @@ public Voucher read(Long id) { */ public VoucherReadResponseDto read(Long id, String username) { Optional voucher = voucherRepository.findById(id); - List vouchers = voucherRepository.findAllByUserUsername(username); + List vouchers = voucherRepository.findAllByMemberUsername(username); if (voucher.isEmpty()) { throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); @@ -125,7 +124,7 @@ public VoucherListResponseDto list(Long userId, String username) { throw new BusinessException("상품권을 조회할 권한이 없습니다.", StatusEnum.FORBIDDEN); } - List vouchers = voucherRepository.findAllByUserId(userId); + List vouchers = voucherRepository.findAllByMemberId(userId); List voucherIdList = new ArrayList<>(); for (Voucher voucher : vouchers) { // 삭제된 기프티콘은 조회되지 않도록 함 @@ -145,7 +144,7 @@ public VoucherListResponseDto list(Long userId, String username) { 사용자 별 기프티콘 목록 조회 메서드(username으로 조회) */ public List list(String username) { - List vouchers = voucherRepository.findAllByUserUsername(username); + List vouchers = voucherRepository.findAllByMemberUsername(username); List voucherIdList = new ArrayList<>(); for (Voucher voucher : vouchers) { voucherIdList.add(voucher.getId()); @@ -159,24 +158,38 @@ public List list(String username) { public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto voucherUpdateRequestDto) { Voucher voucher = voucherRepository.findById(voucherId) .orElseThrow(() -> new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND)); + // Balance 수정 + if (voucherUpdateRequestDto.getBalance() != null) { + Optional product = productService.read(voucher.getBrand().getId(), voucher.getProduct().getName()); + if (product.isEmpty()) { + product = productService.read(brandService.read("기타").get().getId(), voucher.getProduct().getName()); + } - Product product = productService.read(voucher.getProduct().getName()); - - Integer productPrice = product.getPrice(); - Integer voucherUpdateRequestBalance = voucherUpdateRequestDto.getBalance(); + Integer productPrice = product.get().getPrice(); + Integer voucherUpdateRequestBalance = voucherUpdateRequestDto.getBalance(); - if (productPrice != null && voucherUpdateRequestBalance != null && voucherUpdateRequestBalance > productPrice) { - throw new BusinessException("잔액은 상품 가격보다 클 수 없습니다.", StatusEnum.BAD_REQUEST); + if (productPrice != null && voucherUpdateRequestBalance > productPrice) { + throw new BusinessException("잔액은 상품 가격보다 클 수 없습니다.", StatusEnum.BAD_REQUEST); + } } - voucher.setBarcode( voucherUpdateRequestDto.getBarcode() == null ? voucher.getBarcode() : voucherUpdateRequestDto.getBarcode()); - voucher.setBrand(voucherUpdateRequestDto.getBrandName() == null ? voucher.getBrand() : - brandService.read(voucherUpdateRequestDto.getBrandName()).get()); - voucher.setProduct(voucherUpdateRequestDto.getProductName() == null ? voucher.getProduct() : - productService.read(voucherUpdateRequestDto.getProductName())); - + // Brand 수정 + Brand brand = null; + if (voucherUpdateRequestDto.getBrandName() == null) { + brand = voucher.getBrand(); + voucher.setBrand(brand); + } else { + brand = updateBrand(voucherUpdateRequestDto); + voucher.setBrand(brand); + } + // Product 수정 + if (voucherUpdateRequestDto.getProductName() == null) { + voucher.setProduct(voucher.getProduct()); + } else { + voucher.setProduct(updateProduct(voucherUpdateRequestDto, brand, voucher.getProduct())); + } voucher.setExpiresAt(voucherUpdateRequestDto.getExpiresAt() == null ? voucher.getExpiresAt() : DateConverter.stringToLocalDate(voucherUpdateRequestDto.getExpiresAt())); @@ -194,56 +207,19 @@ public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto vou 기프티콘 사용 등록 메서드 */ public VoucherUseResponseDto use(String username, Long voucherId, VoucherUseRequestDto voucherUseRequestDto) { - if (voucherUseRequestDto.getAmount() == null || voucherUseRequestDto.getAmount() <= 0) { - throw new BusinessException("사용 금액을 입력해주세요.", StatusEnum.BAD_REQUEST); - } - if (voucherUseRequestDto.getPlace() == null) { - throw new BusinessException("사용처를 입력해주세요.", StatusEnum.BAD_REQUEST); - } - Optional voucher = voucherRepository.findById(voucherId); - List vouchers = voucherRepository.findAllByUserUsername(username); - List voucherUsageHistories = voucherUsageHistoryRepository.findAllByVoucherId(voucherId); - - if (voucher.isEmpty()) { - throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); - } - if (!vouchers.contains(voucher.get())) { - throw new BusinessException("상품권을 사용할 권한이 없습니다.", StatusEnum.FORBIDDEN); + validateVoucherUseRequest(voucherUseRequestDto); + Voucher voucher = getValidVoucherForUser(username, voucherId); + if (voucher.getProduct().getPrice() == null) { + validateVoucherWithoutPriceInfo(voucher, voucherUseRequestDto); + } else { + validateVoucherWithPriceInfo(voucher, voucherUseRequestDto); } - - if (voucher.get().getBalance() == 0) { - throw new BusinessException("이미 사용된 상품권 입니다.", StatusEnum.NOT_FOUND); - } - - int remainingBalance = voucher.get().getBalance(); - int requestedAmount = voucherUseRequestDto.getAmount(); - - if (requestedAmount > remainingBalance) { - throw new BusinessException("잔액이 부족합니다.", StatusEnum.CONFLICT); - } - - if (voucher.get().getExpiresAt().isBefore(LocalDate.now())) { - throw new BusinessException("유효기간이 만료된 상품권 입니다.", StatusEnum.CONFLICT); + Long usageId = voucherUsageHistoryService.create(voucher, voucherUseRequestDto, username); + if (voucher.getBalance() == null || voucher.getProduct().getIsReusable() == 0) { + return use(voucher, voucherId, usageId); + } else { + return use(voucher, voucherUseRequestDto, voucherId, usageId); } - - VoucherUsageHistory voucherUsageHistory = VoucherUsageHistory.builder() - .user(userService.read(username)) - .voucher(voucher.get()) - .amount(voucherUseRequestDto.getAmount()) - .place(voucherUseRequestDto.getPlace()) - .createdAt(LocalDateTime.now()) - .build(); - voucherUsageHistoryRepository.save(voucherUsageHistory); - - voucher.get().setBalance(remainingBalance - requestedAmount); - voucherRepository.save(voucher.get()); - - return VoucherUseResponseDto.builder() - .usageId(voucherUsageHistory.getId()) - .voucherId(voucherId) - .balance(remainingBalance - requestedAmount) - .price(voucher.get().getProduct().getPrice()) - .build(); } /* @@ -251,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.findAllByUserUsername(username); + List vouchers = voucherRepository.findAllByMemberUsername(username); if (voucher.isEmpty()) { throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); @@ -290,7 +266,7 @@ public VoucherReadResponseDto mapToDto(Voucher voucher) { * 사용자 별 중복 기프티콘 검사 메서드 */ public boolean isDuplicateVoucher(String username, String barcode) { - List vouchers = voucherRepository.findAllByUserUsername(username); + List vouchers = voucherRepository.findAllByMemberUsername(username); for (Voucher voucher : vouchers) { if (voucher.getBarcode().equals(barcode)) { return true; @@ -298,4 +274,136 @@ public boolean isDuplicateVoucher(String username, String barcode) { } return false; } -} + + /** + * 기프티콘 사용 등록 메서드 (non-reusabel voucher 이거나 voucher balance가 null인 경우) + */ + public VoucherUseResponseDto use(Voucher voucher, Long voucherId, Long usageId) { + voucher.setBalance(0); + voucherRepository.save(voucher); + return VoucherUseResponseDto.builder() + .usageId(usageId) + .voucherId(voucherId) + .balance(0) + .price(voucher.getProduct().getPrice()) + .build(); + } + + /** + * 기프티콘 사용 등록 메서드 (usable voucher) + */ + public VoucherUseResponseDto use(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto, + Long voucherId, Long usageId) { + int remainingBalance = voucher.getBalance(); + int requestedAmount = voucherUseRequestDto.getAmount(); + + if (requestedAmount > remainingBalance) { + throw new BusinessException("잔액이 부족합니다.", StatusEnum.CONFLICT); + } + voucher.setBalance(remainingBalance - requestedAmount); + voucherRepository.save(voucher); + + return VoucherUseResponseDto.builder() + .usageId(usageId) + .voucherId(voucherId) + .balance(remainingBalance - requestedAmount) + .price(voucher.getProduct().getPrice()) + .build(); + } + + /** + * 기프티콘 사용 요청 유효성 검사 메소드 + */ + private void validateVoucherUseRequest(VoucherUseRequestDto voucherUseRequestDto) { + if (voucherUseRequestDto.getAmount() != null && voucherUseRequestDto.getAmount() <= 0) { + throw new BusinessException("사용 금액을 입력해주세요.", StatusEnum.BAD_REQUEST); + } + if (voucherUseRequestDto.getPlace() == null) { + throw new BusinessException("사용처를 입력해주세요.", StatusEnum.BAD_REQUEST); + } + } + + /** + * Voucher 유효성 검사 메서드 + */ + private Voucher getValidVoucherForUser(String username, Long voucherId) { + Optional optionalVoucher = voucherRepository.findById(voucherId); + if (optionalVoucher.isEmpty()) { + throw new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND); + } + + Voucher voucher = optionalVoucher.get(); + if (!voucherRepository.findAllByMemberUsername(username).contains(voucher)) { + throw new BusinessException("상품권을 사용할 권한이 없습니다.", StatusEnum.FORBIDDEN); + } + if (voucher.getBalance() != null && voucher.getBalance() == 0) { + throw new BusinessException("이미 사용된 상품권 입니다.", StatusEnum.NOT_FOUND); + } + if (voucher.getExpiresAt().isBefore(LocalDate.now())) { + throw new BusinessException("유효기간이 만료된 상품권 입니다.", StatusEnum.CONFLICT); + } + return voucher; + } + + /** + * DB에 없는 정보의 기프티콘 사용 요청 유효성 검사 메서드 + */ + private void validateVoucherWithoutPriceInfo(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto) { + if (voucher.getBalance() == null && voucherUseRequestDto.getAmount() != null) { + throw new BusinessException("사용 금액을 입력할 수 없는 상품권입니다.", StatusEnum.BAD_REQUEST); + } + + if (voucher.getBalance() != null && voucherUseRequestDto.getAmount() == null) { + throw new BusinessException("사용 금액을 입력해주세요.", StatusEnum.BAD_REQUEST); + } + } + + /** + * DB에 있는 정보의 기프티콘 사용 요청 유효성 검사 메서드 + */ + private void validateVoucherWithPriceInfo(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto) { + if (voucher.getProduct().getIsReusable() == 1) { + if (voucherUseRequestDto.getAmount() == null) { + throw new BusinessException("사용 금액을 입력해주세요.", StatusEnum.BAD_REQUEST); + } + } else if (voucherUseRequestDto.getAmount() != null) { + throw new BusinessException("사용 금액을 입력할 수 없는 상품권입니다.", StatusEnum.BAD_REQUEST); + } + } + + /** + * 기프티콘 정보 수정 메서드 (수정하려고 하는 product name이 존재하지 않을 경우) + */ + public Product updateProduct(VoucherUpdateRequestDto voucherUpdateRequestDto, Brand brand, Product oldProduct) { + Optional optionalProduct = productService.read(brand.getId(), voucherUpdateRequestDto.getProductName()); + + if (optionalProduct.isEmpty()) { + 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))) + .name(voucherUpdateRequestDto.getProductName()) + .isReusable(1) + .price(oldProduct.getPrice()) + .imageUrl(storageService.getDefaultImagePath(voucherDirName)) + .build(); + return productService.save(newProduct); + }); + } + + /** + * 기프티콘 정보 수정 메서드 (Brand name) + */ + public Brand updateBrand(VoucherUpdateRequestDto voucherUpdateRequestDto) { + Brand brand = brandService.read(voucherUpdateRequestDto.getBrandName()).orElseGet(() -> { + Optional defaultBrand = brandService.read("기타"); + return defaultBrand.get(); + }); + 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 new file mode 100644 index 00000000..b1645319 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherUsageHistoryService.java @@ -0,0 +1,31 @@ +package org.swmaestro.repl.gifthub.vouchers.service; + +import org.springframework.stereotype.Service; +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; +import org.swmaestro.repl.gifthub.vouchers.repository.VoucherUsageHistoryRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class VoucherUsageHistoryService { + private final VoucherUsageHistoryRepository voucherUsageHistoryRepository; + private final UserService userService; + + /** + * 사용 내역 저장 메서드 + */ + public Long create(Voucher voucher, VoucherUseRequestDto voucherUseRequestDto, String username) { + VoucherUsageHistory voucherUsageHistory = VoucherUsageHistory.builder() + .user(userService.read(username)) + .voucher(voucher) + .amount(voucherUseRequestDto.getAmount()) + .place(voucherUseRequestDto.getPlace()) + .build(); + 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 e69de29b..a2b2c125 100644 --- a/src/main/resources/gpt/question.txt +++ b/src/main/resources/gpt/question.txt @@ -0,0 +1,14 @@ +Please categorize them into 4 categories: brand name(where to use products or gift certificates), product name(gift certificates to use), expiration date, and barcode number. +But please keep this format and return it based on Korean. +However, you don't have to choose only one category from the given strings, you can combine the given strings to categorize them. +For example, given the string ["Iced Café Americano T2", "+ Mascarpone Tiramisu", "Say", "THANKS"], categorize "Iced Café Americano T2 + Mascarpone Tiramisu" as product_name. + +The contents of the strings in the list in the given texts json should not be changed, only the strings in the list themselves should be sorted. +And Return the expiration date in this format, where year is a 4-digit number and month and day are 2-digit numbers. +And the barcode number has 12 digits. Remove any hyphens or spaces and return it as 12 consecutive digits. +If you can't categorize it, return an empty value in the JSON structure below. +"year-month-day" +{"brand_name" : +"product_name" : +"expires_at" : +"barcode": } \ No newline at end of file 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 07394241..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 @@ -16,6 +16,9 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; import org.swmaestro.repl.gifthub.util.JwtProvider; +import org.swmaestro.repl.gifthub.vouchers.dto.GptResponseDto; +import org.swmaestro.repl.gifthub.vouchers.dto.OCRDto; +import org.swmaestro.repl.gifthub.vouchers.dto.SearchResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherListResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherReadResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherSaveRequestDto; @@ -23,10 +26,16 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; +import org.swmaestro.repl.gifthub.vouchers.service.GptService; +import org.swmaestro.repl.gifthub.vouchers.service.PendingVoucherService; +import org.swmaestro.repl.gifthub.vouchers.service.SearchService; +import org.swmaestro.repl.gifthub.vouchers.service.VoucherSaveService; import org.swmaestro.repl.gifthub.vouchers.service.VoucherService; import com.fasterxml.jackson.databind.ObjectMapper; +import reactor.core.publisher.Mono; + @SpringBootTest @AutoConfigureMockMvc class VoucherControllerTest { @@ -42,9 +51,20 @@ class VoucherControllerTest { @MockBean private JwtProvider jwtProvider; + @MockBean + private VoucherSaveService voucherSaveService; + + @MockBean + private GptService gptService; + + @MockBean + private SearchService searchService; + @MockBean + private PendingVoucherService pendingVoucherService; + @Test @WithMockUser(username = "이진우", roles = "USER") - void saveVoucher() throws Exception { + void saveVoucherManual() throws Exception { // given VoucherSaveRequestDto voucher = VoucherSaveRequestDto.builder() .brandName("스타벅스") @@ -64,7 +84,7 @@ void saveVoucher() throws Exception { when(voucherService.save(anyString(), any(VoucherSaveRequestDto.class))).thenReturn(voucherSaveResponseDto); // then - mockMvc.perform(post("/vouchers") + mockMvc.perform(post("/vouchers/manual") .header("Authorization", "Bearer my_awesome_access_token") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(voucher))) @@ -220,4 +240,55 @@ void deleteVoucher() throws Exception { .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } -} + + /* + 기프티콘 자동 등록 테스트 + */ + @Test + @WithMockUser(username = "이진우", roles = "USER") + void saveVoucher() throws Exception { + //given + List texts = new ArrayList<>(); + texts.add("스타벅스"); + texts.add("아이스 아메리카노 T"); + texts.add("012345678910"); + texts.add("2023-06-15"); + + OCRDto ocrDto = OCRDto.builder() + .texts(texts) + .build(); + GptResponseDto gptResponseDto = GptResponseDto.builder() + .choices(new ArrayList<>()) + .build(); + VoucherSaveRequestDto voucherSaveRequestDto = VoucherSaveRequestDto.builder() + .brandName("스타벅스") + .productName("아이스 아메리카노 T") + .barcode("012345678910") + .expiresAt("2023-06-15") + .build(); + SearchResponseDto searchResponseDto = SearchResponseDto.builder() + .hits(new SearchResponseDto.Hits()) + .build(); + VoucherSaveResponseDto voucherSaveResponseDto = VoucherSaveResponseDto.builder() + .id(1L) + .build(); + + OCRDto mockOcrDto = new OCRDto(); // You might want to set some properties if needed + String mockUsername = "testUser"; + + when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); + when(gptService.getGptResponse(any(OCRDto.class))).thenReturn(Mono.just(gptResponseDto)); + when(searchService.search(anyString())).thenReturn(Mono.just(searchResponseDto)); + when(voucherService.save(anyString(), any(VoucherSaveRequestDto.class))).thenReturn(voucherSaveResponseDto); + + // When + voucherSaveService.execute(mockOcrDto, mockUsername); + + // Then + mockMvc.perform(post("/vouchers") + .header("Authorization", "Bearer my_awesome_access_token") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(ocrDto))) + .andExpect(status().isOk()); + } +} \ No newline at end of file From 3e855acc09a3b123af0429f89931a417b8275148 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Sat, 14 Oct 2023 19:08:14 +0900 Subject: [PATCH 11/11] fix: solved circular reference --- .../repl/gifthub/auth/config/AuthConfig.java | 8 ++++++++ .../repl/gifthub/config/SecurityConfig.java | 7 ------- .../repository/PendingVoucherRepository.java | 4 ++-- .../vouchers/repository/VoucherRepository.java | 4 ++-- .../vouchers/service/PendingVoucherService.java | 4 ++-- .../gifthub/vouchers/service/VoucherService.java | 12 ++++++------ 6 files changed, 20 insertions(+), 19 deletions(-) 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 5418115e..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,4 +15,9 @@ @Setter public class AuthConfig { private String defaultNickname; + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } 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/vouchers/repository/PendingVoucherRepository.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/repository/PendingVoucherRepository.java index 5d3e784f..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 84023f3f..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 678d3fbb..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 @@ -22,7 +22,7 @@ public void create(User member) { } public void delete(User user) { - PendingVoucher pendingVoucher = pendingVoucherRepository.findByMemberId(user.getId()); + PendingVoucher pendingVoucher = pendingVoucherRepository.findByUserId(user.getId()); //예외 처리 if (pendingVoucher == null) { throw new BusinessException("PendingVoucher가 존재하지 않습니다.", StatusEnum.NOT_FOUND); @@ -31,6 +31,6 @@ public void delete(User user) { } 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/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index 824f7789..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 @@ -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); @@ -124,7 +124,7 @@ public VoucherListResponseDto list(Long userId, String 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) {