diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java index 9778934e..6ea062a7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java @@ -39,7 +39,7 @@ public ResponseEntity checkUserParticipationInRushEvent(HttpServletRequ BaseUser user = (BaseUser) httpServletRequest.getAttribute("user"); return ResponseEntity .status(HttpStatus.OK) - .body(rushEventService.isExists(user.getId())); + .body(rushEventService.isExists(user.getPhoneNumber())); } @Operation(summary = "선착순 이벤트 응모", description = "해당 유저가 오늘의 이벤트에 응모합니다. optionId 값이 필요합니다. optionId 값이 1이면 왼쪽 선택지, 2이면 오른쪽 선택지에 응모합니다.") diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java index 35acc0ab..04b30988 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java @@ -13,7 +13,7 @@ public record LotteryEventParticipantsResponseDto( public static LotteryEventParticipantsResponseDto of(LotteryParticipants participant) { return new LotteryEventParticipantsResponseDto( participant.getId(), - participant.getBaseUser().getId(), + participant.getBaseUser().getPhoneNumber(), participant.getLinkClickedCount(), participant.getExpectations(), participant.getAppliedCount(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java index 6d40224a..bd97f01e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java @@ -11,7 +11,7 @@ public record RushEventParticipantResponseDto(Long id, String phoneNumber, public static RushEventParticipantResponseDto of(RushParticipants rushParticipants, Long rank){ return new RushEventParticipantResponseDto( rushParticipants.getId(), - rushParticipants.getBaseUser().getId(), + rushParticipants.getBaseUser().getPhoneNumber(), rushParticipants.getOptionId(), rushParticipants.getCreatedAt().toLocalDate(), rushParticipants.getCreatedAt().toLocalTime(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 30720d35..2d401072 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -27,11 +27,11 @@ public class RushEvent extends BaseEvent { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long rushEventId; - @OneToMany(fetch = FetchType.EAGER, mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) @JsonManagedReference private final Set options = new HashSet<>(); - @OneToMany(fetch = FetchType.EAGER, mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) private Set rushParticipants; public RushEvent() { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 93939241..563c21ab 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -14,7 +14,7 @@ public class LotteryParticipants extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY) // mappedBy 이용하면 둘 다 저장 안해도 됨 + @ManyToOne(fetch = FetchType.LAZY) // mappedBy 이용하면 둘 다 저장 안해도 됨 @JoinColumn(name = "base_user_id") @JsonBackReference @JsonIgnore diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java index c5c091fe..5245343f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java @@ -26,7 +26,7 @@ public class LotteryWinners { public LotteryWinners(LotteryParticipants lotteryParticipants) { this.id = lotteryParticipants.getId(); - this.phoneNumber = lotteryParticipants.getBaseUser().getId(); + this.phoneNumber = lotteryParticipants.getBaseUser().getPhoneNumber(); this.linkClickedCount = lotteryParticipants.getLinkClickedCount(); this.expectation = lotteryParticipants.getExpectations(); this.appliedCount = lotteryParticipants.getAppliedCount(); diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java index 94111d30..32ba6d44 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java @@ -14,12 +14,13 @@ public class RushParticipants extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private int optionId; - @OneToOne + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "base_user_id") @JsonBackReference private BaseUser baseUser; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "rush_event_id") private RushEvent rushEvent; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java index d7189cc0..c74eebd7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java @@ -8,5 +8,6 @@ @Repository public interface AdminRepository extends JpaRepository { - Optional findByIdAndPassword(String id, String password); + Optional findByPhoneNumberAndPassword(String id, String password); + Optional findByPhoneNumber(String id); } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index 2634710e..fe469e5c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -16,10 +16,10 @@ public interface LotteryParticipantsRepository extends JpaRepository { Optional findByBaseUser(BaseUser baseUser); - @Query("SELECT p FROM LotteryParticipants p WHERE p.baseUser.id LIKE :id%") + @Query("SELECT p FROM LotteryParticipants p WHERE p.baseUser.phoneNumber LIKE :id%") Page findByBaseUser_Id(@Param("id") String id, Pageable pageable); - @Query("SELECT COUNT(p) FROM LotteryParticipants p WHERE p.baseUser.id LIKE :id%") + @Query("SELECT COUNT(p) FROM LotteryParticipants p WHERE p.baseUser.phoneNumber LIKE :id%") long countByBaseUser_Id(@Param("id") String id); @Query("SELECT lp.id, lp.appliedCount From LotteryParticipants lp") diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index e3904ef2..ac247211 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -12,7 +12,7 @@ @Repository public interface RushParticipantsRepository extends JpaRepository { - boolean existsByRushEvent_RushEventIdAndBaseUser_Id(Long eventId, String userId); + boolean existsByRushEvent_RushEventIdAndBaseUser_PhoneNumber(Long eventId, String userId); long countByRushEvent_RushEventIdAndOptionId(Long eventId, int optionId); @@ -41,12 +41,12 @@ long findUserRankByEventIdAndUserId(@Param("eventId") Long eventId, Page findByRushEvent_RushEventId(Long rushEventId, Pageable pageable); - @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.id LIKE :baseUserId%") + @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.phoneNumber LIKE :baseUserId%") Page findByRushEvent_RushEventIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("baseUserId") String baseUserId, Pageable pageable); Page findByRushEvent_RushEventIdAndOptionId(Long rushEventId, int optionId, Pageable pageable); - @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.id LIKE :baseUserId%") + @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.phoneNumber LIKE :baseUserId%") Page findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("optionId") int optionId, @Param("baseUserId") String baseUserId, Pageable pageable); @@ -60,7 +60,7 @@ Page findWinnerByEventIdAndOptionId( @Query("SELECT rp FROM RushParticipants rp " + "WHERE rp.rushEvent.rushEventId = :eventId " + "AND rp.optionId = :optionId " + - "AND rp.baseUser.id LIKE :phoneNumber% " + + "AND rp.baseUser.phoneNumber LIKE :phoneNumber% " + "ORDER BY rp.id ASC ") Page findWinnerByEventIdAndOptionIdAndPhoneNumber( @Param("eventId") Long eventId, @Param("optionId") int optionId, @Param("phoneNumber") String phoneNumber, Pageable pageable @@ -74,15 +74,15 @@ Page findWinnerByEventIdAndOptionIdAndPhoneNumber( @Query("SELECT rp FROM RushParticipants rp " + "WHERE rp.rushEvent.rushEventId = :eventId " + - "AND rp.baseUser.id LIKE :phoneNumber% " + + "AND rp.baseUser.phoneNumber LIKE :phoneNumber% " + "ORDER BY rp.id ASC ") Page findByWinnerByEventIdAndPhoneNumber(@Param("eventId") Long eventId, @Param("phoneNumber") String phoneNumber, Pageable pageable); - @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.id LIKE :baseUserId%") + @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.phoneNumber LIKE :baseUserId%") long countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("optionId") int optionId, @Param("baseUserId") String baseUserId); long countByRushEvent_RushEventId(long rushEventId); - @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.id LIKE :baseUserId%") + @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.phoneNumber LIKE :baseUserId%") long countByRushEvent_RushEventIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("baseUserId") String baseUserId); } \ No newline at end of file diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index bb6451d6..aa18046b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -64,7 +64,7 @@ public class AdminService { // 어드민 인증 public Admin verifyAdmin(AdminRequestDto adminRequestDto) { - return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); + return adminRepository.findByPhoneNumberAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); } // 어드민 생성 @@ -72,7 +72,7 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { String adminId = adminRequestDto.getAdminId(); String password = adminRequestDto.getPassword(); - Admin admin = adminRepository.findById(adminId).orElse(null); + Admin admin = adminRepository.findByPhoneNumber(adminId).orElse(null); if (admin != null) throw new CustomException("이미 등록된 ID입니다.", CustomErrorCode.CONFLICT); adminRepository.save(new Admin(adminId, password, Role.ADMIN)); @@ -213,7 +213,7 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv List rushEventParticipantResponseDtoList = new ArrayList<>(); for (RushParticipants rushParticipant : rushParticipantsPage) { - String userId = rushParticipant.getBaseUser().getId(); + String userId = rushParticipant.getBaseUser().getPhoneNumber(); int userChoice = rushParticipant.getOptionId(); long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(rushEventId, userId, userChoice); rushEventParticipantResponseDtoList.add( @@ -263,7 +263,7 @@ public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId List rushEventParticipantResponseDtoList = new ArrayList<>(); for (RushParticipants rushParticipant : rushParticipantsPage) { - String userId = rushParticipant.getBaseUser().getId(); + String userId = rushParticipant.getBaseUser().getPhoneNumber(); int userChoice = rushParticipant.getOptionId(); long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(rushEventId, userId, userChoice); rushEventParticipantResponseDtoList.add( @@ -531,7 +531,7 @@ public LotteryEventExpectationsResponseDto getLotteryEventExpectations(int page, Pageable pageable = PageRequest.of(page, size); - Page casperBotPage = casperBotRepository.findByPhoneNumberAndActiveExpectations(lotteryParticipant.getBaseUser().getId(), pageable); + Page casperBotPage = casperBotRepository.findByPhoneNumberAndActiveExpectations(lotteryParticipant.getBaseUser().getPhoneNumber(), pageable); // DTO로 변환합니다. List lotteryEventExpectationResponseDtoList = casperBotPage.getContent().stream() diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index bed67f2f..4d233348 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -6,7 +6,6 @@ import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; -import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.domain.event.service.redisService.RedisService; import JGS.CasperEvent.global.entity.BaseUser; @@ -47,7 +46,7 @@ public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto cas LotteryEvent lotteryEvent = eventCacheService.getLotteryEvent(); - CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); + CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getPhoneNumber())); lotteryEvent.addAppliedCount(); participants.updateCasperId(casperBot.getCasperId()); @@ -85,7 +84,6 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto addReferralAppliedCount(casperBotRequestDto); - user.updateLotteryParticipants(participant); userRepository.save(user); } @@ -99,7 +97,7 @@ private void addReferralAppliedCount(CasperBotRequestDto casperBotRequestDto) th String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); Optional referralParticipant = lotteryParticipantsRepository.findByBaseUser( - userRepository.findById(referralId).orElse(null) + userRepository.findByPhoneNumber(referralId).orElse(null) ); referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); } catch (Exception e) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 2906c3df..6fb3f30b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -70,7 +70,7 @@ public RushEventListResponseDto getAllRushEvents() { public boolean isExists(String userId) { LocalDate today = LocalDate.now(); Long todayEventId = eventCacheService.getTodayEvent(today).rushEventId(); - return rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(todayEventId, userId); + return rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_PhoneNumber(todayEventId, userId); } @Transactional @@ -79,7 +79,7 @@ public void apply(BaseUser user, int optionId) { Long todayEventId = eventCacheService.getTodayEvent(today).rushEventId(); // 이미 응모한 회원인지 검증 - if (rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(todayEventId, user.getId())) { + if (rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_PhoneNumber(todayEventId, user.getPhoneNumber())) { throw new CustomException("이미 응모한 회원입니다.", CustomErrorCode.CONFLICT); } @@ -95,7 +95,7 @@ public void apply(BaseUser user, int optionId) { public RushEventRateResponseDto getRushEventRate(BaseUser user) { LocalDate today = LocalDate.now(); Long todayEventId = eventCacheService.getTodayEvent(today).rushEventId(); - Optional optionId = rushParticipantsRepository.getOptionIdByUserId(user.getId()); + Optional optionId = rushParticipantsRepository.getOptionIdByUserId(user.getPhoneNumber()); long leftOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 1); long rightOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 2); @@ -117,7 +117,7 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) { long leftOption = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 1); long rightOption = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 2); - Optional optionIdOptional = rushParticipantsRepository.getOptionIdByUserId(user.getId()); + Optional optionIdOptional = rushParticipantsRepository.getOptionIdByUserId(user.getPhoneNumber()); if (optionIdOptional.isEmpty()) { return new RushEventResultResponseDto( null, @@ -135,7 +135,7 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) { // 동점인 경우 if (leftOption == rightOption) { // 전체 참여자에서 등수 계산하기 - long rank = rushParticipantsRepository.findUserRankByEventIdAndUserId(todayRushEvent.rushEventId(), user.getId()); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserId(todayRushEvent.rushEventId(), user.getPhoneNumber()); // 각 옵션 선택지를 더하여 전체 참여자 수 구하기 long totalParticipants = leftOption + rightOption; @@ -149,7 +149,7 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) { long totalParticipants = (optionId == 1 ? leftOption : rightOption); // eventId, userId, optionId 를 이용하여 해당 유저가 응모한 선택지에서 등수를 가져옴 - long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayRushEvent.rushEventId(), user.getId(), optionId); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayRushEvent.rushEventId(), user.getPhoneNumber(), optionId); // 해당 유저가 선택한 옵션이 패배한 경우 if ((optionId == 1 && leftOption < rightOption) || (optionId == 2 && leftOption > rightOption)) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index c2652818..a26b3520 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -36,7 +36,7 @@ public class UrlService { //todo: 테스트 끝나면 수정필요 // 단축 url 생성 public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - String encryptedUserId = AESUtils.encrypt(user.getId(), secretKey); + String encryptedUserId = AESUtils.encrypt(user.getPhoneNumber(), secretKey); String originalUrl = clientUrl + "?" + "referralId=" + encryptedUserId; String originalLocalUrl = localClientUrl + "?" + "referralId=" + encryptedUserId; diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java index 0dec157b..21dbda9c 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java @@ -9,31 +9,34 @@ import lombok.EqualsAndHashCode; import lombok.Getter; +import java.util.List; + @Getter @Entity @EqualsAndHashCode(callSuper = false) @Inheritance(strategy = InheritanceType.JOINED) public class BaseUser extends BaseEntity { + + @Id - String id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + Long id; + + String phoneNumber; Role role; @JsonManagedReference - @OneToOne(mappedBy = "baseUser", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "baseUser", cascade = CascadeType.ALL) @JsonIgnore - private LotteryParticipants lotteryParticipants; + private List lotteryParticipants; @JsonManagedReference - @OneToOne(mappedBy = "baseUser", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "baseUser", cascade = CascadeType.ALL) @JsonIgnore - private RushParticipants rushParticipants; - - public void updateLotteryParticipants(LotteryParticipants lotteryParticipant) { - this.lotteryParticipants = lotteryParticipant; - } + private List rushParticipants; - public BaseUser(String id, Role role) { - this.id = id; + public BaseUser(String phoneNumber, Role role) { + this.phoneNumber = phoneNumber; this.role = role; } diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java index cc086358..9c5ccc36 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java @@ -69,7 +69,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha String token = getToken(httpServletRequest); BaseUser user = getAuthenticateUser(token); verifyAuthorization(requestUri, user); - log.info("값 : {}", user.getId()); + log.info("값 : {}", user.getPhoneNumber()); httpServletRequest.setAttribute("user", user); chain.doFilter(request, response); } catch (JsonParseException e) { diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/repository/UserRepository.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/repository/UserRepository.java index 8dbf311e..a262c44f 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/repository/UserRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/repository/UserRepository.java @@ -2,6 +2,8 @@ import JGS.CasperEvent.global.entity.BaseUser; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { + Optional findByPhoneNumber(String phoneNumber); } diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/service/UserService.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/service/UserService.java index 536f0fb7..56573740 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/service/UserService.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/service/UserService.java @@ -15,7 +15,7 @@ public class UserService { private final UserRepository userRepository; public BaseUser verifyUser(UserLoginDto userLoginDto) { - return userRepository.findById(userLoginDto.getPhoneNumber()).orElseGet( + return userRepository.findByPhoneNumber(userLoginDto.getPhoneNumber()).orElseGet( () -> userRepository.save(new BaseUser(userLoginDto.getPhoneNumber(), Role.USER))); } } diff --git a/Server/src/main/resources/application.yml b/Server/src/main/resources/application.yml index 3e49e647..695816b1 100644 --- a/Server/src/main/resources/application.yml +++ b/Server/src/main/resources/application.yml @@ -1,6 +1,4 @@ spring: application: name: hybrid-jgs - jpa: - show-sql: false # 데이터베이스 설정은 공통으로 지정하지 않음