Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 95 additions & 22 deletions src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aloc.aloc.global.init;

import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.enums.ColorType;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -29,41 +30,113 @@ private void initProfileBackgroundColor() {

List<ProfileBackgroundColor> colors =
List.of(
new ProfileBackgroundColor("Red", "#FF5A5A", null, null, null, null, "common", null),
new ProfileBackgroundColor("Yellow", "#FFB800", null, null, null, null, "common", null),
new ProfileBackgroundColor("Orange", "#FF9635", null, null, null, null, "common", null),
new ProfileBackgroundColor("Green", "#2ADC0D", null, null, null, null, "common", null),
new ProfileBackgroundColor(
"Emerald", "#00DC9A", null, null, null, null, "common", null),
"Red", "#FF5A5A", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"Skyblue", "#00C2FF", null, null, null, null, "common", null),
new ProfileBackgroundColor("Blue", "#408CFF", null, null, null, null, "common", null),
new ProfileBackgroundColor("Indigo", "#4440FF", null, null, null, null, "common", null),
new ProfileBackgroundColor("Purple", "#BA63FF", null, null, null, null, "common", null),
new ProfileBackgroundColor("Pink", "#FF5AB3", null, null, null, null, "common", null),
"Yellow", "#FFB800", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"PurpleRed", "#BA63FF", "#FF5A5A", null, null, null, "rare", 135),
"Orange", "#FF9635", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"BluePurple", "#408CFF", "#BA63FF", null, null, null, "rare", 135),
"Green", "#2ADC0D", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"IndigoPink", "#4440FF", "#FF5AB3", null, null, null, "rare", 135),
"Emerald", "#00DC9A", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"SkyblueIndigo", "#00C2FF", "#4440FF", null, null, null, "rare", 135),
"Skyblue", "#00C2FF", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"GreenSkyblue", "#2ADC0D", "#00C2FF", null, null, null, "rare", 135),
"Blue", "#408CFF", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"RedYellow", "#FF5A5A", "#FFB800", null, null, null, "rare", 135),
"Indigo", "#4440FF", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"BeautifulYPB", "#FFB800", "#FF69F0", "#408CFF", "", "", "special", 135),
"Purple", "#BA63FF", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"BeautifulBPR", "#408CFF", "#E95FFF", "#FF5A5A", "", "", "special", 135),
"Pink", "#FF5AB3", null, null, null, null, ColorType.COMMON.getValue(), null),
new ProfileBackgroundColor(
"GreenTea", "#CED690", "#49985D", null, null, null, "rare", 180),
"PurpleRed",
"#BA63FF",
"#FF5A5A",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"TequilaSunrise", "#F2F1AF", "#EF3529", null, null, null, "rare", 180),
new ProfileBackgroundColor("10AM", "#759CFF", "#B2E3FF", null, null, null, "rare", 180),
"BluePurple",
"#408CFF",
"#BA63FF",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"10PM", "#111579", "#0071C3", null, null, null, "rare", 180));
"IndigoPink",
"#4440FF",
"#FF5AB3",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"SkyblueIndigo",
"#00C2FF",
"#4440FF",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"GreenSkyblue",
"#2ADC0D",
"#00C2FF",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"RedYellow",
"#FF5A5A",
"#FFB800",
null,
null,
null,
ColorType.RARE.getValue(),
135),
new ProfileBackgroundColor(
"BeautifulYPB",
"#FFB800",
"#FF69F0",
"#408CFF",
"",
"",
ColorType.SPECIAL.getValue(),
135),
new ProfileBackgroundColor(
"BeautifulBPR",
"#408CFF",
"#E95FFF",
"#FF5A5A",
"",
"",
ColorType.SPECIAL.getValue(),
135),
new ProfileBackgroundColor(
"GreenTea", "#CED690", "#49985D", null, null, null, ColorType.RARE.getValue(), 180),
new ProfileBackgroundColor(
"TequilaSunrise",
"#F2F1AF",
"#EF3529",
null,
null,
null,
ColorType.RARE.getValue(),
180),
new ProfileBackgroundColor(
"10AM", "#759CFF", "#B2E3FF", null, null, null, ColorType.RARE.getValue(), 180),
new ProfileBackgroundColor(
"10PM", "#111579", "#0071C3", null, null, null, ColorType.RARE.getValue(), 180));

profileBackgroundColorRepository.saveAll(colors);
log.info("βœ… profile_background_color 초기 데이터 μ‚½μž… μ™„λ£Œ: {}개", colors.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.aloc.aloc.profilebackgroundcolor.enums;

/**
* ν”„λ‘œν•„ λ°°κ²½ 색상 νƒ€μž…μ„ μ •μ˜ν•˜λŠ” Enum - COMMON: 일반 색상 (85% ν™•λ₯ ) - RARE: 희귀 색상 (10% ν™•λ₯ , 86~95%) - SPECIAL: νŠΉλ³„ 색상
* (5% ν™•λ₯ , 96~100%)
*/
public enum ColorType {
COMMON("common"),
RARE("rare"),
SPECIAL("special");

private final String value;

ColorType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.aloc.aloc.profilebackgroundcolor.dto.response.ColorResponseDto;
import com.aloc.aloc.profilebackgroundcolor.entity.ProfileBackgroundColor;
import com.aloc.aloc.profilebackgroundcolor.enums.ColorType;
import com.aloc.aloc.profilebackgroundcolor.repository.ProfileBackgroundColorRepository;
import com.aloc.aloc.user.repository.UserRepository;
import java.util.List;
import java.util.Random;
import lombok.RequiredArgsConstructor;
Expand All @@ -17,38 +17,65 @@
@RequiredArgsConstructor
public class ProfileBackgroundColorService {
private final ProfileBackgroundColorRepository profileBackgroundColorRepository;
private final UserRepository userRepository;
private final Random randomNumberGenerator = new Random();

private static final int COLOR_CHANGE_MONEY = 100;
// 랜덀 컬러 선택 ν™•λ₯  경계 μ„€μ •
private static final int MAX_PROBABILITY = 100;
private static final int COMMON_THRESHOLD = 85;
private static final int RARE_THRESHOLD = 95;

// 1. getColorByName μ΄λ¦„μœΌλ‘œ 쑰회
// input : 컬러 이름
// output : 컬러 이름에 ν•΄λ‹Ήν•˜λŠ” 컬러
public ProfileBackgroundColor getColorByName(String name) {
public ProfileBackgroundColor getColorByName(String colorName) {
return profileBackgroundColorRepository
.findByName(name)
.orElseThrow(() -> new IllegalArgumentException("ν•΄λ‹Ή μ»¬λŸ¬κ°€ μ—†μŠ΅λ‹ˆλ‹€. " + name));
.findByName(colorName)
.orElseThrow(() -> new IllegalArgumentException("ν•΄λ‹Ή μ»¬λŸ¬κ°€ μ—†μŠ΅λ‹ˆλ‹€. " + colorName));
}

// 2. pickColor 랜덀 컬러 선택
// input : μ—†μŒ
// output : 랜덀 컬러 이름
public String pickColor() {
Random random = new Random();
int draw = random.nextInt(100) + 1;

List<ProfileBackgroundColor> profileBackgroundColorList;
if (draw <= 85) {
profileBackgroundColorList = profileBackgroundColorRepository.findByType("common");
} else if (draw <= 95) {
profileBackgroundColorList = profileBackgroundColorRepository.findByType("rare");
ColorType selectedType = determineColorTypeByProbability();
List<ProfileBackgroundColor> colorsOfSelectedType = getColorsByType(selectedType);
return selectRandomColor(colorsOfSelectedType);
}

// ν™•λ₯  기반으둜 ColorType κ²°μ •
// input : μ—†μŒ
// output : μ„ νƒλœ ColorType
private ColorType determineColorTypeByProbability() {
int randomNumber = randomNumberGenerator.nextInt(MAX_PROBABILITY) + 1;

if (randomNumber <= COMMON_THRESHOLD) {
return ColorType.COMMON;
} else if (randomNumber <= RARE_THRESHOLD) {
return ColorType.RARE;
} else {
profileBackgroundColorList = profileBackgroundColorRepository.findByType("special");
return ColorType.SPECIAL;
}
}

// νŠΉμ • νƒ€μž…μ˜ 색상 리슀트 쑰회
// input : ColorType
// output : ν•΄λ‹Ή νƒ€μž…μ˜ 색상 리슀트
private List<ProfileBackgroundColor> getColorsByType(ColorType colorType) {
List<ProfileBackgroundColor> colors =
profileBackgroundColorRepository.findByType(colorType.getValue());

if (colors.isEmpty()) {
throw new IllegalStateException("μ„ νƒλœ νƒ€μž…μ— ν•΄λ‹Ήν•˜λŠ” 색상이 μ—†μŠ΅λ‹ˆλ‹€: " + colorType.getValue());
}

return profileBackgroundColorList
.get(random.nextInt(profileBackgroundColorList.size()))
.getName();
return colors;
}

// 색상 λ¦¬μŠ€νŠΈμ—μ„œ λžœλ€ν•˜κ²Œ ν•˜λ‚˜ 선택
// input : 색상 리슀트
// output : μ„ νƒλœ 색상 이름
private String selectRandomColor(List<ProfileBackgroundColor> colors) {
return colors.get(randomNumberGenerator.nextInt(colors.size())).getName();
}

// 3. getAllColors λͺ¨λ“  컬러 쑰회
Expand Down