Commit 548c2768 authored by lemin's avatar lemin

commit

parent e20a73c3
...@@ -31,7 +31,7 @@ public class ProductAggregate { ...@@ -31,7 +31,7 @@ public class ProductAggregate {
@CommandHandler @CommandHandler
public ProductAggregate(CreateProductCommand command) { public ProductAggregate(CreateProductCommand command) {
log.info("[ProductAggregate(CreateProductCommand) > apply new ProductCreatedEvent]"); log.info("[ProductAggregate(CreateProductCommand) > apply new ProductCreatedEvent]");
apply(new ProductCreatedEvent(command.getId(), command.getName(), command.getComment(), command.getPrice())); apply(new ProductCreatedEvent(command.getId(), command.getName(), command.getComment(), command.getPrice(), command.getChannel()));
} }
@EventSourcingHandler @EventSourcingHandler
......
...@@ -15,6 +15,6 @@ public class CreateProductCommand { ...@@ -15,6 +15,6 @@ public class CreateProductCommand {
private final String name; private final String name;
private final String comment; private final String comment;
private final BigDecimal price; private final BigDecimal price;
// private final Integer quantity; private final Integer channel;
} }
...@@ -35,7 +35,8 @@ public class ProductController { ...@@ -35,7 +35,8 @@ public class ProductController {
public ResponseEntity<Map<String, String>> productCreate(@RequestBody ProductCreateDto productCreateDto) { public ResponseEntity<Map<String, String>> productCreate(@RequestBody ProductCreateDto productCreateDto) {
String productId = productService.createProduct(productCreateDto.getName(), String productId = productService.createProduct(productCreateDto.getName(),
productCreateDto.getComment(), productCreateDto.getComment(),
BigDecimal.valueOf(productCreateDto.getPrice())); BigDecimal.valueOf(productCreateDto.getPrice()),
productCreateDto.getChannel());
HashMap<String, String> m = new HashMap<>(); HashMap<String, String> m = new HashMap<>();
m.put("productId", productId); m.put("productId", productId);
m.put("productName", productCreateDto.getName()); m.put("productName", productCreateDto.getName());
......
...@@ -9,5 +9,6 @@ public class ProductCreateDto { ...@@ -9,5 +9,6 @@ public class ProductCreateDto {
private String name; private String name;
private String comment; private String comment;
private int price; private int price;
private int channel;
} }
package com.showcase.synapse.product.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ChannelEntity {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "channel_id")
private Integer id;
@Column(name = "name")
private String name;
}
package com.showcase.synapse.product.entity; package com.showcase.synapse.product.entity;
import java.math.BigDecimal;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity @Entity
@Getter @Getter
@Setter @Setter
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class ProductEntity { public class ProductEntity{
@Id
@Id
private String id; private String id;
private String name; private String name;
private String comment; private String comment;
private BigDecimal price; private BigDecimal price;
// @Column(name = "channel", nullable = false)
// private Integer channel;
@OneToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "channel_id")
private ChannelEntity channel;
} }
...@@ -12,4 +12,5 @@ public class ProductCreatedEvent { ...@@ -12,4 +12,5 @@ public class ProductCreatedEvent {
private String name; private String name;
private String comment; private String comment;
private BigDecimal price; private BigDecimal price;
private Integer channel;
} }
...@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.axonframework.eventhandling.EventHandler; import org.axonframework.eventhandling.EventHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.showcase.synapse.product.entity.ChannelEntity;
import com.showcase.synapse.product.entity.ProductEntity; import com.showcase.synapse.product.entity.ProductEntity;
import com.showcase.synapse.product.event.ProductCreatedEvent; import com.showcase.synapse.product.event.ProductCreatedEvent;
import com.showcase.synapse.product.event.ProductQuantityChangedEvent; import com.showcase.synapse.product.event.ProductQuantityChangedEvent;
...@@ -27,6 +28,9 @@ public class ProductEventHandler { ...@@ -27,6 +28,9 @@ public class ProductEventHandler {
productEntity.setName(productCreatedEvent.getName()); productEntity.setName(productCreatedEvent.getName());
productEntity.setComment(productCreatedEvent.getComment()); productEntity.setComment(productCreatedEvent.getComment());
productEntity.setPrice(productCreatedEvent.getPrice()); productEntity.setPrice(productCreatedEvent.getPrice());
ChannelEntity ce = new ChannelEntity();
ce.setId(productCreatedEvent.getChannel());
productEntity.setChannel(ce);
productRepository.save(productEntity); productRepository.save(productEntity);
......
...@@ -28,11 +28,11 @@ public class ProductService { ...@@ -28,11 +28,11 @@ public class ProductService {
this.queryGateway = queryGateway; this.queryGateway = queryGateway;
} }
public String createProduct(String name, String comment, BigDecimal price) { public String createProduct(String name, String comment, BigDecimal price, int channel) {
log.info("[@Service createProduct] new CreateProductCommand"); log.info("[@Service createProduct] new CreateProductCommand");
// command생성 // command생성
CreateProductCommand createProductCommand = new CreateProductCommand( CreateProductCommand createProductCommand = new CreateProductCommand(
UUID.randomUUID().toString(), name, comment, price UUID.randomUUID().toString(), name, comment, price, channel
); );
System.out.println("test"); System.out.println("test");
// 여기 // 여기
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment