-
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.
chore: 추천 템플릿이 중복인 경우, 그 중에서 랜덤으로 하나 선택하도록 수정 (#220)
- Loading branch information
Showing
5 changed files
with
65 additions
and
6 deletions.
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
7 changes: 7 additions & 0 deletions
7
layer-domain/src/main/java/org/layer/domain/common/random/CustomRandom.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,7 @@ | ||
package org.layer.domain.common.random; | ||
|
||
public interface CustomRandom { | ||
String generateRandomValue(); | ||
|
||
int nextInt(int index); | ||
} |
19 changes: 19 additions & 0 deletions
19
layer-domain/src/main/java/org/layer/domain/common/random/MockRandom.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,19 @@ | ||
package org.layer.domain.common.random; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Profile("test") | ||
public class MockRandom implements CustomRandom { | ||
|
||
@Override | ||
public String generateRandomValue() { | ||
return "test-random-value"; | ||
} | ||
|
||
@Override | ||
public int nextInt(int index) { | ||
return 1; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
layer-domain/src/main/java/org/layer/domain/common/random/RealRandom.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,22 @@ | ||
package org.layer.domain.common.random; | ||
|
||
import java.util.Random; | ||
import java.util.UUID; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Profile({"local", "dev", "prod"}) | ||
public class RealRandom implements CustomRandom { | ||
@Override | ||
public String generateRandomValue() { | ||
return UUID.randomUUID().toString().substring(0, 13); | ||
} | ||
|
||
@Override | ||
public int nextInt(int index) { | ||
Random random = new Random(); | ||
return random.nextInt(index); | ||
} | ||
} |
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