Commit 802a3849 authored by lemin's avatar lemin

Delivery commit

parent 1e7782a2
......@@ -8,11 +8,11 @@ import org.axonframework.eventsourcing.EventSourcingHandler;
import org.axonframework.modelling.command.AggregateIdentifier;
import org.axonframework.spring.stereotype.Aggregate;
import com.showcase.synapse.delivery.command.ChangeQuantityCommand;
import com.showcase.synapse.delivery.command.CreateProductCommand;
import com.showcase.synapse.delivery.event.ProductCreatedEvent;
import com.showcase.synapse.delivery.event.ProductQuantityChangedEvent;
import com.showcase.synapse.delivery.saga.ProductSaga;
import com.showcase.synapse.delivery.command.ChangeDeliveryStatusCommand;
import com.showcase.synapse.delivery.command.CreateDeliveryCommand;
import com.showcase.synapse.delivery.event.DeliveryCreatedEvent;
import com.showcase.synapse.delivery.event.DeliveryQuantityChangedEvent;
import com.showcase.synapse.delivery.saga.DeliverySaga;
import java.math.BigDecimal;
......@@ -21,7 +21,7 @@ import static org.axonframework.modelling.command.AggregateLifecycle.apply;
@Aggregate
@NoArgsConstructor
@Slf4j
public class ProductAggregate {
public class DeliveryAggregate {
@AggregateIdentifier
private String id;
......@@ -29,26 +29,26 @@ 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()));
public DeliveryAggregate(CreateDeliveryCommand command) {
log.info("[DeliveryAggregate(CreateDeliveryCommand) > apply new DeliveryCreatedEvent]");
apply(new DeliveryCreatedEvent(command.getId(), command.getName(), command.getComment(), command.getPrice()));
}
@EventSourcingHandler
public void createProduct(ProductCreatedEvent event) {
public void createProduct(DeliveryCreatedEvent event) {
this.id = event.getProductId();
// this.quantiy = event.getQuantity();
}
@CommandHandler
public void changeQuantity(ChangeQuantityCommand command) {
public void changeQuantity(ChangeDeliveryStatusCommand command) {
log.info("[@CommandHandler ProductchangeQuantity]");
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new ProductQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
// apply(new DeliveryQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
}
@EventSourcingHandler
public void changeQuantity(ProductQuantityChangedEvent event) {
public void changeQuantity(DeliveryQuantityChangedEvent event) {
// this.quantiy = event.getQuantity();
}
......
......@@ -7,7 +7,7 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public class ChangeQuantityCommand {
public class ChangeDeliveryStatusCommand {
@TargetAggregateIdentifier
private String productId;
......
......@@ -8,7 +8,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
@Getter
public class CreateProductCommand {
public class CreateDeliveryCommand {
@TargetAggregateIdentifier
private final String id;
......
......@@ -3,9 +3,9 @@ package com.showcase.synapse.delivery.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.showcase.synapse.delivery.dto.ProductCreateDto;
import com.showcase.synapse.delivery.entity.ProductEntity;
import com.showcase.synapse.delivery.service.ProductService;
import com.showcase.synapse.delivery.dto.DeliveryCreateDto;
import com.showcase.synapse.delivery.entity.DeliveryEntity;
import com.showcase.synapse.delivery.service.DeliveryService;
import java.math.BigDecimal;
import java.util.HashMap;
......@@ -16,23 +16,23 @@ import java.util.concurrent.ExecutionException;
@RestController
@RequestMapping("/api/msa/product")
@CrossOrigin(origins = "*")
public class ProductController {
public class DeliveryController {
final ProductService productService;
final DeliveryService productService;
public ProductController(ProductService productService) {
public DeliveryController(DeliveryService productService) {
this.productService = productService;
}
@GetMapping("/")
public ResponseEntity<List<ProductEntity>> getProducts() throws ExecutionException, InterruptedException {
List<ProductEntity> productEntities = productService.getProducts();
public ResponseEntity<List<DeliveryEntity>> getProducts() throws ExecutionException, InterruptedException {
List<DeliveryEntity> productEntities = productService.getProducts();
return ResponseEntity.ok(productEntities);
}
@PostMapping("/")
public ResponseEntity<Map<String, String>> productCreate(@RequestBody ProductCreateDto productCreateDto) {
public ResponseEntity<Map<String, String>> productCreate(@RequestBody DeliveryCreateDto productCreateDto) {
String productId = productService.createProduct(productCreateDto.getName(),
productCreateDto.getComment(),
BigDecimal.valueOf(productCreateDto.getPrice()));
......
......@@ -5,7 +5,7 @@ import lombok.Setter;
@Getter
@Setter
public class ProductCreateDto {
public class DeliveryCreateDto {
private String name;
private String comment;
private int price;
......
......@@ -14,7 +14,7 @@ import java.math.BigDecimal;
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ProductEntity {
public class DeliveryEntity {
@Id
private String id;
private String name;
......
package com.showcase.synapse.delivery.enums;
public enum OrderStatus {
public enum DeliveryStatus {
CREATED, CANCELED
}
......@@ -7,7 +7,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
@Getter
public class ProductCreatedEvent {
public class DeliveryCreatedEvent {
private String productId;
private String name;
private String comment;
......
......@@ -5,7 +5,7 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public class ProductQuantityChangedEvent {
public class DeliveryQuantityChangedEvent {
private String productId;
private int quantity;
}
......@@ -5,24 +5,24 @@ import lombok.extern.slf4j.Slf4j;
import org.axonframework.eventhandling.EventHandler;
import org.springframework.stereotype.Component;
import com.showcase.synapse.delivery.entity.ProductEntity;
import com.showcase.synapse.delivery.event.ProductCreatedEvent;
import com.showcase.synapse.delivery.event.ProductQuantityChangedEvent;
import com.showcase.synapse.delivery.repository.ProductRepository;
import com.showcase.synapse.delivery.entity.DeliveryEntity;
import com.showcase.synapse.delivery.event.DeliveryCreatedEvent;
import com.showcase.synapse.delivery.event.DeliveryQuantityChangedEvent;
import com.showcase.synapse.delivery.repository.DeliveryRepository;
@Component
@AllArgsConstructor
@Slf4j
public class ProductEventHandler {
public class DeliveryEventHandler {
private final ProductRepository productRepository;
private final DeliveryRepository productRepository;
@EventHandler
protected void saveProduct(ProductCreatedEvent productCreatedEvent) {
protected void saveProduct(DeliveryCreatedEvent productCreatedEvent) {
log.info("ProductCreatedEvent 이벤트 받음?");
log.info("ProductEventHandler > [ProductCreatedEvent] productCreatedEvent");
ProductEntity productEntity = new ProductEntity();
log.info("DeliveryCreatedEvent 이벤트 받음?");
log.info("DeliveryEventHandler > [DeliveryCreatedEvent] productCreatedEvent");
DeliveryEntity productEntity = new DeliveryEntity();
productEntity.setId(productCreatedEvent.getProductId());
productEntity.setName(productCreatedEvent.getName());
productEntity.setComment(productCreatedEvent.getComment());
......@@ -33,10 +33,10 @@ public class ProductEventHandler {
}
@EventHandler
protected void changeQuantity(ProductQuantityChangedEvent productQuantityChangedEvent) {
log.info("ProductQuantityChangedEvent 이벤트 받음?");
log.info("[ProductQuantityChangedEvent]");
ProductEntity productEntity = productRepository.findById(productQuantityChangedEvent.getProductId()).get();
protected void changeQuantity(DeliveryQuantityChangedEvent productQuantityChangedEvent) {
log.info("DeliveryQuantityChangedEvent 이벤트 받음?");
log.info("[DeliveryQuantityChangedEvent]");
DeliveryEntity productEntity = productRepository.findById(productQuantityChangedEvent.getProductId()).get();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
productRepository.save(productEntity);
......
......@@ -5,9 +5,9 @@ import java.util.List;
import org.axonframework.queryhandling.QueryHandler;
import org.springframework.stereotype.Component;
import com.showcase.synapse.delivery.entity.ProductEntity;
import com.showcase.synapse.delivery.query.GetProductsQuery;
import com.showcase.synapse.delivery.repository.ProductRepository;
import com.showcase.synapse.delivery.entity.DeliveryEntity;
import com.showcase.synapse.delivery.query.GetDeliveryQuery;
import com.showcase.synapse.delivery.repository.DeliveryRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -15,12 +15,12 @@ import lombok.extern.slf4j.Slf4j;
@Component
@RequiredArgsConstructor
@Slf4j
public class ProductQueryHandler {
public class DeliveryQueryHandler {
private final ProductRepository productRepository;
private final DeliveryRepository productRepository;
@QueryHandler
protected List<ProductEntity> on(GetProductsQuery query) {
protected List<DeliveryEntity> on(GetDeliveryQuery query) {
log.info("---product query---");
return productRepository.findAll();
}
......
package com.showcase.synapse.delivery.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.showcase.synapse.delivery.entity.ProductEntity;
import com.showcase.synapse.delivery.entity.DeliveryEntity;
public interface ProductRepository extends JpaRepository<ProductEntity, String> {
public interface DeliveryRepository extends JpaRepository<DeliveryEntity, String> {
}
......@@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
//@Saga
@Slf4j
public class ProductSaga {
public class DeliverySaga {
@Autowired
private transient CommandGateway commandGateway;
......
......@@ -10,28 +10,28 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
import org.axonframework.queryhandling.QueryGateway;
import org.springframework.stereotype.Service;
import com.showcase.synapse.delivery.command.CreateProductCommand;
import com.showcase.synapse.delivery.entity.ProductEntity;
import com.showcase.synapse.delivery.query.GetProductsQuery;
import com.showcase.synapse.delivery.command.CreateDeliveryCommand;
import com.showcase.synapse.delivery.entity.DeliveryEntity;
import com.showcase.synapse.delivery.query.GetDeliveryQuery;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class ProductService {
public class DeliveryService {
private final CommandGateway commandGateway;
private final QueryGateway queryGateway;
public ProductService(CommandGateway commandGateway, QueryGateway queryGateway) {
public DeliveryService(CommandGateway commandGateway, QueryGateway queryGateway) {
this.commandGateway = commandGateway;
this.queryGateway = queryGateway;
}
public String createProduct(String name, String comment, BigDecimal price) {
log.info("[@Service createProduct] new CreateProductCommand");
log.info("[@Service createProduct] new CreateDeliveryCommand");
// command생성
CreateProductCommand createProductCommand = new CreateProductCommand(
CreateDeliveryCommand createProductCommand = new CreateDeliveryCommand(
UUID.randomUUID().toString(), name, comment, price
);
System.out.println("test");
......@@ -42,9 +42,9 @@ public class ProductService {
return returnValue;
}
public List<ProductEntity> getProducts() throws ExecutionException, InterruptedException {
return queryGateway.query(new GetProductsQuery(),
ResponseTypes.multipleInstancesOf(ProductEntity.class)).get();
public List<DeliveryEntity> getProducts() throws ExecutionException, InterruptedException {
return queryGateway.query(new GetDeliveryQuery(),
ResponseTypes.multipleInstancesOf(DeliveryEntity.class)).get();
}
}
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