-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: add experience three times check
- Loading branch information
Showing
5 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -73,6 +73,9 @@ endif::[] | |
|7000 | ||
|질문은 3초에 1번만 작성이 가능합니다. | ||
|
||
|7001 | ||
|경험은 3초에 1번만 작성이 가능합니다. | ||
|
||
|=== | ||
|
||
== 현재 오류 사항 | ||
|
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/sirius/spurt/common/validator/ExperienceValidator.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,30 @@ | ||
package com.sirius.spurt.common.validator; | ||
|
||
import static com.sirius.spurt.common.meta.ResultCode.EXPERIENCE_THREE_SECONDS; | ||
|
||
import com.sirius.spurt.common.exception.GlobalException; | ||
import com.sirius.spurt.store.repository.database.entity.ExperienceEntity; | ||
import java.sql.Timestamp; | ||
|
||
public class ExperienceValidator { | ||
private static long EXPERIENCE_DUPLICATE_TIME = 3000L; | ||
|
||
public static void validateTimestamp(ExperienceEntity experienceEntity) { | ||
if (!isExistExperience(experienceEntity)) { | ||
return; | ||
} | ||
|
||
if (isWithin3SecondsDifference(experienceEntity.getCreateTimestamp())) { | ||
throw new GlobalException(EXPERIENCE_THREE_SECONDS); | ||
} | ||
} | ||
|
||
private static boolean isExistExperience(ExperienceEntity experienceEntity) { | ||
return experienceEntity != null; | ||
} | ||
|
||
private static boolean isWithin3SecondsDifference(Timestamp timestamp) { | ||
return new Timestamp(System.currentTimeMillis()).getTime() - timestamp.getTime() | ||
< EXPERIENCE_DUPLICATE_TIME; | ||
} | ||
} |
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
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