Skip to content

Commit

Permalink
refactor(MovieRating): 별점 text 및 number 계산해주는 함수 constants > rating 파…
Browse files Browse the repository at this point in the history
…일로 분리
  • Loading branch information
Hain-tain committed Apr 1, 2024
1 parent c42e660 commit c9380ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getRatingNumber, getRatingText } from "../../../../constants/rating";

import createElement from "../../../utils/createElement";
import generateStarRangeInput from "../../../common/generateStarRangeInput";

Expand Down Expand Up @@ -76,28 +78,11 @@ class MovieRating {
}

private ratingNumber(rating: number) {
return String(rating * 2);
return String(getRatingNumber(rating));
}

private ratingText(rating: number) {
switch (rating) {
case 1:
return "최악이예요";
case 2:
return "별로예요";

case 3:
return "보통이에요";

case 4:
return "재미있어요";

case 5:
return "명작이에요";

default:
return "별점을 매겨보세요";
}
return getRatingText(rating);
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/constants/rating.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
export const DEFAULT_RATING = 0;
export const MAX_RATING = 5;

export const getRatingNumber = (rating: number) => {
return rating * 2;
};

export const getRatingText = (rating: number) => {
switch (rating) {
case 1:
return "최악이예요";
case 2:
return "별로예요";

case 3:
return "보통이에요";

case 4:
return "재미있어요";

case 5:
return "명작이에요";

default:
return "별점을 매겨보세요";
}
};

0 comments on commit c9380ee

Please sign in to comment.