-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProductServiceImpl.java
More file actions
54 lines (43 loc) · 1.58 KB
/
Copy pathProductServiceImpl.java
File metadata and controls
54 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.example.demo.service;
import com.example.demo.model.Product;
import com.example.demo.repo.ProductRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductServiceImpl implements ProductService{
@Autowired
private ProductRepo productRepo;
@Override
public List<Product> retreiveAll(){
return productRepo.findAll();
}
@Override
public List<Product> retreiveByCategory(String category){
return productRepo.findAllByCategory(category);
}
@Override
public List<Product> retreiveByCategoryOfMerchant(int merchantID,String category){
List<Product> products = productRepo.findAllByMerchantID(merchantID);
products.stream().filter(p -> p.getCategory().equals(category));
return products;
}
@Override
public Product saveNewProduct(Product product){
return productRepo.save(product);
}
@Override
public void updateExistingProduct(int productID, Product newProduct){
Product product = productRepo.findByProductID(productID);
product.setCategory(newProduct.getCategory());
product.setDescription(newProduct.getDescription());
product.setName(newProduct.getName());
product.setPrice(newProduct.getPrice());
product.setMerchantID(newProduct.getMerchantID());
}
@Override
public void deleteProduct(int productID){
Product product = productRepo.findByProductID(productID);
productRepo.delete(product);
}
}