Skip to content
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

Lf1 179 register product #9

Merged
merged 5 commits into from
Nov 22, 2023
Merged
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
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33'
implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '0.1.0-alpha2'
// https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb
implementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.12.592'
runtimeOnly 'com.h2database:h2'
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.7.17'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
}

dependencyManagement {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kr/bb/product/ProductServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.mongodb.config.EnableReactiveMongoAuditing;

@SpringBootApplication
@EnableEurekaClient
@EnableJpaAuditing
@EnableReactiveMongoAuditing
public class ProductServiceApplication {

public static void main(String[] args) {
Expand Down
57 changes: 0 additions & 57 deletions src/main/java/kr/bb/product/config/DynamoDBConfiguration.java

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/java/kr/bb/product/dto/category/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@ToString
public class Category extends BaseEntity {
private Long id;
private Long categoryId;
private String categoryName;
}
31 changes: 31 additions & 0 deletions src/main/java/kr/bb/product/dto/request/ProductRequestData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kr.bb.product.dto.request;

import javax.validation.constraints.NotBlank;
import kr.bb.product.dto.category.Category;
import kr.bb.product.dto.tag.Tag;
import kr.bb.product.entity.Flowers;
import kr.bb.product.entity.ProductSaleStatus;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ProductRequestData {
private Category category;
@NotBlank private String productName;
@NotBlank private String productSummary;
@NotBlank private Long productPrice;
@NotBlank private ProductSaleStatus productSaleStatus;
private Tag tag;
private Flowers productFlowers;
@NotBlank private String productDescriptionImage;
@NotBlank private Long reviewCount;
@Builder.Default @NotBlank private Long productSaleAmount = 0L;
@NotBlank private Double averageRating;
@NotBlank private Long storeId;
}
4 changes: 2 additions & 2 deletions src/main/java/kr/bb/product/dto/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Tag extends BaseEntity {
private Long id;
private String categoryName;
private Long tagId;
private String tagName;
}
54 changes: 27 additions & 27 deletions src/main/java/kr/bb/product/entity/Product.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package kr.bb.product.entity;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import java.time.LocalDateTime;
import javax.persistence.Id;
import javax.validation.constraints.NotBlank;
import kr.bb.product.dto.category.Category;
import kr.bb.product.dto.tag.Tag;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@DynamoDBTable(tableName = "product")
@ToString
@Document(collation = "product")
public class Product {
@DynamoDBHashKey @DynamoDBAutoGeneratedKey private Long productId;
@Id @NotBlank private String productId;

@DynamoDBAttribute(attributeName = "category")
private Category category;

@DynamoDBAttribute(attributeName = "product_name")
private String productName;
@NotBlank private String productName;

@DynamoDBAttribute(attributeName = "product_summary")
private String productSummary;
@NotBlank private String productSummary;

@DynamoDBAttribute(attributeName = "product_price")
private Long productPrice;
@NotBlank private Long productPrice;

@DynamoDBAttribute(attributeName = "product_sale_status")
private ProductSaleStatus productSaleStatus;
@NotBlank private ProductSaleStatus productSaleStatus;

@DynamoDBAttribute(attributeName = "tag")
private Tag tag;

@DynamoDBAttribute(attributeName = "product_flowers")
private Flowers productFlowers;

@DynamoDBAttribute(attributeName = "product_description_image")
private String productDescriptionImage;
@NotBlank private String productDescriptionImage;
@NotBlank private Long reviewCount;
@Builder.Default @NotBlank private Long productSaleAmount = 0L;

@DynamoDBAttribute(attributeName = "review_count")
private Long reviewCount;
@NotBlank private Double averageRating;

@DynamoDBAttribute(attributeName = "product_sale_amount")
private Long productSaleAmount;
@NotBlank private Long storeId;

@DynamoDBAttribute(attributeName = "average_rating")
private Double averageRating;
@NotBlank @CreatedDate private LocalDateTime createdAt;

@DynamoDBAttribute(attributeName = "store_id")
private Long storeId;
@NotBlank @LastModifiedDate private LocalDateTime updatedAt;

@NotBlank
@Builder.Default
@Field(name = "is_deleted")
private Boolean isDeleted = false;
}
15 changes: 15 additions & 0 deletions src/main/java/kr/bb/product/mapper/ProductMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kr.bb.product.mapper;

import kr.bb.product.dto.request.ProductRequestData;
import kr.bb.product.entity.Product;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface ProductMapper {
@Mapping(target = "productId", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "updatedAt", ignore = true)
@Mapping(target = "isDeleted", ignore = true)
Product entityToData(ProductRequestData productRequestData);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kr.bb.product.repository;

import kr.bb.product.entity.Product;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface ProductMongoRepository extends MongoRepository<Product, String> {}
18 changes: 18 additions & 0 deletions src/main/java/kr/bb/product/service/ProductService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.bb.product.service;

import kr.bb.product.dto.request.ProductRequestData;
import kr.bb.product.mapper.ProductMapper;
import kr.bb.product.repository.ProductMongoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProductService {
private final ProductMongoRepository productMongoRepository;
private final ProductMapper productMapper;

public void createProduct(ProductRequestData productRequestData) {
productMongoRepository.save(productMapper.entityToData(productRequestData));
}
}
101 changes: 0 additions & 101 deletions src/test/java/kr/bb/product/config/DynamoDBConfigurationTest.java

This file was deleted.

Loading
Loading