TIL

[TIL] 2024/08/30

dev_ajrqkq 2024. 9. 2. 12:36

1. jpa에서 setter를 지양하는 이유 - ??추가할 예정

 

2.특정 날짜의 요일 구하기

LocalDateTime date = LocalDateTime.now();
DayOfWeek dayOfWeek = date.getDayOfWeek();
if(store.getClosedDays().equals(dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREAN))){
    throw new ApplicationException(CLOSED_DAY_STORE);
}

 

3. git 강제 pull

git fetch --all
git reset --hard origin/master
git pull origin master

 

4. jpa pageable 사이즈 제한

 private static final int[] ALLOWED_PAGE_SIZES = {10, 30, 50};
 private static final int DEFAULT_PAGE_SIZE = 10;
 
 ...
 
@GetMapping
@Operation(summary = "주문 전체 조회", description = "주문에 대한 전체 리스트 조회")
public Response<Page<OrderFindResponse>> findOrders(OrderSearchRequest searchDto,
                                                    Pageable pageable,
                                                    @AuthenticationPrincipal UserDetailsImpl userDetails) {
    int size = DEFAULT_PAGE_SIZE; // 기본 10건
    if(Arrays.stream(ALLOWED_PAGE_SIZES).anyMatch(s->s == pageable.getPageSize())){ //요청 사이즈가 10, 30, 50일 때
        size = pageable.getPageSize();
    }

    Pageable validatedPageable = PageRequest.of(pageable.getPageNumber(), size, pageable.getSort());

    return Response.success(orderService.findAllOrders(searchDto, validatedPageable, userDetails.getUser()));
}

 

5. UUID랑 Integer는 @NOTNULL 사용하기

https://wildeveloperetrain.tistory.com/68

 

@NotNull @NotEmpty @NotBlank 차이점 한번은 알고 가자

@NotNull @NotEmpty @NotBlank javax.validation.constraints package에 포함된 기능으로 api에서 값을 입력받을 때 validation 체크를 위해 사용되는 어노테이션입니다. 많이 사용하게 되는 어노테이션으로 한 번만 차

wildeveloperetrain.tistory.com

 

6. 현재 시간은 운영시간에 포함되는지?? 정답은 아닌 거 같음...;;;

public static boolean checkTime(LocalTime startTime , LocalTime endTime, LocalDateTime now){
    LocalDateTime startDateTime = now.with(startTime);
    LocalDateTime endDateTime = now.with(endTime);

    if (endTime.isBefore(startTime)) {
        // 자정을 넘는 시간 범위 처리 (예: 22:00 ~ 03:30)
        if (now.toLocalTime().isBefore(endTime)) {
            startDateTime = startDateTime.minusDays(1);
        }
    }

    log.info("now.isAfter(startDateTime) {}", now.isAfter(startDateTime));
    log.info("now.isBefore(endDateTime) {}", now.isBefore(endDateTime));
    return now.isAfter(startDateTime) && now.isBefore(endDateTime);

}