Commit c0eed78e authored by lemin's avatar lemin

wms commit

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