Commit 2cb2a4a1 authored by lemin's avatar lemin

commit

parent 5459bcbe
package com.showcase.synapse.sales.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.showcase.synapse.sales.dto.SalesCreateDto;
import com.showcase.synapse.sales.entity.SalesEntity;
import com.showcase.synapse.sales.service.SalesService;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.showcase.synapse.sales.dto.SalesCreateDto;
import com.showcase.synapse.sales.entity.ProductEntity;
import com.showcase.synapse.sales.entity.SalesEntity;
import com.showcase.synapse.sales.service.SalesService;
@RestController
@RequestMapping("/api/msa/product")
@RequestMapping("/api/msa/sales")
@CrossOrigin(origins = "*")
public class SalesController {
final SalesService productService;
final SalesService salesService;
public SalesController(SalesService productService) {
this.productService = productService;
public SalesController(SalesService salesService) {
this.salesService = salesService;
}
@GetMapping("/")
public ResponseEntity<List<SalesEntity>> getProducts() throws ExecutionException, InterruptedException {
List<SalesEntity> productEntities = productService.getProducts();
@GetMapping("/product/")
public ResponseEntity<List<ProductEntity>> getProducts() throws ExecutionException, InterruptedException {
List<ProductEntity> productEntities = salesService.getProducts();
return ResponseEntity.ok(productEntities);
}
@GetMapping("/")
public ResponseEntity<List<SalesEntity>> getSalesList() throws ExecutionException, InterruptedException {
List<SalesEntity> salesList = salesService.getSalesList();
return ResponseEntity.ok(salesList);
}
@PostMapping("/")
public ResponseEntity<Map<String, String>> productCreate(@RequestBody SalesCreateDto productCreateDto) {
String productId = productService.createProduct(productCreateDto.getName(),
String productId = salesService.createProduct(productCreateDto.getName(),
productCreateDto.getComment(),
BigDecimal.valueOf(productCreateDto.getPrice()));
HashMap<String, String> m = new HashMap<>();
......
package com.showcase.synapse.sales.entity;
import java.math.BigDecimal;
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
@Column(name = "channel_id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "discount_rate")
private BigDecimal discountRate;
}
package com.showcase.synapse.sales.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class InventoryEntity implements Serializable{
private static final long serialVersionUID = -6540276275154344203L;
@Id
@Column(name = "wh_id")
private String whid;
@Column(name = "ref_product_id")
private String productid;
private String whName;
private Integer quantity;
}
package com.showcase.synapse.sales.entity;
import java.math.BigDecimal;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
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(fetch= FetchType.EAGER,cascade = CascadeType.PERSIST)
@JoinColumn(name = "channel_id")
private ChannelEntity channel;
@OneToOne(fetch= FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "ref_product_id", referencedColumnName = "ref_product_id")
private InventoryEntity inventory;
}
......@@ -11,6 +11,7 @@ import org.axonframework.queryhandling.QueryGateway;
import org.springframework.stereotype.Service;
import com.showcase.synapse.sales.command.CreateSalesCommand;
import com.showcase.synapse.sales.entity.ProductEntity;
import com.showcase.synapse.sales.entity.SalesEntity;
import com.showcase.synapse.sales.query.GetSalesQuery;
......@@ -42,9 +43,14 @@ public class SalesService {
return returnValue;
}
public List<SalesEntity> getProducts() throws ExecutionException, InterruptedException {
public List<ProductEntity> getProducts() throws ExecutionException, InterruptedException {
return queryGateway.query(new GetSalesQuery(),
ResponseTypes.multipleInstancesOf(SalesEntity.class)).get();
ResponseTypes.multipleInstancesOf(ProductEntity.class)).get();
}
public List<SalesEntity> getSalesList() throws ExecutionException, InterruptedException {
return queryGateway.query(new GetSalesQuery(),
ResponseTypes.multipleInstancesOf(SalesEntity.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