-
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.
Merge pull request #47 from taco-official/KL-131/상품에-평점-필드-추가
feat(KL-131): add rating field to product
- Loading branch information
Showing
20 changed files
with
284 additions
and
21 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/taco/klkl/domain/product/converter/RatingConverter.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,27 @@ | ||
package taco.klkl.domain.product.converter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
import taco.klkl.domain.product.domain.Rating; | ||
|
||
@Converter(autoApply = true) | ||
public class RatingConverter implements AttributeConverter<Rating, BigDecimal> { | ||
|
||
@Override | ||
public BigDecimal convertToDatabaseColumn(final Rating attribute) { | ||
if (attribute == null) { | ||
return null; | ||
} | ||
return BigDecimal.valueOf(attribute.getValue()); | ||
} | ||
|
||
@Override | ||
public Rating convertToEntityAttribute(final BigDecimal dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
return Rating.from(dbData.doubleValue()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package taco.klkl.domain.product.domain; | ||
|
||
import java.util.Arrays; | ||
|
||
import lombok.Getter; | ||
import taco.klkl.domain.product.exception.RatingNotFoundException; | ||
|
||
@Getter | ||
public enum Rating { | ||
ZERO_FIVE(0.5), | ||
ONE(1.0), | ||
ONE_FIVE(1.5), | ||
TWO(2.0), | ||
TWO_FIVE(2.5), | ||
THREE(3.0), | ||
THREE_FIVE(3.5), | ||
FOUR(4.0), | ||
FOUR_FIVE(4.5), | ||
FIVE(5.0), | ||
; | ||
|
||
private final double value; | ||
|
||
Rating(double value) { | ||
this.value = value; | ||
} | ||
|
||
public static Rating from(final double value) { | ||
return Arrays.stream(Rating.values()) | ||
.filter(r -> r.value == value) | ||
.findFirst() | ||
.orElseThrow(RatingNotFoundException::new); | ||
} | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/taco/klkl/domain/product/exception/RatingNotFoundException.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,10 @@ | ||
package taco.klkl.domain.product.exception; | ||
|
||
import taco.klkl.global.error.exception.CustomException; | ||
import taco.klkl.global.error.exception.ErrorCode; | ||
|
||
public class RatingNotFoundException extends CustomException { | ||
public RatingNotFoundException() { | ||
super(ErrorCode.RATING_NOT_FOUND); | ||
} | ||
} |
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
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
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
Oops, something went wrong.