Skip to content

Commit

Permalink
Merge pull request #38 from Team-Petudio/feat/#32
Browse files Browse the repository at this point in the history
[FEAT] 컨셉 가격 및 할인 로직 구현
  • Loading branch information
PgmJun authored Jan 30, 2024
2 parents aadcd0e + c2e5d3c commit 2e4fd9c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import lombok.Builder;

@Builder(access = AccessLevel.PRIVATE)
public record ConceptRetrieveResponse(Long conceptId, String mainImageUri, String name, String descriptionMessage,
public record ConceptRetrieveResponse(Long conceptId, String mainImageUri, String name, int conceptPrice, int discountedPrice, String descriptionMessage,
PetType petType, Boolean isNew) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static ConceptsRetrieveResponse convertEntitiesToDto(List<Concept> concep
conceptMessagePrefix + ConceptMessageType.DESCRIPTION.getType());

conceptsResponse.add(new ConceptRetrieveResponse(concept.getId(), concept.getMainImageUri(), name,
concept.getPrice(), concept.getDiscountedPrice(now),
descriptionMessage, concept.getInfo().getPetType(), concept.validateIsNew(now)));
}
return new ConceptsRetrieveResponse(conceptsResponse);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/nice/petudio/domain/concept/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class Concept extends BaseEntity {
@Column(name = "concept_info", length = 30, nullable = false)
private ConceptInfo info;

@Column(name = "concept_price", nullable = false)
private int price;

@Column(name = "concept_main_image_uri", length = 200, nullable = false)
private String mainImageUri;

Expand Down Expand Up @@ -63,4 +66,12 @@ public boolean validateIsNew(LocalDateTime now) {
// 컨셉이 생긴지 90일이 지나지 않았으면 'New 컨셉'에 해당
return getCreatedAt().isAfter(now.minusDays(90));
}

public int getDiscountedPrice(LocalDateTime now) {
if(validateIsNew(now)) {
// isNew가 true이면 30% 할인
return price - ((price / 10) * 3);
}
return price;
}
}
6 changes: 3 additions & 3 deletions src/main/resources/sql/data.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO concepts
VALUES (1, 'DOG_3D', 'mainImage', 'image', 'image', 'image', 'image', 'image', 'image', 'image', 'image',
VALUES (1, 'DOG_3D', 500, 'mainImage', 'image', 'image', 'image', 'image', 'image', 'image', 'image', 'image',
'2024-01-24 23:48:52', '2024-01-24 23:48:52');
INSERT INTO concepts
VALUES (2, 'DOG_TRENDY', 'mainImage', 'image', 'image', 'image', 'image', 'image', 'image', 'image', 'image',
'2024-01-24 23:48:52', '2024-01-24 23:48:52');
VALUES (2, 'DOG_TRENDY', 600, 'mainImage', 'image', 'image', 'image', 'image', 'image', 'image', 'image', 'image',
'2024-01-24 23:48:52', '2024-01-24 23:48:52');
15 changes: 7 additions & 8 deletions src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CREATE TABLE `concepts`
(
`concept_id` bigint AUTO_INCREMENT PRIMARY KEY,
`concept_info` varchar(30) NOT NULL,
`concept_price` int NOT NULL,
`concept_main_image_uri` varchar(200) NOT NULL,
`concept_success_image1_uri` varchar(200) NOT NULL,
`concept_success_image2_uri` varchar(200) NOT NULL,
Expand All @@ -56,14 +57,12 @@ CREATE TABLE `concepts`

CREATE TABLE `pets`
(
`pet_id` bigint AUTO_INCREMENT PRIMARY KEY,
`member_id` bigint NOT NULL,
`pet_name` varchar(30) NOT NULL,
`pet_fur_color` varchar(30) NOT NULL,
`pet_image_s3_directory_path` varchar(100) NOT NULL,
`pet_photos` json NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
`pet_id` bigint AUTO_INCREMENT PRIMARY KEY,
`member_id` bigint NOT NULL,
`pet_name` varchar(30) NOT NULL,
`pet_photos` json NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE `albums`
Expand Down

0 comments on commit 2e4fd9c

Please sign in to comment.