Skip to content

Commit efe1466

Browse files
authored
[fix/#363] 서버 시간 수정 및 기본 설정 닉네임 길이 수정 (#364)
* fix: 애플리케이션의 시간 생성/저장/직렬화를 KST(Asia/Seoul)로 통일 * fix: 자동 생성 닉네임 20글자 초과 버그 수정 * chore: 닉네임 정책 변경(숫자 포함 가능) 및 테스트 수정
1 parent 4d5f271 commit efe1466

17 files changed

Lines changed: 151 additions & 25 deletions

File tree

clokey-api/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN gradle :clokey-api:build -x test --no-daemon
55

66
FROM eclipse-temurin:21-jdk-jammy
77
WORKDIR /app
8+
ENV TZ=Asia/Seoul
89
COPY --from=builder /app/clokey-api/build/libs/*.jar app.jar
910
EXPOSE 8080
10-
ENTRYPOINT ["java", "-jar", "app.jar"]
11+
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-jar", "app.jar"]

clokey-api/dev-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- "8080:8080"
1010
environment:
1111
SPRING_PROFILES_ACTIVE: dev
12+
TZ: Asia/Seoul
1213

1314
# Database
1415
DEV_MYSQL_HOST: ${DEV_MYSQL_HOST}

clokey-api/prod-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- "8080:8080"
1010
environment:
1111
SPRING_PROFILES_ACTIVE: prod
12+
TZ: Asia/Seoul
1213

1314
# Database
1415
PROD_MYSQL_HOST: ${PROD_MYSQL_HOST}

clokey-api/src/main/java/org/clokey/domain/auth/util/UniqueUtil.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@Component
88
public class UniqueUtil {
99

10+
private static final int MAX_NICKNAME_LENGTH = 20;
1011
private static final String[] PREFIX_NAMES = {"미니멀한", "모던한", "케주얼한", "스트릿한"};
1112

1213
private static final String[] CLOTHING_CATEGORIES = {
@@ -22,9 +23,23 @@ public String generateRandomNickname() {
2223

2324
String prefix = PREFIX_NAMES[random.nextInt(PREFIX_NAMES.length)];
2425
String category = CLOTHING_CATEGORIES[random.nextInt(CLOTHING_CATEGORIES.length)];
26+
String nicknamePrefix = prefix + "_" + category + "_";
2527

26-
String uuidPart = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
28+
int suffixLength = MAX_NICKNAME_LENGTH - nicknamePrefix.length();
29+
if (suffixLength <= 0) {
30+
return nicknamePrefix.substring(0, MAX_NICKNAME_LENGTH);
31+
}
2732

28-
return prefix + "-" + category + "-" + uuidPart;
33+
return nicknamePrefix + generateSuffix(suffixLength);
34+
}
35+
36+
private String generateSuffix(int length) {
37+
StringBuilder suffix = new StringBuilder(length);
38+
39+
while (suffix.length() < length) {
40+
suffix.append(UUID.randomUUID().toString().replace("-", ""));
41+
}
42+
43+
return suffix.substring(0, length);
2944
}
3045
}

clokey-api/src/main/java/org/clokey/domain/coordinate/service/CoordinateServiceImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.clokey.domain.coordinate.service;
22

33
import java.time.LocalDate;
4+
import java.time.ZoneId;
45
import java.time.format.DateTimeFormatter;
56
import java.util.*;
67
import java.util.function.Function;
@@ -45,6 +46,8 @@
4546
@Transactional(readOnly = true)
4647
public class CoordinateServiceImpl implements CoordinateService {
4748

49+
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
50+
4851
private final MemberUtil memberUtil;
4952

5053
private final CoordinateRepository coordinateRepository;
@@ -89,7 +92,7 @@ public CoordinateCreateResponse createDailyCoordinate(DailyCoordinateCreateReque
8992
validateExceedingCoordinationClothesLimit(request.payloads());
9093
validateDuplicatedClothes(clothes);
9194
validateAllClothesOwnership(currentMember, clothes);
92-
validateDailyCoordinateExist(currentMember.getId(), LocalDate.now());
95+
validateDailyCoordinateExist(currentMember.getId(), LocalDate.now(KST));
9396

9497
Coordinate coordinate =
9598
Coordinate.createDailyCoordinate(request.coordinateImageUrl(), currentMember);
@@ -522,7 +525,7 @@ private Coordinate getCoordinateById(Long coordinateId) {
522525

523526
private Coordinate getTodayDailyCoordinate(Member member) {
524527
return coordinateRepository
525-
.findDailyCoordinateByDateAndMemberId(LocalDate.now(), member.getId())
528+
.findDailyCoordinateByDateAndMemberId(LocalDate.now(KST), member.getId())
526529
.orElseThrow(
527530
() ->
528531
new BaseCustomException(

clokey-api/src/main/java/org/clokey/domain/history/service/HistoryServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.clokey.domain.history.service;
22

33
import java.time.LocalDate;
4+
import java.time.ZoneId;
45
import java.util.*;
56
import java.util.function.Function;
67
import java.util.stream.Collectors;
@@ -48,6 +49,8 @@
4849
@Transactional(readOnly = true)
4950
public class HistoryServiceImpl implements HistoryService {
5051

52+
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
53+
5154
private final MemberUtil memberUtil;
5255

5356
private final HistoryRepository historyRepository;
@@ -90,7 +93,7 @@ public HistoryCreateResponse createHistory(HistoryCreateRequest request) {
9093
final String content =
9194
Optional.ofNullable(request.content()).map(String::trim).orElse(null);
9295
final History history =
93-
History.createHistory(LocalDate.now(), content, currentMember, situation);
96+
History.createHistory(LocalDate.now(KST), content, currentMember, situation);
9497
historyRepository.save(history);
9598

9699
List<HistoryImage> images = new ArrayList<>();

clokey-api/src/main/java/org/clokey/domain/member/batch/InactiveMemberDeletionBatch.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.clokey.domain.member.batch;
22

33
import java.time.LocalDateTime;
4+
import java.time.ZoneId;
45
import java.util.List;
56
import lombok.RequiredArgsConstructor;
67
import lombok.extern.slf4j.Slf4j;
@@ -17,13 +18,15 @@
1718
@Slf4j
1819
public class InactiveMemberDeletionBatch {
1920

21+
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
22+
2023
private final MemberRepository memberRepository;
2124
private final AuthService authService;
2225

23-
@Scheduled(cron = "0 0 0 * * *") // 매일 00:00:00
26+
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") // 매일 00:00:00 KST
2427
@Transactional
2528
public void deleteInactiveMembers() {
26-
LocalDateTime cutoffDate = LocalDateTime.now().minusDays(15);
29+
LocalDateTime cutoffDate = LocalDateTime.now(KST).minusDays(15);
2730
List<Member> inactiveMembers =
2831
memberRepository.findInactiveMembersBefore(MemberStatus.INACTIVE, cutoffDate);
2932

clokey-api/src/main/java/org/clokey/domain/member/dto/request/DuplicatedNicknameCheckRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public record DuplicatedNicknameCheckRequest(
99
@NotBlank(message = "닉네임은 비워둘 수 없습니다.")
1010
@Size(max = 20, message = "닉네임은 20자 이하여야 합니다.")
1111
@Pattern(
12-
regexp = "^[a-z가-힣._]+$",
13-
message = "닉네임은 영어 소문자, 한글, 언더바(_), 점(.)만 허용됩니다.")
12+
regexp = "^[a-z0-9가-힣._]+$",
13+
message = "닉네임은 영어 소문자, 숫자, 한글, 언더바(_), 점(.)만 허용됩니다.")
1414
@Schema(description = "중복을 확인할 닉네임", example = "clokey.홍길동")
1515
String nickname) {}

clokey-api/src/main/java/org/clokey/domain/member/dto/request/ProfileUpdateRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
import io.swagger.v3.oas.annotations.media.Schema;
44
import jakarta.validation.constraints.NotBlank;
55
import jakarta.validation.constraints.NotNull;
6+
import jakarta.validation.constraints.Pattern;
67
import jakarta.validation.constraints.Size;
78
import org.clokey.member.enums.Visibility;
89

910
public record ProfileUpdateRequest(
10-
@NotBlank(message = "닉네임은 비워둘 수 없습니다.") @Schema(description = "사용자의 닉네임", example = "juwon")
11+
@NotBlank(message = "닉네임은 비워둘 수 없습니다.")
12+
@Size(max = 20, message = "닉네임은 20자 이하여야 합니다.")
13+
@Pattern(
14+
regexp = "^[a-z0-9가-힣._]+$",
15+
message = "닉네임은 영어 소문자, 숫자, 한글, 언더바(_), 점(.)만 허용됩니다.")
16+
@Schema(description = "사용자의 닉네임", example = "juwon")
1117
String nickname,
1218
@Schema(description = "사용자의 한줄 소개", example = "한줄 소개")
1319
@Size(max = 100, message = "바이오는 100자를 넘길 수 없습니다.")

clokey-api/src/main/java/org/clokey/domain/notification/repository/CodiveNotificationRepositoryImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.querydsl.core.types.dsl.BooleanExpression;
77
import com.querydsl.jpa.impl.JPAQueryFactory;
88
import java.time.LocalDateTime;
9+
import java.time.ZoneId;
910
import java.util.List;
1011
import lombok.RequiredArgsConstructor;
1112
import org.clokey.domain.notification.dto.response.NotificationListResponse;
@@ -19,6 +20,8 @@
1920
@RequiredArgsConstructor
2021
public class CodiveNotificationRepositoryImpl implements CodiveNotificationRepositoryCustom {
2122

23+
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
24+
2225
private final JPAQueryFactory queryFactory;
2326

2427
@Override
@@ -56,7 +59,7 @@ public void updateAllReadStatusByMemberId(Long memberId) {
5659
queryFactory
5760
.update(codiveNotification)
5861
.set(codiveNotification.readStatus, ReadStatus.READ)
59-
.set(codiveNotification.updatedAt, LocalDateTime.now())
62+
.set(codiveNotification.updatedAt, LocalDateTime.now(KST))
6063
.where(
6164
codiveNotification.member.id.eq(memberId),
6265
codiveNotification.readStatus.eq(ReadStatus.NOT_READ))

0 commit comments

Comments
 (0)