-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 엑셀 다운로드 중복 방지 redis 적용 * feat: 엑셀 다운로드 중복 방지 로직 추가 * style: 라인 포맷팅 * fix: 리뷰 반영 * fix: 개행 추가 * fix: ExcelDownloadCache.from 매개변수 변경
- Loading branch information
1 parent
23c5f96
commit f9b0f38
Showing
4 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/in/koreatech/koin/domain/coop/exception/DuplicateExcelRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package in.koreatech.koin.domain.coop.exception; | ||
|
||
import java.time.LocalDate; | ||
|
||
import in.koreatech.koin.global.exception.DuplicationException; | ||
|
||
public class DuplicateExcelRequestException extends DuplicationException { | ||
|
||
private static final String DEFAULT_MESSAGE = "동일한 요청을 30초 안에 다시 보낼 수 없습니다!"; | ||
|
||
public DuplicateExcelRequestException(String message) { | ||
super(message); | ||
} | ||
|
||
public DuplicateExcelRequestException(String message, String detail) { | ||
super(message, detail); | ||
} | ||
|
||
public static DuplicateExcelRequestException withDetail(LocalDate startDate, LocalDate endDate) { | ||
return new DuplicateExcelRequestException(DEFAULT_MESSAGE, | ||
"startDate: '" + startDate + "'" + "endDate: " + endDate); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/in/koreatech/koin/domain/coop/model/ExcelDownloadCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package in.koreatech.koin.domain.coop.model; | ||
|
||
import java.time.LocalDate; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@RedisHash(value = "excelDownload") | ||
public class ExcelDownloadCache { | ||
|
||
private static final long CACHE_EXPIRE_SECONDS = 30L; | ||
|
||
@Id | ||
private String id; | ||
|
||
@TimeToLive(unit = TimeUnit.SECONDS) | ||
private final Long expiration; | ||
|
||
@Builder | ||
private ExcelDownloadCache(String id, Long expiration) { | ||
this.id = id; | ||
this.expiration = expiration; | ||
} | ||
|
||
public static ExcelDownloadCache from(LocalDate startDate, LocalDate endDate) { | ||
return ExcelDownloadCache.builder() | ||
.id(startDate.toString() + endDate.toString()) | ||
.expiration(CACHE_EXPIRE_SECONDS) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/in/koreatech/koin/domain/coop/repository/ExcelDownloadCacheRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package in.koreatech.koin.domain.coop.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import in.koreatech.koin.domain.coop.model.ExcelDownloadCache; | ||
|
||
public interface ExcelDownloadCacheRepository extends Repository<ExcelDownloadCache, String> { | ||
|
||
ExcelDownloadCache save(ExcelDownloadCache excelDownloadCache); | ||
|
||
Optional<ExcelDownloadCache> findById(String id); | ||
|
||
boolean existsById(String id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters