Commit 548c2768 authored by lemin's avatar lemin

commit

parent e20a73c3
......@@ -31,7 +31,7 @@ public class ProductAggregate {
@CommandHandler
public ProductAggregate(CreateProductCommand command) {
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
......
......@@ -15,6 +15,6 @@ public class CreateProductCommand {
private final String name;
private final String comment;
private final BigDecimal price;
// private final Integer quantity;
private final Integer channel;
}
......@@ -35,7 +35,8 @@ public class ProductController {
public ResponseEntity<Map<String, String>> productCreate(@RequestBody ProductCreateDto productCreateDto) {
String productId = productService.createProduct(productCreateDto.getName(),
productCreateDto.getComment(),
BigDecimal.valueOf(productCreateDto.getPrice()));
BigDecimal.valueOf(productCreateDto.getPrice()),
productCreateDto.getChannel());
HashMap<String, String> m = new HashMap<>();
m.put("productId", productId);
m.put("productName", productCreateDto.getName());
......
......@@ -9,5 +9,6 @@ public class ProductCreateDto {
private String name;
private String comment;
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;
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.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ProductEntity {
public class ProductEntity{
@Id
private String id;
private String name;
private String comment;
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 {
private String name;
private String comment;
private BigDecimal price;
private Integer channel;
}
......@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.axonframework.eventhandling.EventHandler;
import org.springframework.stereotype.Component;
import com.showcase.synapse.product.entity.ChannelEntity;
import com.showcase.synapse.product.entity.ProductEntity;
import com.showcase.synapse.product.event.ProductCreatedEvent;
import com.showcase.synapse.product.event.ProductQuantityChangedEvent;
......@@ -27,6 +28,9 @@ public class ProductEventHandler {
productEntity.setName(productCreatedEvent.getName());
productEntity.setComment(productCreatedEvent.getComment());
productEntity.setPrice(productCreatedEvent.getPrice());
ChannelEntity ce = new ChannelEntity();
ce.setId(productCreatedEvent.getChannel());
productEntity.setChannel(ce);
productRepository.save(productEntity);
......
......@@ -28,11 +28,11 @@ public class ProductService {
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");
// command생성
CreateProductCommand createProductCommand = new CreateProductCommand(
UUID.randomUUID().toString(), name, comment, price
UUID.randomUUID().toString(), name, comment, price, channel
);
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