From 184c3846cf701309d701cc59a46abba06d4731be Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Thu, 5 Jun 2025 16:14:33 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=87=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/todoapp/dto/ToBuysDTO.java | 2 +- .../com/example/todoapp/model/Stocks.java | 2 +- .../todoapp/service/ToBuysService.java | 19 +++++++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java b/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java index 649b912..fe6db25 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java @@ -14,7 +14,7 @@ import lombok.Data; @Data public class ToBuysDTO { private int tobuy_id; - private Integer stuff_id; + private Long stuff_id; private Long user_id; private int price; private int amount; diff --git a/backend/src/main/java/com/example/todoapp/model/Stocks.java b/backend/src/main/java/com/example/todoapp/model/Stocks.java index 4a13d3f..fb1b84b 100644 --- a/backend/src/main/java/com/example/todoapp/model/Stocks.java +++ b/backend/src/main/java/com/example/todoapp/model/Stocks.java @@ -52,7 +52,7 @@ public class Stocks { referencedColumnName = "stuff_id", nullable = false ) - private int stuff_id; + private Long stuff_id; /** diff --git a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java index 376c1c0..f34be5f 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -69,26 +69,25 @@ public class ToBuysService { User user = userRepository.findByUsername(username) .orElseThrow(() -> new RuntimeException("ユーザーが見つかりません: " + username)); - Stuffs stuffs; + Stuffs stuff; if (toBuyDTO.getStuff_id() == null) { // 新しい材料を作成 - stuffs = new Stuffs(); - stuffs.setStuff_name(toBuyDTO.getStuff_name()); - stuffs.setCategory(toBuyDTO.getCategory()); - stuffs = stuffsRepository.save(stuffs); + stuff = new Stuffs(); + stuff.setStuff_name(toBuyDTO.getStuff_name()); + stuff.setCategory(toBuyDTO.getCategory()); + stuff = stuffsRepository.save(stuff); } else { // 材料情報を取得 - int stuff_id = toBuyDTO.getStuff_id(); - Optional optionalStuffs = stuffsRepository.findById(stuff_id); + Optional optionalStuffs = stuffsRepository.findById(toBuyDTO.getStuff_id()); if (!optionalStuffs.isPresent()) { throw new RuntimeException("材料がありません"); } - stuffs = optionalStuffs.get(); + stuff = optionalStuffs.get(); } ToBuys toBuys = new ToBuys(); toBuys.setUser_id(user); - toBuys.setStuffs(stuffs); + toBuys.setStuff_id(stuff.getStuff_id()); toBuys.setAmount(toBuyDTO.getAmount()); toBuys.setStore(toBuyDTO.getShop()); @@ -134,7 +133,7 @@ public class ToBuysService { ToBuys toBuys = new ToBuys(); toBuys.setUser_id(user); - toBuys.setStuffs(stuffs); + toBuys.setStuff_id(stuffs.getStuff_id()); toBuys.setAmount(toBuyDTO.getAmount()); toBuys.setStore(toBuyDTO.getShop());