Commit 0eac338a authored by shoei.kanno's avatar shoei.kanno

商品管理画面、重複商品は個数を変更

parent 9eeaf4ab
......@@ -12,4 +12,9 @@ import com.example.domain.Shoes;
public interface ShoesRepository extends JpaRepository<Shoes, Integer>{
@Query(value = "SELECT * FROM shoes WHERE product_status = ?1 ORDER BY id DESC", nativeQuery = true)
public List <Shoes> findAllByStatus(Integer status);
//管理画面で使用
@Query(value = "SELECT * FROM shoes WHERE name = ?1 && size = ?2", nativeQuery = true)
public Shoes findOneAddStock(String name, Integer size);
}
\ No newline at end of file
......@@ -49,4 +49,9 @@ public class ShoesService {
public List<Shoes> findAllLimitedShoes() {
return shoesRepository.findAllByStatus(1);
}
//管理画面、重複商品のバリデーション
public Shoes findOneAddStock(String name, Integer size) {
return shoesRepository.findOneAddStock(name, size);
};
}
......@@ -62,7 +62,23 @@ public class ManagementController {
if(result.hasErrors()) {
return "management";
}
multipartFile = form.getMultipartFile();
System.out.println(multipartFile);
//以前に登録されている商品の場合に登録できないバリデーション
Shoes sameShoes = shoesService.findOneAddStock(form.getName(), form.getSize());
System.out.println(sameShoes);
if (!(sameShoes == null)) {
Integer sumStock = form.getStock() + sameShoes.getStock();
if (sumStock >= 10) {
sameShoes.setStock(10);
shoesService.update(sameShoes);
} else {
sameShoes.setStock(sumStock);
shoesService.update(sameShoes);
}
} else {
Shoes shoes = new Shoes();
if (!multipartFile.isEmpty()) {
try {
......@@ -112,12 +128,19 @@ public class ManagementController {
} else {
shoes.setPhoto("noimage.jpg");
}
shoes.setName(form.getName());
shoes.setPrice(form.getPrice());
shoes.setStock(form.getStock());
shoes.setSize(form.getSize());
shoes.setProductStatus(form.getProductStatus());
shoesService.update(shoes);
}
//遷移先
return "redirect:/limited/admin/management";
}
......
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