пыталась сделать доп из 3 лабы......

This commit is contained in:
Ino 2023-04-28 15:15:53 +04:00
parent a9112f5e06
commit 4f93068cce
6 changed files with 49 additions and 47 deletions

View File

@ -1,6 +1,10 @@
package com.example.demo.supply.Order;
import com.example.demo.supply.Product.Product;
import com.example.demo.supply.Product.ProductDto;
import com.example.demo.supply.Supplier.Supplier;
import com.example.demo.supply.Supplier.SupplierDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -30,6 +34,16 @@ public class OrderController {
return orderService.findAllOrderProducts(id).stream().map(ProductDto::new).toList();
}
// @PostMapping("/someSuppliers/")
// public List<SupplierDto> getSomeSuppliers(@RequestBody() List<Product> products) {
// return orderService.suppliers(products).stream().map(SupplierDto::new).toList();
// }
// @PostMapping("/someSuppliers/")
// public List<ProductDto> getSomeSuppliers(@RequestBody() List<ProductDto> products) {
// return products;
// }
@PostMapping("/")
public Long createOrder(@RequestParam() Long supplierId) {
return new OrderDto(orderService.addOrder(supplierId)).getId();

View File

@ -1,10 +1,14 @@
package com.example.demo.supply.Order;
import com.example.demo.supply.Product.Product;
import com.example.demo.supply.Supplier.Supplier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface OrderRepository extends JpaRepository<_Order, Long> {
@Query("SELECT distinct o.supplier FROM _Order o join Product p where p in (?1)")
List<Supplier> getSomeSuppliers(List<Product> products);
}

View File

@ -2,6 +2,7 @@ package com.example.demo.supply.Order;
import com.example.demo.supply.Product.Product;
import com.example.demo.supply.Product.ProductService;
import com.example.demo.supply.Supplier.Supplier;
import com.example.demo.supply.Supplier.SupplierService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -40,6 +41,11 @@ public class OrderService {
// .setParameter("products", products).getResultList();
// }
@Transactional
public List<Supplier> suppliers(List<Product> products){
return orderRepository.getSomeSuppliers(products);
}
@Transactional
public _Order addProduct(Long id, Long productId) {
final _Order currentOrder = findOrder(id);

View File

@ -51,6 +51,28 @@ export default class DataService {
return true;
}
static async getSomeSuppliers(){
const arr =[
{
"id":104,
"name":"prod3",
"cost":3333
},
{
"id":153,
"name":"prod3",
"cost":5555
}
]
//const resArr = JSON.stringify(arr)
//console.log(resArr)
const response = await axios.post(this.mainUrl + `order/someSuppliers/`, {
body: {arr}
});
console.log(response)
}
static async update(url, data) {
await fetch(getFullUrl(this.mainUrl + url, data), {
method: 'PATCH',

View File

@ -56,7 +56,9 @@ export default function OrderPage(){
}
const handleTableClick = (tableSelectedItems) => {selectedItems = tableSelectedItems;}
const handleTableDblClick = (tableSelectedItem) =>{}
const handleTableDblClick = (tableSelectedItem) =>{
DataService.getSomeSuppliers()
}
return(
<>

View File

@ -1,46 +0,0 @@
import axios from 'axios';
function toJSON(data) {
const jsonObj = {};
const fields = Object.getOwnPropertyNames(data);
for (const field of fields) {
if (data[field] === undefined) {
continue;
}
jsonObj[field] = data[field];
}
return jsonObj;
}
export default class DataService {
static dataUrlPrefix = 'http://localhost:8080/';
static async readAll(url, transformer) {
const response = await axios.get(this.dataUrlPrefix + url);
return response.data.map(item => transformer(item));
}
static async read(url, transformer) {
const response = await axios.get(this.dataUrlPrefix + url);
return transformer(response.data);
}
static async create(url, data) {
console.log(toJSON(data))
const response = await axios.post(this.dataUrlPrefix + url, {
name: 'prod4',
cost: 123
});
return true;
}
static async update(url, data) {
const response = await axios.put(this.dataUrlPrefix + url, toJSON(data));
return true;
}
static async delete(url) {
const response = await axios.delete(this.dataUrlPrefix + url);
return response.data.id;
}
}