Skip to content

Commit

Permalink
Merge pull request #86 from Senity-Waved/Refactor/#85
Browse files Browse the repository at this point in the history
Refactor: 서버 타임 리팩토링
  • Loading branch information
chaewon-io authored Apr 15, 2024
2 parents bff0072 + 46e414b commit e47f439
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 68 deletions.
22 changes: 0 additions & 22 deletions src/main/java/com/senity/waved/common/ZonedDateTimeConverter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AdminServiceImpl implements AdminService {
@Override
@Transactional(readOnly = true)
public List<AdminChallengeGroupResponseDto> getGroups() {
ZonedDateTime todayStart = ZonedDateTime.now(ZoneId.of("GMT")).truncatedTo(ChronoUnit.DAYS).minusHours(9);
ZonedDateTime todayStart = ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);
List<ChallengeGroup> groups = groupRepository.findChallengeGroupsInProgress(todayStart);

return groups.stream()
Expand Down Expand Up @@ -148,7 +148,7 @@ private MyChallenge getMyChallengeByGroupAndMemberId(ChallengeGroup group, Long

private void createCanceledVerificationNotification(Verification verification, String groupTitle, Long memberId) {
int month = verification.getCreateDate().getMonthValue();
int day = verification.getCreateDate().plusHours(9).getDayOfMonth();
int day = verification.getCreateDate().getDayOfMonth();
String message = String.format("%s의 \r\n%d월 %d일 인증이 취소되었습니다.", groupTitle, month, day);

Notification newNotification = Notification.of(memberId, "인증 취소", message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public Page<ChallengeReviewResponseDto> getReviewsPaged(Long challengeId, int pa

@Transactional
// @Scheduled(fixedDelay = 10000)
@Scheduled(cron = "0 0 16 * * SUN") // 매주 월요일 1시, 배포 서버 일요일 16시
@Scheduled(cron = "0 0 1 * * MON") // 매주 월요일 1시
public void makeChallengeGroupAndDoNotificationScheduled() {
List<Challenge> challengeList = challengeRepository.findAll();

for (Challenge challenge : challengeList) {
Long latestGroupIndex = challenge.getLatestGroupIndex();
ChallengeGroup latestGroup = getGroupByChallengeIdAndGroupIndex(challenge.getId(), latestGroupIndex);

if (latestGroup.getStartDate().plusHours(9).equals(ZonedDateTime.now(ZoneId.of("GMT")).plusHours(9).truncatedTo(ChronoUnit.DAYS))) {
if (latestGroup.getStartDate().equals(ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS))) {

Long lastGroupIndex = latestGroupIndex - 1;
ChallengeGroup lastGroup = getGroupByChallengeIdAndGroupIndex(challenge.getId(), lastGroupIndex);
Expand All @@ -97,7 +97,7 @@ public void makeChallengeGroupAndDoNotificationScheduled() {
}

@Transactional
@Scheduled(cron = "0 0 17 * * SUN")
@Scheduled(cron = "0 0 2 * * MON")
public void deleteOldNotifications() {
ZonedDateTime deleteBefore = ZonedDateTime.now().toLocalDate().minusDays(14).atStartOfDay(ZoneId.systemDefault());
notificationRepository.deleteNotificationsByCreateDate(deleteBefore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static AdminChallengeGroupResponseDto from(ChallengeGroup challengeGroup)
return AdminChallengeGroupResponseDto.builder()
.challengeGroupId(challengeGroup.getId())
.groupTitle(challengeGroup.getGroupTitle())
.startDate(challengeGroup.getStartDate().plusHours(9))
.endDate(challengeGroup.getEndDate().plusHours(9))
.startDate(challengeGroup.getStartDate())
.endDate(challengeGroup.getEndDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static ChallengeGroupHomeResponseDto of(ChallengeGroup group, Challenge c
.verificationType(challenge.getVerificationType())
.isFree(challenge.getIsFree())
.participantCount(group.getParticipantCount())
.startDate(group.getStartDate().plusHours(9))
.endDate(group.getEndDate().plusHours(9))
.startDate(group.getStartDate())
.endDate(group.getEndDate())
.challengeGroupId(group.getId())
.imageUrl(imageUrl)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static ChallengeGroupResponseDto of(ChallengeGroup group, Challenge chall
return ChallengeGroupResponseDto.builder()
.groupTitle(group.getGroupTitle())
.participantCount(group.getParticipantCount())
.startDate(group.getStartDate().plusHours(9))
.endDate(group.getEndDate().plusHours(9))
.startDate(group.getStartDate())
.endDate(group.getEndDate())
.verificationType(challenge.getVerificationType())
.description(challenge.getDescription())
.verificationDescription(challenge.getVerificationDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
public interface LikedRepository extends JpaRepository<Liked, Long> {
boolean existsByMemberIdAndVerification(Long memberId, Verification verification);
Long countLikesByVerification(Verification verification);

Optional<Liked> findByMemberIdAndVerification(Long memberId, Verification verification);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String email);

void deleteByEmail(String email);

Optional<Member> getMemberByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static MyChallengeCompletedDto of(MyChallenge myChallenge, ChallengeGroup
Boolean isSuccessed = myChallenge.getSuccessCount() < successCount ? false : true;
return MyChallengeCompletedDto.builder()
.groupTitle(group.getGroupTitle())
.startDate(group.getStartDate().plusHours(9))
.endDate(group.getEndDate().plusHours(9))
.startDate(group.getStartDate())
.endDate(group.getEndDate())
.deposit(myChallenge.getDeposit())
.challengeGroupId(group.getId())
.myChallengeId(myChallenge.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class MyChallengeProgressDto extends MyChallengeResponseDto {
public static MyChallengeProgressDto of(MyChallenge myChallenge, ChallengeGroup group, Challenge challenge, Boolean isGithubConnected) {
return MyChallengeProgressDto.builder()
.groupTitle(group.getGroupTitle())
.startDate(group.getStartDate().plusHours(9))
.endDate(group.getEndDate().plusHours(9))
.startDate(group.getStartDate())
.endDate(group.getEndDate())
.successCount(myChallenge.getSuccessCount())
.deposit(myChallenge.getDeposit())
.myChallengeId(myChallenge.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class MyChallengeResponseDto {
public static MyChallengeResponseDto of(MyChallenge myChallenge, ChallengeGroup group) {
return MyChallengeResponseDto.builder()
.groupTitle(group.getGroupTitle())
.startDate(group.getStartDate().plusHours(9))
.startDate(group.getStartDate())
.deposit(myChallenge.getDeposit())
.endDate(group.getEndDate().plusHours(9))
.endDate(group.getEndDate())
.challengeGroupId(group.getId())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MyVerifsResponseDto(MyChallenge myChallenge, ChallengeGroup group) {
myVerifs[i-1] = (int) (longMyVerifs / Math.pow(10, 14 - i) % 10);
}
this.groupTitle = group.getGroupTitle();
this.startDate = group.getStartDate().plusHours(9);
this.endDate = group.getEndDate().plusHours(9);
this.startDate = group.getStartDate();
this.endDate = group.getEndDate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.ColumnDefault;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

Expand Down Expand Up @@ -91,7 +92,7 @@ public void incrementSuccessCount() {
}

public boolean isVerified() {
ZonedDateTime currentDate = ZonedDateTime.now();
ZonedDateTime currentDate = ZonedDateTime.now(ZoneId.systemDefault());
ZonedDateTime startDate = getStartDate();
long daysFromStart = ChronoUnit.DAYS.between(startDate, currentDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void cancelAppliedMyChallenge(String email, Long myChallengeId) {
public List<MyChallengeResponseDto> getMyChallengesListed(String email, ChallengeStatus status) {
Member member = getMemberByEmail(email);
List<MyChallenge> myChallengesListed;
ZonedDateTime todayStart = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS).plusHours(9);
ZonedDateTime todayStart = ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);

switch (status) {
case PROGRESS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static NotificationResponseDto of(Notification notification) {
.notificationId(notification.getId())
.title(notification.getTitle())
.message(notification.getMessage())
.createDate(notification.getCreateDate().plusHours(9))
.createDate(notification.getCreateDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static PaymentRecordResponseDto from(PaymentRecord paymentRecord) {
.groupTitle(paymentRecord.getGroupTitle())
.status(paymentRecord.getPaymentStatus())
.deposit(paymentRecord.getDeposit())
.createDate(paymentRecord.getCreateDate().plusHours(9))
.createDate(paymentRecord.getCreateDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import com.siot.IamportRestClient.exception.IamportResponseException;
import com.siot.IamportRestClient.request.CancelData;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Optional;

@Slf4j
@Service
@AllArgsConstructor
public class PaymentRecordServiceImpl implements PaymentRecordService {
Expand Down Expand Up @@ -60,6 +63,10 @@ public void cancelChallengePayment(String email, Long myChallengeId) {
Member member = getMemberByEmail(email);
MyChallenge myChallenge = getMyChallengeById(myChallengeId);

ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);
log.info("----------------------------- now : " + now);
log.info("-------- challengeGroup startDate : " + myChallenge.getStartDate());

validateMember(member, myChallenge);
cancelImportPayment(String.valueOf(myChallenge.getImpUid()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

import com.senity.waved.domain.quiz.entity.Quiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.ZonedDateTime;
import java.util.Optional;

public interface QuizRepository extends JpaRepository<Quiz, Long> {
Optional<Quiz> findByChallengeGroupIdAndDate(Long challengeGroupId, ZonedDateTime today);

@Query("SELECT q FROM Quiz q WHERE q.challengeGroup.id = :challengeGroupId AND q.date = :quizDate")
Optional<Quiz> findQuizByChallengeGroupIdAndRequestDate(@Param("challengeGroupId") Long challengeGroupId,
@Param("quizDate") ZonedDateTime quizDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public class QuizServiceImpl implements QuizService {
@Override
public QuizResponseDto getTodaysQuiz(Long challengeGroupId) {
verificationService.IsChallengeGroupTextType(challengeGroupId);
ZonedDateTime today = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS);
ZonedDateTime today = ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);
Quiz quiz = findQuizByDate(challengeGroupId, today);

ZonedDateTime plusDate = quiz.getDate().plusHours(9);
ZonedDateTime plusDate = quiz.getDate();
return new QuizResponseDto(plusDate, quiz.getQuestion());
}

@Override
public QuizResponseDto getQuizByDate(Long challengeGroupId, Timestamp requestedQuizDate) {
ZonedDateTime quizDate = requestedQuizDate.toInstant().atZone(ZoneId.systemDefault())
.withZoneSameInstant(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS);
.withZoneSameInstant(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);
verificationService.IsChallengeGroupTextType(challengeGroupId);
Quiz quiz = findQuizByDate(challengeGroupId, quizDate);

ZonedDateTime plusDate = quiz.getDate().plusHours(9);
ZonedDateTime plusDate = quiz.getDate();
return new QuizResponseDto(plusDate, quiz.getQuestion());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private ChallengeGroup getGroupById(Long id) {
if (group.getEndDate().isAfter(ZonedDateTime.now())) {
throw new ChallengeGroupNotCompletedException("종료된 챌린지 그룹에 대해서만 리뷰 작성 가능합니다.");
} */

return group;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class LinkVerificationResponseDto extends VerificationResponseDto {
public static LinkVerificationResponseDto of(Verification verification, Member member, boolean isLiked) {
ZonedDateTime verificationDate = null;
if (verification.getCreateDate() != null) {
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime().plusHours(9);
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Seoul"));
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime();
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
}

return LinkVerificationResponseDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class PictureVerificationResponseDto extends VerificationResponseDto {
public static PictureVerificationResponseDto of(Verification verification, Member member, boolean isLiked) {
ZonedDateTime verificationDate = null;
if (verification.getCreateDate() != null) {
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime().plusHours(9);
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Seoul"));
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime();
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
}

return PictureVerificationResponseDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class TextVerificationResponseDto extends VerificationResponseDto {
public static TextVerificationResponseDto of(Verification verification, Member member, boolean isLiked) {
ZonedDateTime verificationDate = null;
if (verification.getCreateDate() != null) {
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime().plusHours(9);
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Seoul"));
LocalDateTime localDateTime = verification.getCreateDate().toLocalDateTime();
verificationDate = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
}

return TextVerificationResponseDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GithubService {

public boolean hasCommitsToday(String githubId, String token) throws IOException {
GHCommit commits = githubApi.getCommits(githubId, token);
ZonedDateTime commitDate = commits.getCommitDate().toInstant().atZone(ZoneId.of("GMT")).plusHours(9).truncatedTo(ChronoUnit.DAYS);
return commitDate.equals(ZonedDateTime.now(ZoneId.of("GMT")).plusHours(9).truncatedTo(ChronoUnit.DAYS));
ZonedDateTime commitDate = commits.getCommitDate().toInstant().atZone(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS);
return commitDate.equals(ZonedDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.DAYS));
}
}

0 comments on commit e47f439

Please sign in to comment.