-
Notifications
You must be signed in to change notification settings - Fork 0
237 refactor profile background color refactor #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
237 refactor profile background color refactor #229
Conversation
Walkthroughνλ‘ν λ°°κ²½μ μ΄κΈ° λ°μ΄ν° ꡬμ±μμ λ¬Έμμ΄ νμ μ enum κΈ°λ°μΌλ‘ λ³κ²½νκ³ , ColorType enumμ μ μ€νλ€. μλΉμ€ λ μ΄μ΄λ νλ₯ κΈ°λ° νμ κ²°μ β νμ λ³ μμ μ‘°ν β 무μμ μ νμ λ¨κ³μ νλ¦μΌλ‘ 리ν©ν°λ§λμκ³ , μ΄λ¦ κ²μ λ©μλ νλΌλ―Έν° λͺ μ΄ μ λλμλ€. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Service as ProfileBackgroundColorService
participant Repo as ProfileBackgroundColorRepository
Client->>Service: pickColor()
Service->>Service: determineColorTypeByProbability()
Service->>Repo: findByType(colorType.getValue())
Repo-->>Service: List<ProfileBackgroundColor>
Service->>Service: selectRandomColor(list)
Service-->>Client: ProfileBackgroundColor
sequenceDiagram
participant Client
participant Service as ProfileBackgroundColorService
participant Repo as ProfileBackgroundColorRepository
Client->>Service: getColorByName(colorName)
Service->>Repo: findByName(colorName)
Repo-->>Service: Optional<ProfileBackgroundColor>
Service-->>Client: ProfileBackgroundColor or Exception
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~25 minutes Possibly related PRs
Tip π Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. β¨ Finishing Touches
π§ͺ Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (10)
src/main/java/com/aloc/aloc/profilebackgroundcolor/enums/ColorType.java (2)
3-6
: μ£Όμ(νλ₯ )κ³Ό ꡬν(μλΉμ€μ μκ³κ°) κ° λ리ννΈ λ°©μ§ μ μμ£Όμμ 85/10/5 νλ₯ μ΄ λͺ μλμ΄ μκ³ , μλΉμ€ ν΄λμ€μλ COMMON_THRESHOLD/RARE_THRESHOLDκ° λ³λλ‘ μ‘΄μ¬ν©λλ€. μκ°μ΄ μ§λλ©΄ λ¬Έμ-μ½λκ° μ΄κΈλ κ°λ₯μ±μ΄ μμ΄, κ°μ€μΉλ₯Ό Enum λ΄λΆλ‘ λμ΄μ¬λ¦¬λ λ°©μμ κ³ λ €ν΄λ³΄μΈμ.
μμ(diffλ μ°Έμ‘°μ©, μ€μ λ°μμ μ ν):
public enum ColorType { - COMMON("common"), - RARE("rare"), - SPECIAL("special"); + COMMON("common", 85), + RARE("rare", 10), + SPECIAL("special", 5); - private final String value; + private final String value; + private final int weightPercent; - ColorType(String value) { - this.value = value; - } + ColorType(String value, int weightPercent) { + this.value = value; + this.weightPercent = weightPercent; + } public String getValue() { return value; } + + public int getWeightPercent() { + return weightPercent; + } }μ΄λ κ² λλ©΄, μλΉμ€μμλ λμ κ°μ€μΉ κΈ°λ°μΌλ‘ νμ μ μΆμΆν μ μμ΄ μ£Όμ/μ½λ λ리ννΈλ₯Ό μλ°©ν μ μμ΅λλ€.
12-20
: toString μ€λ²λΌμ΄λ λλ fromValue μ 곡 κ³ λ €νμ¬λ getValue()λ‘ λ¬Έμμ΄μ λ ΈμΆν©λλ€. νΈμΆλΆμμ value λ¬Έμμ΄μ΄ νμν λλ§λ€ getValue() νΈμΆμ΄ λ°λ³΅λ©λλ€. toString() μ€λ²λΌμ΄λ(νΉμ fromValue(String) μλ§€ν) μΆκ°λ₯Ό κ³ λ €νλ©΄ κ°λ μ±κ³Ό μ¬μ©μ± λͺ¨λ μ’μμ§λλ€.
μμ:
public String getValue() { return value; } + + @Override + public String toString() { + return value; + } + + public static ColorType fromValue(String value) { + for (ColorType ct : values()) { + if (ct.value.equals(value)) return ct; + } + throw new IllegalArgumentException("Unknown ColorType value: " + value); + }src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java (4)
108-116
: λΉ λ¬Έμμ΄("") λμ null μ¬μ© κΆμ₯ (λ°μ΄ν° μΌκ΄μ±)SPECIAL μμμμ color4, color5μ λΉ λ¬Έμμ΄μ΄ λ€μ΄κ°λλ€. μν°ν° νλλ null νμ©μ΄κ³ , λ€λ₯Έ νλͺ©μ nullμ μ¬μ©νκ³ μμ΄ μΌκ΄μ±μ΄ λ¨μ΄μ§λλ€. API μλ΅μμλ ""μ null ꡬλΆμ΄ μ겨 ν΄λΌμ΄μΈνΈ μ²λ¦¬ 볡μ‘λκ° μ¦κ°ν©λλ€. nullλ‘ ν΅μΌμ κΆμ₯ν©λλ€.
μ μ diff:
new ProfileBackgroundColor( "BeautifulYPB", "#FFB800", "#FF69F0", "#408CFF", - "", - "", + null, + null, ColorType.SPECIAL.getValue(), 135),
117-124
: μμ λμΌ: λΉ λ¬Έμμ΄("") β null ν΅μΌ κΆμ₯λ°μ΄ν° μΌκ΄μ±μ μν΄ color4, color5λ₯Ό nullλ‘ μ 리ν΄μ£ΌμΈμ.
μ μ diff:
new ProfileBackgroundColor( "BeautifulBPR", "#408CFF", "#E95FFF", "#FF5A5A", - "", - "", + null, + null, ColorType.SPECIAL.getValue(), 135),
31-141
: κ°λ μ±: λ€μΈμ μμ±μ λμ Builder μ¬μ© κ³ λ €8κ° νλΌλ―Έν° μμ μμ‘΄μ΄ κ°νκ³ μ€μ μ¬μ§κ° ν½λλ€. μν°ν°μ @builderκ° μ΄λ―Έ μ μ©λμ΄ μμΌλ―λ‘ μ΄κΈ° λ°μ΄ν° μμ±λ Builderλ‘ μ ννλ©΄ κ°λ μ±κ³Ό μμ μ±μ΄ μ¬λΌκ°λλ€.
μμ:
ProfileBackgroundColor.builder() .name("Red") .color1("#FF5A5A") .type(ColorType.COMMON.getValue()) .build();
25-30
: μ΄κΈ° λ°μ΄ν° λ³΄κ° μ λ΅ μ¬κ³ (μ ν μ¬ν)count()>0μ΄λ©΄ μ 체 μμ±μ 건λλλλ€. κΈ°μ‘΄ dev DBμ μΌλΆλ§ μ‘΄μ¬νλ κ²½μ° μ κ· μμμ΄ μΆκ°λμ§ μμ μ μμ΅λλ€. μ΄λ¦(@id) κΈ°μ€μΌλ‘ μ‘΄μ¬νμ§ μλ νλͺ©λ§ upsertνλ λ‘μ§μΌλ‘ λ°κΎΈλ©΄ κ°λ° νΈμμ±μ΄ μ’μμ§λλ€.
src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (4)
64-72
: λΉ λ¦¬μ€νΈ μμΈ μ²λ¦¬ OK, λ©μμ§ κ΅¬μ²΄νλ μ ν μ¬ννμ λ³ μ»¬λ¬κ° λΉμ΄μμ λ IllegalStateExceptionμΌλ‘ λΉ λ₯΄κ² μ€ν¨νλ μ λ΅ μ’μ΅λλ€. μΆκ°λ‘, μ΄μ κ΄μ μμ μμΈ νμ μ λλλ‘ νμ κ³Ό νμ¬ DB μ΄λ(νΉμ νμ λ³ κ±΄μ)μ ν¬ν¨ν΄λ μ’μ΅λλ€.
μμ:
- throw new IllegalStateException("μ νλ νμ μ ν΄λΉνλ μμμ΄ μμ΅λλ€: " + colorType.getValue()); + throw new IllegalStateException( + "μ νλ νμ μ ν΄λΉνλ μμμ΄ μμ΅λλ€: " + colorType.getValue() + + " (colors.size=" + colors.size() + ")" + );Also applies to: 77-79
20-20
: Random μ¬μ© λ°©μ κ°μ μ μ: ThreadLocalRandom λλ μ£Όμ ν Randomνμ¬ νλμ new Random()μ κ³ μ μμ±ν©λλ€. λ©ν°μ€λ λ/μ±λ₯μ κ³ λ €νλ©΄ ThreadLocalRandom μ¬μ©μ΄ λ κ²½λμ΄λ©°, ν μ€νΈ μ©μ΄μ±μ κ³ λ €νλ©΄ Randomμ μ£Όμ λ°μ μλ κ³ μ μ΄ κ°λ₯ν©λλ€. μν©μ λ§κ² λ κ°μ§ μ€ νλλ₯Ό κΆμ₯ν©λλ€.
μ΅μ A: ThreadLocalRandom μ¬μ©(κ°λ¨, κ³ μ±λ₯)
-import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; ... - private final Random randomNumberGenerator = new Random(); + // ThreadLocalRandom μ¬μ©μΌλ‘ λ½ κ²½ν© μκ³ μ±λ₯ μ°μ ... - int randomNumber = randomNumberGenerator.nextInt(MAX_PROBABILITY) + 1; + int randomNumber = ThreadLocalRandom.current().nextInt(MAX_PROBABILITY) + 1; ... - return colors.get(randomNumberGenerator.nextInt(colors.size())).getName(); + return colors.get(ThreadLocalRandom.current().nextInt(colors.size())).getName();μ΅μ B: Random μ£Όμ (ν μ€νΈμμ μλ κ³ μ κ°λ₯)
- νλμμ μ΄κΈ°ν μ κ±° ν μμ±μ μ£Όμ μΌλ‘ κ΅μ²΄(ν μ€νΈ μ
new Random(0)
μ£Όμ ).- λ³λ @configurationμμ Random λΉ μ μ.
Also applies to: 48-58, 77-79
22-26
: νλ₯ μμ λ€μ΄λ°κ³Ό λ¬Έμν μ¬μν κ°μ μ μMAX_PROBABILITY=100, COMMON_THRESHOLD=85, RARE_THRESHOLD=95λ λͺ νν©λλ€. μ£Όμμ β1
85=COMMON, 8695=RARE, 96~100=SPECIALβ ν μ€ μμλ₯Ό λ¨κ²¨λλ©΄ μ μ§λ³΄μμκ° λΉ λ₯΄κ² μ΄ν΄ν μ μμ΅λλ€.
39-43
: μΊμ± κ³ λ €(μ ν): νμ λ³ μ»¬λ¬ λͺ©λ‘μ λ³λ μ μνμ λ³ μ»¬λ¬ λͺ©λ‘μ μμ£Ό λ°λμ§ μλ μ μ λ°μ΄ν°μ κ°κΉμ΅λλ€. pickColor() νΈμΆ λΉλκ° λλ€λ©΄,
getColorsByType
μ @Cacheable(type) μΊμλ₯Ό λκ±°λ, μ ν리μΌμ΄μ κΈ°λ μ λ©λͺ¨λ¦¬ λ‘λνμ¬ μ°Έμ‘°νλ λ°©μμΌλ‘ DB μ볡μ μ€μΌ μ μμ΅λλ€.Also applies to: 64-72
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π‘ Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
π Files selected for processing (3)
src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java
(2 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/enums/ColorType.java
(1 hunks)src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java
(2 hunks)
π§° Additional context used
𧬠Code Graph Analysis (3)
src/main/java/com/aloc/aloc/profilebackgroundcolor/enums/ColorType.java (3)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
Entity
(15-36)src/main/java/com/aloc/aloc/user/dto/response/UserColorChangeResponseDto.java (1)
Data
(10-28)src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java (2)
Getter
(8-47)of
(35-46)
src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (5)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
Entity
(15-36)src/test/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorServiceTest.java (2)
ExtendWith
(22-70)Test
(30-52)src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java (1)
Repository
(14-20)src/main/java/com/aloc/aloc/user/dto/response/UserColorChangeResponseDto.java (1)
Data
(10-28)src/test/java/com/aloc/aloc/user/service/UserServiceTest.java (2)
Nested
(64-130)Test
(68-91)
src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java (3)
src/main/java/com/aloc/aloc/profilebackgroundcolor/entity/ProfileBackgroundColor.java (1)
Entity
(15-36)src/main/java/com/aloc/aloc/profilebackgroundcolor/repository/ProfileBackgroundColorRepository.java (1)
Repository
(14-20)src/main/java/com/aloc/aloc/profilebackgroundcolor/dto/response/ColorResponseDto.java (1)
Getter
(8-47)
π Additional comments (6)
src/main/java/com/aloc/aloc/profilebackgroundcolor/enums/ColorType.java (1)
7-20
: Enum λμ κ³Ό λλ©μΈ λΆλ¦¬, κΉλν©λλ€λ¬Έμμ΄ μμ λμ EnumμΌλ‘ λΆλ¦¬ν΄ μ μμμ μ¬μ¬μ©νλ λ°©ν₯ μ’μ΅λλ€. μλΉμ€/μ΄κΈ° λ°μ΄ν° λͺ¨λμμ μΌκ΄λκ² μ¬μ©ν μ μμ΄ μ μ§λ³΄μμ± ν₯μμ ν¬κ² κΈ°μ¬ν©λλ€.
src/main/java/com/aloc/aloc/global/init/DevDataInitializer.java (2)
34-52
: Enum κ° μ¬μ©μΌλ‘ μμ λ¬Έμμ΄ μ κ±°: μ μ§λ³΄μμ± ν₯μνλμ½λ©λ "common/rare/special" μ κ±°νκ³ ColorType.getValue()λ‘ μΉνν μ μ’μ΅λλ€. μ μ₯μκ° String νμ μ λ°λ μ μ½μ κ³ λ €ν μ€μ©μ μ κ·Όμ λλ€.
Also applies to: 54-61, 63-71, 72-80, 81-89, 90-98, 99-107, 126-139
31-141
: λ°μ΄ν° νμ§ μ κ² κ²°κ³Ό: μ΄μ μμ
- μ€λ³΅ name(@id) μμ
- color4/color5 νλμ λΉ λ¬Έμμ΄ μμ
- νμ λΆν¬(COMMON: 10, RARE: 10, SPECIAL: 2)κ° μ½λ μλμ μΌμΉ
src/main/java/com/aloc/aloc/profilebackgroundcolor/service/ProfileBackgroundColorService.java (3)
39-43
: λ¨κ³ λΆλ¦¬λ‘ κ°λ μ±κ³Ό ν μ€νΈ μ©μ΄μ±μ΄ ν₯μλμμ΅λλ€pickColor()λ₯Ό μΈ λ¨κ³λ‘ λΆλ¦¬ν ꡬ쑰(νμ κ²°μ β νμ λ³ μ‘°ν β 무μμ μ ν)κ° λͺ ννκ³ μ μ§λ³΄μμ μ 리ν©λλ€. κ²½κ³κ°(85/95) μ²λ¦¬λ off-by-one μμ΄ μ νν©λλ€.
Also applies to: 45-58
85-85
: toList μ¬μ© μ μ Stream λ§λ¬΄λ¦¬μ toList() μ¬μ©μΌλ‘ λΆλ³ 리μ€νΈ λ°νλλ μ μ’μ΅λλ€. DTO λ³νλ κ°κ²°ν©λλ€.
30-34
: μμΈ νμ /λ©μμ§ μ μ μ‘΄μ¬νμ§ μλ μ΄λ¦ μ‘°ν μ IllegalArgumentException μ¬μ©κ³Ό ꡬ체 λ©μμ§ λͺ¨λ μ μ ν©λλ€. ν μ€νΈλ μ΄μ λ§μΆ° μ ꡬμ±λμ΄ μμ΅λλ€.
π PR μ λͺ©
π§ 리ν©ν λ§ λ΄μ©
ColorType enum λΆλ¦¬: μ μμμ μ¬μ© κ°λ₯νλλ‘ λ³λ νμΌλ‘ λΆλ¦¬
λ©μλ λΆλ¦¬: pickColor() λ©μλλ₯Ό λ¨μΌ μ± μ μμΉμ λ°λΌ 3κ° λ©μλλ‘ λΆλ¦¬
determineColorTypeByProbability(): νλ₯ κΈ°λ° νμ κ²°μ
getColorsByType(): νμ λ³ μμ μ‘°ν + μμΈ μ²λ¦¬
selectRandomColor(): λλ€ μμ μ ν
μμν: λ§€μ§ λλ²λ₯Ό μλ―Έμλ μμλ‘ λ³κ²½ (COMMON_THRESHOLD, RARE_THRESHOLD)
λ³μλͺ κ°μ : λ λͺ νν λ³μλͺ μ¬μ© (randomNumberGenerator, randomNumber)
μμΈ μ²λ¦¬ κ°ν: λΉ μμ 리μ€νΈμ λν μμΈ μ²λ¦¬ μΆκ°
μ±λ₯ μ΅μ ν: Random μΈμ€ν΄μ€λ₯Ό ν΄λμ€ λ 벨μμ μ¬μ¬μ©
ποΈ κ΅¬μ‘° κ°μ
Before: 20μ€μ 볡μ‘ν pickColor() λ©μλ
After: 3μ€μ κ°κ²°ν pickColor() λ©μλ + λΆλ¦¬λ private λ©μλλ€
π 체ν¬λ¦¬μ€νΈ
πΈ μ€ν¬λ¦°μ· (UI λ³κ²½μ΄ μλ€λ©΄)
π κ΄λ ¨ μ΄μ
Summary by CodeRabbit