-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductDao.java
47 lines (39 loc) · 1.65 KB
/
ProductDao.java
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
package com.hudabanimustafa.pos.pos.dao;
import com.hudabanimustafa.pos.pos.dto.OrderDto;
import com.hudabanimustafa.pos.pos.entity.OrderEntity;
import com.hudabanimustafa.pos.pos.entity.ProductEntity;
import com.hudabanimustafa.pos.pos.entity.SaleEntity;
import com.hudabanimustafa.pos.pos.repository.ProductRepo;
import com.hudabanimustafa.pos.pos.repository.SaleRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Optional;
@Service
public class ProductDao {
@Autowired
private ProductRepo productRepo;
public ProductEntity addProduct(ProductEntity product) {
return this.productRepo.save(product);
}
public ProductEntity updateProduct(ProductEntity product) {
return this.productRepo.save(product);
}
public void deleteProduct(Integer productId) {
this.productRepo.deleteById(productId);
}
public ProductEntity getProductByBarcode(String barcode) {
Optional<ProductEntity> o = Optional.ofNullable(this.productRepo.findByBarcode(barcode));
return o.isPresent() ? o.get() : null;
}
public ProductEntity getProductById(Integer productId) {
Optional<ProductEntity> o = this.productRepo.findById(productId);
return o.isPresent() ? o.get() : null;
}
public List<ProductEntity> getAllProducts() {
return this.productRepo.findAll();
}
}