From 1df241c8656b4c5d535723e0833202fd3b17f3fd Mon Sep 17 00:00:00 2001 From: Amagasu Date: Fri, 6 Jun 2025 13:15:50 +0900 Subject: [PATCH] varname _ remove, id type int -> long --- .../todoapp/dto/DeleteToBuyRequest.java | 2 +- .../com/example/todoapp/dto/StockDTO.java | 24 +++++++-------- .../example/todoapp/dto/ToBuyResponse.java | 2 +- .../com/example/todoapp/dto/ToBuysDTO.java | 2 +- .../example/todoapp/model/RecipeStuffs.java | 2 +- .../com/example/todoapp/model/Recipes.java | 2 +- .../com/example/todoapp/model/Stocks.java | 29 ++++++++++++------- .../com/example/todoapp/model/ToBuys.java | 2 +- .../todoapp/repository/ToBuysRepository.java | 2 +- .../todoapp/service/StocksService.java | 12 ++++---- .../todoapp/service/ToBuysService.java | 2 +- 11 files changed, 45 insertions(+), 36 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java index b8f7b9e..07b2a37 100644 --- a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java +++ b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java @@ -5,5 +5,5 @@ import lombok.Data; @Data public class DeleteToBuyRequest { private Long userId; - private int tobuyId; + private Long tobuyId; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/StockDTO.java b/backend/src/main/java/com/example/todoapp/dto/StockDTO.java index 7d54c84..284b134 100644 --- a/backend/src/main/java/com/example/todoapp/dto/StockDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/StockDTO.java @@ -16,14 +16,14 @@ import java.time.LocalDate; @Data public class StockDTO { - private Long stock_id; - private Long stuff_id; - private Long user_id; + private Long stockId; + private Long stuffId; + private Long userId; private int amount; private int price; - private LocalDate buy_date; - private LocalDate last_update; - private LocalDate exp_date; + private LocalDate buyDate; + private LocalDate lastUpdate; + private LocalDate expDate; /** * 在庫エンティティからDTOを作成する @@ -33,14 +33,14 @@ public class StockDTO { */ public static StockDTO fromEntity(Stocks stock) { StockDTO dto = new StockDTO(); - dto.setStock_id(stock.getStock_id()); - dto.setStuff_id(stock.getStuff_id()); - dto.setUser_id(stock.getUser_id().getId()); + dto.setStockId(stock.getStockId()); + dto.setStuffId(stock.getStuff().getStuffId()); + dto.setUserId(stock.getUser().getId()); dto.setAmount(stock.getAmount()); dto.setPrice(stock.getPrice()); - dto.setBuy_date(stock.getBuy_date()); - dto.setLast_update(stock.getLast_update()); - dto.setExp_date(stock.getExp_date()); + dto.setBuyDate(stock.getBuyDate()); + dto.setLastUpdate(stock.getLastUpdate()); + dto.setExpDate(stock.getExpDate()); return dto; } } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java index e4a677a..407ae91 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java @@ -4,7 +4,7 @@ import lombok.Data; @Data public class ToBuyResponse { - private int tobuyId; + private Long tobuyId; private Long stuffId; private String stuffName; private int amount; 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 111ccad..fd4a6ff 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java @@ -13,7 +13,7 @@ import lombok.Data; @Data public class ToBuysDTO { - private int tobuyId; + private Long tobuyId; private Long stuffId; private Long userId; private int price; diff --git a/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java b/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java index efd9017..0855330 100644 --- a/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java +++ b/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java @@ -38,7 +38,7 @@ public class RecipeStuffs { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="recipe_stuffs_id") - private int recipeStuffsId ; + private Long recipeStuffsId ; /** * 料理の一意識別子 FK diff --git a/backend/src/main/java/com/example/todoapp/model/Recipes.java b/backend/src/main/java/com/example/todoapp/model/Recipes.java index 25eaaad..c4a986d 100644 --- a/backend/src/main/java/com/example/todoapp/model/Recipes.java +++ b/backend/src/main/java/com/example/todoapp/model/Recipes.java @@ -36,7 +36,7 @@ public class Recipes { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="recipeId") - private int recipeId ; + private Long recipeId ; /** * カテゴリ名 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 1b5b067..1b8ede7 100644 --- a/backend/src/main/java/com/example/todoapp/model/Stocks.java +++ b/backend/src/main/java/com/example/todoapp/model/Stocks.java @@ -39,7 +39,7 @@ public class Stocks { */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long stockI ; + private Long stockId; /** @@ -55,18 +55,27 @@ public class Stocks { private Stuffs stuff; - /** - * ユーザーテーブル参照用の外部キー + // /** + // * ユーザーテーブル参照用の外部キー + // */ + // @NotNull + // @ManyToOne(fetch = FetchType.LAZY) + // @JoinColumn( + // name = "userId", + // referencedColumnName = "id", + // nullable = false + // ) + // private User user; + + /** + * タスクの所有者(ユーザー) + * 多対一の関係で、遅延ロードを使用 */ - @NotNull - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn( - name = "userId", - referencedColumnName = "id", - nullable = false - ) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "userId", nullable = false) private User user; + /** * 在庫数量(デフォルト値: 1) */ diff --git a/backend/src/main/java/com/example/todoapp/model/ToBuys.java b/backend/src/main/java/com/example/todoapp/model/ToBuys.java index e000516..6ab9052 100644 --- a/backend/src/main/java/com/example/todoapp/model/ToBuys.java +++ b/backend/src/main/java/com/example/todoapp/model/ToBuys.java @@ -37,7 +37,7 @@ public class ToBuys { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "tobuyId") - private int tobuyId ; + private Long tobuyId ; /** * 材料の一意識別子 FK diff --git a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java index c208db9..ea45de7 100644 --- a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java @@ -45,5 +45,5 @@ public interface ToBuysRepository extends JpaRepository { */ @Modifying @Query("DELETE FROM ToBuys t WHERE t.user.id = :userId AND t.tobuyId = :tobuyId") - int deleteByUserIdAndTobuyId(@Param("userId") Long userId, @Param("tobuyId") int tobuyId); + int deleteByUserIdAndTobuyId(@Param("userId") Long userId, @Param("tobuyId") Long tobuyId); } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/service/StocksService.java b/backend/src/main/java/com/example/todoapp/service/StocksService.java index 85580d2..07dad3c 100644 --- a/backend/src/main/java/com/example/todoapp/service/StocksService.java +++ b/backend/src/main/java/com/example/todoapp/service/StocksService.java @@ -37,7 +37,7 @@ public class StocksService { */ public Stocks createStock(String username, Stocks stock) { User user = getUserByUsername(username); - stock.setUser_id(user); + stock.setUser(user); return stocksRepository.save(stock); } @@ -49,7 +49,7 @@ public class StocksService { */ public List getALLStocksByUser(String username) { User user = getUserByUsername(username); - return stocksRepository.findStocksByUser_id(user.getId()); + return stocksRepository.findStocksByUserId(user.getId()); } /** @@ -63,7 +63,7 @@ public class StocksService { public Stocks getStockById(String username, Long stockId) { User user = getUserByUsername(username); return stocksRepository.findById(stockId) - .filter(stock -> stock.getUser_id().getId().equals(user.getId())) // ユーザーの在庫かどうかを確認 + .filter(stock -> stock.getUser().equals(user)) // ユーザーの在庫かどうかを確認 .orElseThrow(() -> new RuntimeException(messageUtils.getMessage("error.stock.not.found"))); } @@ -79,9 +79,9 @@ public class StocksService { Stocks stock = getStockById(username, stockId); stock.setAmount(stockDetails.getAmount()); stock.setPrice(stockDetails.getPrice()); - stock.setLast_update(stockDetails.getLast_update()); - stock.setBuy_date(stockDetails.getBuy_date()); - stock.setExp_date(stockDetails.getExp_date()); + stock.setLastUpdate(stockDetails.getLastUpdate()); + stock.setBuyDate(stockDetails.getBuyDate()); + stock.setExpDate(stockDetails.getExpDate()); return stocksRepository.save(stock); } 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 41847d9..0908e01 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -159,7 +159,7 @@ public class ToBuysService { * @param tobuyId 購入リストID */ @Transactional - public int deleteToBuyByIds(Long userId, int tobuyId) { + public int deleteToBuyByIds(Long userId, Long tobuyId) { return toBuysRepository.deleteByUserIdAndTobuyId(userId, tobuyId); }