From e40755598fb749f1d5dd63fa5bb55a2940bb0657 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Tue, 3 Jun 2025 10:51:52 +0900 Subject: [PATCH 01/23] =?UTF-8?q?model=E3=82=92=E4=BD=9C=E6=88=90=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/todoapp/model/RecipeStuffs.java | 74 +++++++++++++ .../com/example/todoapp/model/Recipes.java | 53 ++++++++++ .../com/example/todoapp/model/Stocks.java | 100 ++++++++++++++++++ .../com/example/todoapp/model/Stuffs.java | 59 +++++++++++ .../com/example/todoapp/model/ToBuys.java | 81 ++++++++++++++ 5 files changed, 367 insertions(+) create mode 100644 backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java create mode 100644 backend/src/main/java/com/example/todoapp/model/Recipes.java create mode 100644 backend/src/main/java/com/example/todoapp/model/Stocks.java create mode 100644 backend/src/main/java/com/example/todoapp/model/Stuffs.java create mode 100644 backend/src/main/java/com/example/todoapp/model/ToBuys.java diff --git a/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java b/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java new file mode 100644 index 0000000..fc94cd5 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java @@ -0,0 +1,74 @@ +//-------------------------------- +// RecipiesStuffs.java +// +// 分類:社員管理システムV2・ビジネスロジック層 +// +// 更新履歴:2025/06/02 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + +package com.example.todoapp.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 料理に必要な材料 + */ +@Data +@NoArgsConstructor +@Entity +@Table(name = "recipe_stuffs") +public class RecipeStuffs { + + + /** + * 料理に必要リストの一意識別子 + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int recipe_stuffs_id ; + + /** + * 料理の一意識別子 FK + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "recipe_id", + referencedColumnName = "recipe_id", + nullable = false + ) + private Recipes recipes; + + + /** + * 材料の一意識別子 FK + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "stuff_id", + referencedColumnName = "stuff_id", + nullable = false + ) + private Stuffs stuffs; + + /** + * 材料の数量 + */ + @NotBlank + @Column(nullable = false) + private int amount; + +} diff --git a/backend/src/main/java/com/example/todoapp/model/Recipes.java b/backend/src/main/java/com/example/todoapp/model/Recipes.java new file mode 100644 index 0000000..76de887 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/model/Recipes.java @@ -0,0 +1,53 @@ +//-------------------------------- +// Recipes.java +// +// 分類:社員管理システムV2・ビジネスロジック層 +// +// 更新履歴:2025/06/02 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + +package com.example.todoapp.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * カテゴリエンティティクラス + * このクラスはタスクのカテゴリ情報を表します。 + * カテゴリは名前、色、所有ユーザーなどの情報を持ちます。 + */ + +@Data +@NoArgsConstructor +@Entity +@Table(name = "recipes") +public class Recipes { + /** + * カテゴリID(主キー) + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int recipe_id ; + + /** + * カテゴリ名 + */ + @NotBlank + @Column(unique = true, length = 255, nullable = false) + private String recipie_name; + + /** + * カテゴリ + */ + @Column (columnDefinition = "TEXT") + private String summary; + +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/model/Stocks.java b/backend/src/main/java/com/example/todoapp/model/Stocks.java new file mode 100644 index 0000000..660ab87 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/model/Stocks.java @@ -0,0 +1,100 @@ +//-------------------------------- +// Stocks.java +// +// 分類:社員管理システムV2・ビジネスロジック層 +// +// 更新履歴:2025/06/03 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + +package com.example.todoapp.model; + +import java.time.LocalDate; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * 在庫にある食材 + */ + +@Data +@NoArgsConstructor +@Entity +@Table(name = "stocks") +public class Stocks { + /** + * 在庫リストの一意識別子 + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int stock_id ; + + + /** + * 商品テーブル参照用の外部キー + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "stuff_id", + referencedColumnName = "stuff_id", + nullable = false + ) + private Stuffs stuffs; + + + /** + * ユーザーテーブル参照用の外部キー + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "user_id", + referencedColumnName = "id", + nullable = false + ) + private User user_id; + + /** + * 在庫数量(デフォルト値: 1) + */ + @Column(nullable = false) + private int amount = 1; + + /** + * シングルの値段(デフォルト値: 0) + */ + @Column(nullable = false) + private int price = 0; + + /** + * 購入日 + */ + @Column(nullable = false) + private LocalDate buy_date; + + /** + * 最後の操作時間 + */ + @Column(nullable = false) + private LocalDate last_update; + + /** + * 賞味期限 + */ + @Column(nullable = false) + private LocalDate exp_date; + +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/model/Stuffs.java b/backend/src/main/java/com/example/todoapp/model/Stuffs.java new file mode 100644 index 0000000..b0e7939 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/model/Stuffs.java @@ -0,0 +1,59 @@ +//-------------------------------- +// Stuffs.java +// +// 分類:社員管理システムV2・ビジネスロジック層 +// +// 更新履歴:2025/06/02 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + +package com.example.todoapp.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * カテゴリエンティティクラス + * このクラスはタスクのカテゴリ情報を表します。 + * カテゴリは名前、色、所有ユーザーなどの情報を持ちます。 + */ +@Data +@NoArgsConstructor +@Entity +@Table(name = "stuffs") + public class Stuffs { + + /** + * カテゴリID(主キー) + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int stuff_id ; + + /** + * カテゴリ名 + */ + @NotBlank + @Column(unique = true, length = 255, nullable = false) + private String stuff_name; + + /** + * カテゴリ + */ + @Column (columnDefinition = "TEXT") + private String summary; + + /** + * カテゴリ + */ + @NotBlank + @Column(nullable = false, length = 225) + private String category = "その他" ; + } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/model/ToBuys.java b/backend/src/main/java/com/example/todoapp/model/ToBuys.java new file mode 100644 index 0000000..25bb797 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/model/ToBuys.java @@ -0,0 +1,81 @@ +//-------------------------------- +// ToBuys.java +// +// 分類:社員管理システムV2・ビジネスロジック層 +// +// 更新履歴:2025/06/03 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + +package com.example.todoapp.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * ユーザーの買うものリスト + */ + +@Data +@NoArgsConstructor +@Entity +@Table(name = "to_buys") +public class ToBuys { + + /** + * 購入項目の一意識別子 + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int tobuy_id ; + + /** + * 材料の一意識別子 FK + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "stuff_id", + referencedColumnName = "stuff_id", + nullable = false + ) + private Stuffs stuffs; + + /** + * ユーザーテーブル参照用の外部キー + */ + @NotBlank + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn( + name = "user_id", + referencedColumnName = "id", + nullable = false + ) + private User user_id; + + /** + * 購入する数量 + */ + @NotBlank + @Column(nullable = false) + private int amount = 1; + + /** + * 購入するお店 + */ + @NotBlank + @Column(nullable = false) + private String store; + +} + From ec4669c92b5bb9b35c5c738428e606debdf9fb2f Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Wed, 4 Jun 2025 11:04:31 +0900 Subject: [PATCH 02/23] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/TestPage.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 frontend/src/pages/TestPage.tsx diff --git a/frontend/src/pages/TestPage.tsx b/frontend/src/pages/TestPage.tsx new file mode 100644 index 0000000..f6d70be --- /dev/null +++ b/frontend/src/pages/TestPage.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { Box } from '@mui/material'; + +const TestPage: React.FC = () => { + return ( + + {/* 白紙のページ - 何も表示しない */} + + ); +}; + +export default TestPage; \ No newline at end of file From cb2ffbd4935ecad241b81dc29262843e6e5abb95 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Wed, 4 Jun 2025 16:03:35 +0900 Subject: [PATCH 03/23] =?UTF-8?q?add-=E6=97=A2=E5=AD=98=E3=81=AE=E9=A3=9F?= =?UTF-8?q?=E6=9D=90=E3=81=AE=E5=A0=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 22 ++++++++ .../com/example/todoapp/dto/ToBuyDTO.java | 18 +++++++ .../todoapp/repository/StuffsRepository.java | 12 +++++ .../todoapp/repository/ToBuysRepository.java | 9 ++++ .../todoapp/service/ToBuysService.java | 51 +++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 backend/src/main/java/com/example/todoapp/controller/ToBuysController.java create mode 100644 backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java create mode 100644 backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java create mode 100644 backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java create mode 100644 backend/src/main/java/com/example/todoapp/service/ToBuysService.java diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java new file mode 100644 index 0000000..fbb0603 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -0,0 +1,22 @@ +package com.example.todoapp.controller; + +import com.example.todoapp.dto.ToBuyDTO; +import com.example.todoapp.service.ToBuysService; +import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/tobuy/add") +public class ToBuysController { + + @Autowired + private ToBuysService toBuysService; + + @PostMapping + public ResponseEntity addToBuys(@Valid @RequestBody ToBuyDTO dto) { + toBuysService.addToBuys(dto); + return ResponseEntity.ok("Item added to 'To Buys' successfully"); + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java b/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java new file mode 100644 index 0000000..36295bf --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java @@ -0,0 +1,18 @@ +package com.example.todoapp.dto; + +import lombok.Data; +/** + * カテゴリDTOクラス + * このクラスはタスクのカテゴリ情報を表します。 + * カテゴリは名前、色、所有ユーザーなどの情報を持ちます。 + * + */ + + @Data + public class ToBuyDTO { + private Long stuffsId; + private Long userId; + + private int amount; + private String store; + } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java b/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java new file mode 100644 index 0000000..3c29f31 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java @@ -0,0 +1,12 @@ +package com.example.todoapp.repository; + +import com.example.todoapp.model.Stuffs; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface StuffsRepository extends JpaRepository { + Optional findById(Long id); +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java new file mode 100644 index 0000000..ff6469f --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java @@ -0,0 +1,9 @@ +package com.example.todoapp.repository; + +import com.example.todoapp.model.ToBuys; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ToBuysRepository extends JpaRepository { +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java new file mode 100644 index 0000000..2a44acb --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -0,0 +1,51 @@ +package com.example.todoapp.service; + +import com.example.todoapp.dto.ToBuyDTO; +import com.example.todoapp.model.Stuffs; +import com.example.todoapp.model.ToBuys; +import com.example.todoapp.model.User; +import com.example.todoapp.repository.StuffsRepository; +import com.example.todoapp.repository.ToBuysRepository; +import com.example.todoapp.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public class ToBuysService { + + @Autowired + private ToBuysRepository toBuysRepository; + + @Autowired + private UserRepository userRepository; + + @Autowired + private StuffsRepository stuffsRepository; + + public void addToBuys(ToBuyDTO toBuyDTO) { + + //get user + Optional user = userRepository.findById(toBuyDTO.getUserId()); + if (!user.isPresent()) { + throw new RuntimeException("no: " + toBuyDTO.getUserId()); + } + + //get stuffs + Optional stuffs = stuffsRepository.findById(toBuyDTO.getStuffsId()); + if (!stuffs.isPresent()) { + throw new RuntimeException("材料不存在"); + } + + ToBuys toBuys = new ToBuys(); + toBuys.setUser_id(user.get()); + toBuys.setStuffs(stuffs.get()); + toBuys.setAmount(toBuyDTO.getAmount()); + toBuys.setStore(toBuyDTO.getStore()); + + // 保存到数据库 + toBuysRepository.save(toBuys); + + } +} \ No newline at end of file From 840f2365403e8713aa0d4510dd4fab8753bba689 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Wed, 4 Jun 2025 17:19:31 +0900 Subject: [PATCH 04/23] ToBuyDto.java --- .../src/main/java/com/example/todoapp/dto/ToBuyDTO.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java b/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java index 36295bf..6212f7d 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java @@ -10,9 +10,12 @@ import lombok.Data; @Data public class ToBuyDTO { - private Long stuffsId; - private Long userId; + private Long stuff_id; + private Long user_id; private int amount; - private String store; + private String shop; + + private String stuff_name; + private String category; } \ No newline at end of file From 44cd5183cd3eae0744d66fb2c39c3a7b0610d6f2 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 09:24:42 +0900 Subject: [PATCH 05/23] =?UTF-8?q?1.=20toBuysController,=20toBuysService,?= =?UTF-8?q?=20toBuysRepository,=20stuffsRepository=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=202.=20recipes,=20stuffs,=20tobuys,=20stocks=20?= =?UTF-8?q?=E3=81=AE=E3=80=80NotBlank=E3=81=A8NotNull=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 23 +++++++- .../com/example/todoapp/model/Recipes.java | 4 +- .../com/example/todoapp/model/Stocks.java | 6 +- .../com/example/todoapp/model/Stuffs.java | 8 +-- .../com/example/todoapp/model/ToBuys.java | 14 ++--- .../todoapp/repository/StuffsRepository.java | 19 ++++++- .../todoapp/repository/ToBuysRepository.java | 14 +++++ .../todoapp/service/ToBuysService.java | 57 ++++++++++++++----- 8 files changed, 111 insertions(+), 34 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index fbb0603..ceb10df 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -1,3 +1,10 @@ +//-------------------------------- +// ToBuysController.java +// +// 更新履歴:2025/06/05 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + package com.example.todoapp.controller; import com.example.todoapp.dto.ToBuyDTO; @@ -7,13 +14,27 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +/** + * 購入リストに関するRESTコントローラー + *

+ * このコントローラーは、購入リスト (to_buys) へのアイテム追加機能を提供します。 + * リクエストボディには ToBuyDTO 形式のデータが期待されます。 + *

+ */ @RestController -@RequestMapping("/api/tobuy/add") +@RequestMapping("/tobuy/add") public class ToBuysController { @Autowired private ToBuysService toBuysService; + /** + * 新しい購入アイテムを追加する + * + * @param dto 追加する購入アイテムのデータ(DTO) + * @return 成功時のレスポンスメッセージ + */ + @PostMapping public ResponseEntity addToBuys(@Valid @RequestBody ToBuyDTO dto) { toBuysService.addToBuys(dto); 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 76de887..98d3936 100644 --- a/backend/src/main/java/com/example/todoapp/model/Recipes.java +++ b/backend/src/main/java/com/example/todoapp/model/Recipes.java @@ -15,7 +15,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @@ -40,7 +40,7 @@ public class Recipes { /** * カテゴリ名 */ - @NotBlank + @NotNull @Column(unique = true, length = 255, nullable = false) private String recipie_name; 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 660ab87..d9f3f42 100644 --- a/backend/src/main/java/com/example/todoapp/model/Stocks.java +++ b/backend/src/main/java/com/example/todoapp/model/Stocks.java @@ -20,7 +20,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @@ -45,7 +45,7 @@ public class Stocks { /** * 商品テーブル参照用の外部キー */ - @NotBlank + @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn( name = "stuff_id", @@ -58,7 +58,7 @@ public class Stocks { /** * ユーザーテーブル参照用の外部キー */ - @NotBlank + @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn( name = "user_id", diff --git a/backend/src/main/java/com/example/todoapp/model/Stuffs.java b/backend/src/main/java/com/example/todoapp/model/Stuffs.java index b0e7939..55fe1f9 100644 --- a/backend/src/main/java/com/example/todoapp/model/Stuffs.java +++ b/backend/src/main/java/com/example/todoapp/model/Stuffs.java @@ -15,7 +15,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @@ -35,12 +35,12 @@ import lombok.NoArgsConstructor; */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private int stuff_id ; + private Long stuff_id ; /** * カテゴリ名 */ - @NotBlank + @NotNull @Column(unique = true, length = 255, nullable = false) private String stuff_name; @@ -53,7 +53,7 @@ import lombok.NoArgsConstructor; /** * カテゴリ */ - @NotBlank + @NotNull @Column(nullable = false, length = 225) private String category = "その他" ; } \ No newline at end of file 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 25bb797..0670392 100644 --- a/backend/src/main/java/com/example/todoapp/model/ToBuys.java +++ b/backend/src/main/java/com/example/todoapp/model/ToBuys.java @@ -1,7 +1,6 @@ //-------------------------------- // ToBuys.java // -// 分類:社員管理システムV2・ビジネスロジック層 // // 更新履歴:2025/06/03 新規作成 // Copyright(c) 2025 IVIS All rights reserved. @@ -18,7 +17,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @@ -42,7 +41,7 @@ public class ToBuys { /** * 材料の一意識別子 FK */ - @NotBlank + @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn( name = "stuff_id", @@ -54,26 +53,25 @@ public class ToBuys { /** * ユーザーテーブル参照用の外部キー */ - @NotBlank + // @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn( name = "user_id", - referencedColumnName = "id", - nullable = false + referencedColumnName = "id" ) private User user_id; /** * 購入する数量 */ - @NotBlank + @NotNull @Column(nullable = false) private int amount = 1; /** * 購入するお店 */ - @NotBlank + @NotNull @Column(nullable = false) private String store; diff --git a/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java b/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java index 3c29f31..1e2fa69 100644 --- a/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java @@ -1,12 +1,25 @@ +//-------------------------------- +// StuffsRepository.java +// +// +// 更新履歴:2025/06/05 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + package com.example.todoapp.repository; import com.example.todoapp.model.Stuffs; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.Optional; - +/** + * 材料 (stuffs) テーブルへのアクセスを行うリポジトリ. + *

+ * このクラスは材料テーブル (stuffs) に対する基本的なCRUD操作を提供します。 + * Spring Data JPAによって自動的に実装されます。 + *

+ */ @Repository public interface StuffsRepository extends JpaRepository { - Optional findById(Long id); + // 材料情報を主キーで取得するメソッド(必要に応じて追加) } \ No newline at end of file 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 ff6469f..368aef8 100644 --- a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java @@ -1,9 +1,23 @@ +//-------------------------------- +// ToBuysRepository.java +// +// +// 更新履歴:2025/06/05 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- package com.example.todoapp.repository; import com.example.todoapp.model.ToBuys; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +/** + * to_buys テーブルへのアクセスを行うリポジトリ + *

+ * このクラスは to_buys テーブルに対する基本的なCRUD操作を提供します。 + * Spring Data JPAによって自動的に実装されます。 + *

+ */ @Repository public interface ToBuysRepository extends JpaRepository { } \ No newline at end of file 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 2a44acb..475879f 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -1,3 +1,11 @@ +//-------------------------------- +// ToBuysService.java +// +// +// 更新履歴:2025/06/05 新規作成 +// Copyright(c) 2025 IVIS All rights reserved. +//-------------------------------------------- + package com.example.todoapp.service; import com.example.todoapp.dto.ToBuyDTO; @@ -12,6 +20,14 @@ import org.springframework.stereotype.Service; import java.util.Optional; +/** + * 購入リストのサービスクラス + *

+ * このクラスは、購入リスト (to_buys) の登録処理を提供します。 + * 材料 (stuffs) の存在確認と新規作成、ユーザー情報の取得などを行います。 + *

+ */ + @Service public class ToBuysService { @@ -24,27 +40,42 @@ public class ToBuysService { @Autowired private StuffsRepository stuffsRepository; + + /** + * 購入リストに新しいアイテムを追加する + * + * @param toBuyDTO 追加する購入アイテムのデータ(DTO) + */ public void addToBuys(ToBuyDTO toBuyDTO) { - //get user - Optional user = userRepository.findById(toBuyDTO.getUserId()); - if (!user.isPresent()) { - throw new RuntimeException("no: " + toBuyDTO.getUserId()); - } + // ユーザー情報を取得 + User user = userRepository.findById(toBuyDTO.getUser_id()) + .orElseThrow(() -> new RuntimeException("用户不存在: " + toBuyDTO.getUser_id())); - //get stuffs - Optional stuffs = stuffsRepository.findById(toBuyDTO.getStuffsId()); - if (!stuffs.isPresent()) { - throw new RuntimeException("材料不存在"); + Stuffs stuffs; + if (toBuyDTO.getStuff_id() == null) { + // 新しい材料を作成 + stuffs = new Stuffs(); + stuffs.setStuff_name(toBuyDTO.getStuff_name()); + stuffs.setCategory(toBuyDTO.getCategory()); + stuffs = stuffsRepository.save(stuffs); + } else { + // 材料情報を取得 + Optional optionalStuffs = stuffsRepository.findById(toBuyDTO.getStuff_id()); + if (!optionalStuffs.isPresent()) { + throw new RuntimeException("材料不存在"); + } + stuffs = optionalStuffs.get(); } ToBuys toBuys = new ToBuys(); - toBuys.setUser_id(user.get()); - toBuys.setStuffs(stuffs.get()); + System.out.println("AAAAuser_id: " + toBuyDTO.getUser_id()); + toBuys.setUser_id(user); + toBuys.setStuffs(stuffs); toBuys.setAmount(toBuyDTO.getAmount()); - toBuys.setStore(toBuyDTO.getStore()); + toBuys.setStore(toBuyDTO.getShop()); - // 保存到数据库 + // データベースに保存 toBuysRepository.save(toBuys); } From 13cefbc829fd0c630d31f026a752d0ab0c7d6717 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Thu, 5 Jun 2025 09:53:26 +0900 Subject: [PATCH 06/23] =?UTF-8?q?=E6=96=99=E7=90=86=E5=90=8D=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD(?= =?UTF-8?q?=E4=BA=88=E5=AE=9A)=E3=81=AE=E5=AE=9F=E8=A3=85=E3=80=81?= =?UTF-8?q?=E3=81=9D=E3=82=8C=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B=E3=83=AB?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=81=A8=E3=83=AC=E3=82=A4=E3=82=A2=E3=82=A6?= =?UTF-8?q?=E3=83=88=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 20 ++++++++ frontend/src/components/Layout.tsx | 9 ++++ frontend/src/pages/AddDishes1.tsx | 81 ++++++++++++++++++++++++++++++ frontend/src/pages/AddDishes2.tsx | 16 ++++++ 4 files changed, 126 insertions(+) create mode 100644 frontend/src/pages/AddDishes1.tsx create mode 100644 frontend/src/pages/AddDishes2.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7141e87..1d803fa 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -10,6 +10,9 @@ import LoginPage from './pages/LoginPage'; import RegisterPage from './pages/RegisterPage'; import TaskListPage from './pages/TaskListPage'; import './App.css'; +// 必要なインポートを追加 +import AddDishes1 from './pages/AddDishes1'; +import AddDishes2 from './pages/AddDishes2'; /** * アプリケーション全体のMaterial UIテーマを定義 @@ -92,6 +95,23 @@ const App: React.FC = () => { } /> + {/* テストページへのルートを追加 */} + + + + } + /> + + + + } + /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index e8696a9..6854702 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -21,6 +21,7 @@ import { import { Menu as MenuIcon, ListAlt as ListAltIcon, + Science as ScienceIcon, // テストページ用のアイコン } from '@mui/icons-material'; import { useNavigate, Outlet, useLocation } from 'react-router-dom'; @@ -98,6 +99,14 @@ const Layout: React.FC = () => { + {/* テストページへのリンクを追加 */} + handleNavigate('/add1')} + selected={isSelected('/add1')} + > + + + diff --git a/frontend/src/pages/AddDishes1.tsx b/frontend/src/pages/AddDishes1.tsx new file mode 100644 index 0000000..6cee3ab --- /dev/null +++ b/frontend/src/pages/AddDishes1.tsx @@ -0,0 +1,81 @@ +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { + AppBar, + Toolbar, + Typography, + Container, + Box, + Button, + Drawer, + List, + ListItemText, + ListItemIcon, + ListItemButton, + Divider, + IconButton, + TextField, + Paper, + Alert, + Link, + Grid, + } from '@mui/material'; + import { LoginCredentials } from '../types/types'; +import { authApi } from '../services/api'; +import { GENERAL_ERRORS } from '../constants/errorMessages'; + +const AddDishes1: React.FC = () => { + const navigate = useNavigate(); + const [dish, setDish] = useState(""); + // エラーメッセージの状態管理 + const [error, setError] = useState(false); + + const handleChange = (event: React.ChangeEvent) => { + setDish(event.target.value); + }; + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); // フォームのデフォルト送信動作を防止 + if (!dish.trim()) { + setError(true); + } else { + alert("送信成功!"); + navigate('/add2'); // タスク一覧ページにリダイレクト + } + }; + + return ( +
+ + 料理の追加・編集 + + +
+ +
+
+ +
+
+
+ ); +}; + +export default AddDishes1; \ No newline at end of file diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx new file mode 100644 index 0000000..ed12aa4 --- /dev/null +++ b/frontend/src/pages/AddDishes2.tsx @@ -0,0 +1,16 @@ +/** + * テストページコンポーネント + * 白紙の状態で表示されるテスト用のページ + */ +import React from 'react'; +import { Box } from '@mui/material'; + +const AddDishes2: React.FC = () => { + return ( + + {/* 白紙のページ - 何も表示しない */} + + ); +}; + +export default AddDishes2; \ No newline at end of file From e57d01de15bd57e75df461b6014061a1b7ee0fac Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 10:25:22 +0900 Subject: [PATCH 07/23] =?UTF-8?q?=E5=8F=96=E5=BE=97=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 44 +++++++++++++++++-- .../example/todoapp/dto/ToBuyResponse.java | 12 +++++ .../dto/{ToBuyDTO.java => ToBuysDTO.java} | 2 +- .../todoapp/repository/ToBuysRepository.java | 13 ++++++ .../todoapp/service/ToBuysService.java | 20 ++++++--- 5 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java rename backend/src/main/java/com/example/todoapp/dto/{ToBuyDTO.java => ToBuysDTO.java} (93%) diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index ceb10df..1efa39b 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -7,9 +7,17 @@ package com.example.todoapp.controller; -import com.example.todoapp.dto.ToBuyDTO; +import com.example.todoapp.dto.ToBuyResponse; +import com.example.todoapp.dto.ToBuysDTO; +import com.example.todoapp.model.ToBuys; import com.example.todoapp.service.ToBuysService; import jakarta.validation.Valid; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -22,7 +30,7 @@ import org.springframework.web.bind.annotation.*; *

*/ @RestController -@RequestMapping("/tobuy/add") +@RequestMapping("/tobuy") public class ToBuysController { @Autowired @@ -35,9 +43,37 @@ public class ToBuysController { * @return 成功時のレスポンスメッセージ */ - @PostMapping - public ResponseEntity addToBuys(@Valid @RequestBody ToBuyDTO dto) { + @PostMapping("/add") + public ResponseEntity addToBuys(@Valid @RequestBody ToBuysDTO dto) { toBuysService.addToBuys(dto); return ResponseEntity.ok("Item added to 'To Buys' successfully"); } + + /** + * 指定されたユーザーIDに基づいてすべての「買うもの」リストを取得する + * + * @param userId ユーザーID + * @return ユーザーに紐づく「買うもの」リスト + */ + @GetMapping("/get") + public ResponseEntity getAllToBuysByUserId(@RequestParam Long user_id) { + List toBuysList = toBuysService.getToBuysByUserId(user_id); + + // DTO形式に変換して返す + List responseList = toBuysList.stream() + .map(toBuy -> { + ToBuyResponse resp = new ToBuyResponse(); + resp.setTobuy_id(toBuy.getTobuy_id()); + resp.setStuff_id(toBuy.getStuffs().getStuff_id()); + resp.setAmount(toBuy.getAmount()); + resp.setShop(toBuy.getStore()); + return resp; + }) + .collect(Collectors.toList()); + + Map responseBody = new HashMap<>(); + responseBody.put("tobuy_array", responseList); + + return ResponseEntity.ok(responseList); + } } \ 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 new file mode 100644 index 0000000..2ffab6e --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java @@ -0,0 +1,12 @@ +// src/main/java/com/example/todoapp/dto/ToBuyResponse.java +package com.example.todoapp.dto; + +import lombok.Data; + +@Data +public class ToBuyResponse { + private int tobuy_id; + private Long stuff_id; + private int amount; + private String shop; +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java b/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java similarity index 93% rename from backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java rename to backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java index 6212f7d..90830fd 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java @@ -9,7 +9,7 @@ import lombok.Data; */ @Data - public class ToBuyDTO { + public class ToBuysDTO { private Long stuff_id; private Long user_id; 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 368aef8..49029ea 100644 --- a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java @@ -8,7 +8,11 @@ package com.example.todoapp.repository; import com.example.todoapp.model.ToBuys; + +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; /** @@ -20,4 +24,13 @@ import org.springframework.stereotype.Repository; */ @Repository public interface ToBuysRepository extends JpaRepository { + /** + * 指定されたユーザーIDに基づいて「買うもの」リストを取得する + * + * @param userId ユーザーID + * @return 「買うもの」リスト + */ + + @Query("SELECT t FROM ToBuys t WHERE t.user_id.id = ?1") + List findByUserId(Long user_id); } \ No newline at end of file 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 475879f..d1cd65c 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -8,7 +8,7 @@ package com.example.todoapp.service; -import com.example.todoapp.dto.ToBuyDTO; +import com.example.todoapp.dto.ToBuysDTO; import com.example.todoapp.model.Stuffs; import com.example.todoapp.model.ToBuys; import com.example.todoapp.model.User; @@ -18,6 +18,7 @@ import com.example.todoapp.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Optional; /** @@ -46,11 +47,11 @@ public class ToBuysService { * * @param toBuyDTO 追加する購入アイテムのデータ(DTO) */ - public void addToBuys(ToBuyDTO toBuyDTO) { + public void addToBuys(ToBuysDTO toBuyDTO) { // ユーザー情報を取得 User user = userRepository.findById(toBuyDTO.getUser_id()) - .orElseThrow(() -> new RuntimeException("用户不存在: " + toBuyDTO.getUser_id())); + .orElseThrow(() -> new RuntimeException("ユーザーがありませ: " + toBuyDTO.getUser_id())); Stuffs stuffs; if (toBuyDTO.getStuff_id() == null) { @@ -63,13 +64,12 @@ public class ToBuysService { // 材料情報を取得 Optional optionalStuffs = stuffsRepository.findById(toBuyDTO.getStuff_id()); if (!optionalStuffs.isPresent()) { - throw new RuntimeException("材料不存在"); + throw new RuntimeException("材料がありません"); } stuffs = optionalStuffs.get(); } ToBuys toBuys = new ToBuys(); - System.out.println("AAAAuser_id: " + toBuyDTO.getUser_id()); toBuys.setUser_id(user); toBuys.setStuffs(stuffs); toBuys.setAmount(toBuyDTO.getAmount()); @@ -79,4 +79,14 @@ public class ToBuysService { toBuysRepository.save(toBuys); } + + /** + * 指定されたユーザーIDに基づいてすべての「買うもの」リストを取得する + * + * @param userId ユーザーID + * @return ユーザーに紐づく「買うもの」リスト + */ + public List getToBuysByUserId(Long userId) { + return toBuysRepository.findByUserId(userId); + } } \ No newline at end of file From 2e2214c90837615005ab5429808871eeb3d9cdc9 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 10:52:08 +0900 Subject: [PATCH 08/23] =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 22 +++++++++++++++++++ .../todoapp/dto/DeleteToBuyRequest.java | 9 ++++++++ .../example/todoapp/dto/ToBuyResponse.java | 1 - .../todoapp/repository/ToBuysRepository.java | 15 ++++++++++++- .../todoapp/service/ToBuysService.java | 14 ++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index 1efa39b..7398b01 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -7,6 +7,7 @@ package com.example.todoapp.controller; +import com.example.todoapp.dto.DeleteToBuyRequest; import com.example.todoapp.dto.ToBuyResponse; import com.example.todoapp.dto.ToBuysDTO; import com.example.todoapp.model.ToBuys; @@ -76,4 +77,25 @@ public class ToBuysController { return ResponseEntity.ok(responseList); } + + /** + * ユーザーが指定したIDの「買うもの」を削除する + * + * @param request 削除する「買うもの」の情報を含むリクエストボディ + * @return 削除が成功した場合にtrueを含むレスポンス + */ + @DeleteMapping("/delete") + public ResponseEntity> deleteToBuy(@RequestBody DeleteToBuyRequest request) { + int deletedCount = toBuysService.deleteToBuyByIds(request.getUser_id(), request.getTobuy_id()); + + Map response = new HashMap<>(); + + if (deletedCount > 0) { + response.put("result", true); + } else { + response.put("result", false); + } + + return ResponseEntity.ok(response); + } } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java new file mode 100644 index 0000000..b19c196 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java @@ -0,0 +1,9 @@ +package com.example.todoapp.dto; + +import lombok.Data; + +@Data +public class DeleteToBuyRequest { + private Long user_id; + private int tobuy_id; +} \ 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 2ffab6e..03809dc 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java @@ -1,4 +1,3 @@ -// src/main/java/com/example/todoapp/dto/ToBuyResponse.java package com.example.todoapp.dto; import lombok.Data; 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 49029ea..57cd2cb 100644 --- a/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java @@ -12,7 +12,9 @@ import com.example.todoapp.model.ToBuys; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; /** @@ -24,13 +26,24 @@ import org.springframework.stereotype.Repository; */ @Repository public interface ToBuysRepository extends JpaRepository { + /** * 指定されたユーザーIDに基づいて「買うもの」リストを取得する * * @param userId ユーザーID * @return 「買うもの」リスト */ - @Query("SELECT t FROM ToBuys t WHERE t.user_id.id = ?1") List findByUserId(Long user_id); + + /** + * 指定されたユーザーIDに基づいて「買うもの」リストを取得する + * + * @param userId ユーザーID + * @param tobuyId 「買うもの」ID + * @return + */ + @Modifying + @Query("DELETE FROM ToBuys t WHERE t.user_id.id = :userId AND t.tobuy_id = :tobuyId") + int deleteByUserIdAndTobuyId(@Param("userId") Long userId, @Param("tobuyId") int tobuyId); } \ No newline at end of file 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 d1cd65c..589137c 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -15,6 +15,9 @@ import com.example.todoapp.model.User; import com.example.todoapp.repository.StuffsRepository; import com.example.todoapp.repository.ToBuysRepository; import com.example.todoapp.repository.UserRepository; + +import jakarta.transaction.Transactional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -89,4 +92,15 @@ public class ToBuysService { public List getToBuysByUserId(Long userId) { return toBuysRepository.findByUserId(userId); } + + /** + * 指定されたユーザーIDと購入リストIDに基づいて「買うもの」を削除する + * + * @param userId ユーザーID + * @param tobuyId 購入リストID + */ + @Transactional + public int deleteToBuyByIds(Long userId, int tobuyId) { + return toBuysRepository.deleteByUserIdAndTobuyId(userId, tobuyId); + } } \ No newline at end of file From 7e9759b3769c0a7ccef78ae1d27264800480be24 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Thu, 5 Jun 2025 10:58:00 +0900 Subject: [PATCH 09/23] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E9=81=B7?= =?UTF-8?q?=E7=A7=BB=E6=99=82=E3=81=AB=E5=85=A5=E5=8A=9B=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=9F=E6=96=99=E7=90=86=E5=90=8D=E3=82=92=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddDishes1.tsx | 5 +++-- frontend/src/pages/AddDishes2.tsx | 30 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/AddDishes1.tsx b/frontend/src/pages/AddDishes1.tsx index 6cee3ab..3175670 100644 --- a/frontend/src/pages/AddDishes1.tsx +++ b/frontend/src/pages/AddDishes1.tsx @@ -39,7 +39,8 @@ const AddDishes1: React.FC = () => { setError(true); } else { alert("送信成功!"); - navigate('/add2'); // タスク一覧ページにリダイレクト + localStorage.setItem("dishName", dish); + navigate('/add2', { state: dish }); // タスク一覧ページにリダイレクト } }; @@ -59,7 +60,7 @@ const AddDishes1: React.FC = () => { InputLabelProps={{ style: { fontSize: "40px" }}} style={{width: "80%" }} InputProps={{ style: { fontSize: "40px"} }} - // name="username" + name="dish_name" // autoComplete="username" autoFocus value={dish} diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx index ed12aa4..394b76b 100644 --- a/frontend/src/pages/AddDishes2.tsx +++ b/frontend/src/pages/AddDishes2.tsx @@ -3,13 +3,35 @@ * 白紙の状態で表示されるテスト用のページ */ import React from 'react'; -import { Box } from '@mui/material'; +import { useLocation } from "react-router-dom"; +import { + AppBar, + Toolbar, + Typography, + Container, + Box, + Button, + Drawer, + List, + ListItemText, + ListItemIcon, + ListItemButton, + Divider, + IconButton, + TextField, + Paper, + Alert, + Link, + Grid, +} from '@mui/material'; const AddDishes2: React.FC = () => { + const receivedData = localStorage.getItem("dishName"); return ( - - {/* 白紙のページ - 何も表示しない */} - +
+

追加する料理名

+

{receivedData}

+
); }; From ddec6a2e23b061523e9021a8ab87509a1a9d9c1e Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 11:47:59 +0900 Subject: [PATCH 10/23] =?UTF-8?q?1.=20Long=20user=5Fid=20=E2=86=92=20Authe?= =?UTF-8?q?ntication=20authentication=202.=20SecurityConfig=20=20.anyReque?= =?UTF-8?q?st().permitAll();=E7=84=A1=E5=8A=B9=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/todoapp/config/SecurityConfig.java | 7 +++++-- .../main/java/com/example/todoapp/dto/ToBuyResponse.java | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/config/SecurityConfig.java b/backend/src/main/java/com/example/todoapp/config/SecurityConfig.java index 0c91b4f..326888d 100644 --- a/backend/src/main/java/com/example/todoapp/config/SecurityConfig.java +++ b/backend/src/main/java/com/example/todoapp/config/SecurityConfig.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -49,8 +50,10 @@ public class SecurityConfig { .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeHttpRequests() - .requestMatchers("/auth/**").permitAll() // 認証エンドポイントは認証不要 - .anyRequest().authenticated(); // その他のエンドポイントは認証必要 + // .requestMatchers("/auth/**").permitAll() // 認証エンドポイントは認証不要 + // .anyRequest().authenticated() + .anyRequest().permitAll(); + ; // その他のエンドポイントは認証必要 // JWTフィルターを認証フィルターの前に追加 http.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); 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 03809dc..bf5730b 100644 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java @@ -6,6 +6,7 @@ import lombok.Data; public class ToBuyResponse { private int tobuy_id; private Long stuff_id; + private String stuff_name; private int amount; private String shop; } \ No newline at end of file From 7d173a03dc36df47ebe27986d7d9f0eb85d4e444 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 11:51:04 +0900 Subject: [PATCH 11/23] =?UTF-8?q?stuff=5Fname=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index 7398b01..b984698 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -11,6 +11,8 @@ import com.example.todoapp.dto.DeleteToBuyRequest; import com.example.todoapp.dto.ToBuyResponse; import com.example.todoapp.dto.ToBuysDTO; import com.example.todoapp.model.ToBuys; +import com.example.todoapp.model.User; +import com.example.todoapp.repository.UserRepository; import com.example.todoapp.service.ToBuysService; import jakarta.validation.Valid; @@ -21,6 +23,8 @@ import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.web.bind.annotation.*; /** @@ -37,6 +41,9 @@ public class ToBuysController { @Autowired private ToBuysService toBuysService; + @Autowired + private UserRepository userRepository; + /** * 新しい購入アイテムを追加する * @@ -57,8 +64,17 @@ public class ToBuysController { * @return ユーザーに紐づく「買うもの」リスト */ @GetMapping("/get") - public ResponseEntity getAllToBuysByUserId(@RequestParam Long user_id) { - List toBuysList = toBuysService.getToBuysByUserId(user_id); + public ResponseEntity getAllToBuysByUserId(Authentication authentication) { + + + // 認証されたユーザー名を取得 + String username = authentication.getName(); + + // ユーザー情報を取得(例: userRepository経由) + User user = userRepository.findByUsername(username) + .orElseThrow(() -> new UsernameNotFoundException("User not found")); + + List toBuysList = toBuysService.getToBuysByUserId(user.getId()); // DTO形式に変換して返す List responseList = toBuysList.stream() @@ -66,6 +82,7 @@ public class ToBuysController { ToBuyResponse resp = new ToBuyResponse(); resp.setTobuy_id(toBuy.getTobuy_id()); resp.setStuff_id(toBuy.getStuffs().getStuff_id()); + resp.setStuff_name(toBuy.getStuffs().getStuff_name()); resp.setAmount(toBuy.getAmount()); resp.setShop(toBuy.getStore()); return resp; @@ -90,6 +107,7 @@ public class ToBuysController { Map response = new HashMap<>(); + if (deletedCount > 0) { response.put("result", true); } else { From 88d927c3fe64c8c77dc9c493faaa9a78f9e02299 Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 13:08:50 +0900 Subject: [PATCH 12/23] =?UTF-8?q?(add,=20delete)=20Long=20user=5Fid=20?= =?UTF-8?q?=E2=86=92=20Authentication=20authentication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 23 ++++++++++++++----- .../todoapp/service/ToBuysService.java | 8 ++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index b984698..bce8a33 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -52,8 +52,10 @@ public class ToBuysController { */ @PostMapping("/add") - public ResponseEntity addToBuys(@Valid @RequestBody ToBuysDTO dto) { - toBuysService.addToBuys(dto); + public ResponseEntity addToBuys( + @Valid @RequestBody ToBuysDTO dto, + Authentication authentication) { + toBuysService.addToBuys(dto, authentication); return ResponseEntity.ok("Item added to 'To Buys' successfully"); } @@ -66,11 +68,10 @@ public class ToBuysController { @GetMapping("/get") public ResponseEntity getAllToBuysByUserId(Authentication authentication) { - // 認証されたユーザー名を取得 String username = authentication.getName(); - // ユーザー情報を取得(例: userRepository経由) + // ユーザー情報を取得 User user = userRepository.findByUsername(username) .orElseThrow(() -> new UsernameNotFoundException("User not found")); @@ -102,8 +103,18 @@ public class ToBuysController { * @return 削除が成功した場合にtrueを含むレスポンス */ @DeleteMapping("/delete") - public ResponseEntity> deleteToBuy(@RequestBody DeleteToBuyRequest request) { - int deletedCount = toBuysService.deleteToBuyByIds(request.getUser_id(), request.getTobuy_id()); + public ResponseEntity> deleteToBuy( + @RequestBody DeleteToBuyRequest request, + Authentication authentication) { + + // 認証されたユーザー名を取得 + String username = authentication.getName(); + + // ユーザー情報を取得 + User user = userRepository.findByUsername(username) + .orElseThrow(() -> new UsernameNotFoundException("User not found")); + + int deletedCount = toBuysService.deleteToBuyByIds(user.getId(), request.getTobuy_id()); Map response = new HashMap<>(); 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 589137c..8049ee9 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -18,6 +18,7 @@ import com.example.todoapp.repository.UserRepository; import jakarta.transaction.Transactional; +import org.springframework.security.core.Authentication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -50,11 +51,12 @@ public class ToBuysService { * * @param toBuyDTO 追加する購入アイテムのデータ(DTO) */ - public void addToBuys(ToBuysDTO toBuyDTO) { + public void addToBuys(ToBuysDTO toBuyDTO, Authentication authentication) { // ユーザー情報を取得 - User user = userRepository.findById(toBuyDTO.getUser_id()) - .orElseThrow(() -> new RuntimeException("ユーザーがありませ: " + toBuyDTO.getUser_id())); + String username = authentication.getName(); + User user = userRepository.findByUsername(username) + .orElseThrow(() -> new RuntimeException("ユーザーが見つかりません: " + username)); Stuffs stuffs; if (toBuyDTO.getStuff_id() == null) { From 036fbfa09aa6bbc3211d12194e1e2ca2946cecfd Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 13:43:32 +0900 Subject: [PATCH 13/23] =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todoapp/controller/ToBuysController.java | 10 ++++ .../todoapp/service/ToBuysService.java | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index bce8a33..7b81ea3 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -59,6 +59,16 @@ public class ToBuysController { return ResponseEntity.ok("Item added to 'To Buys' successfully"); } + @PutMapping("/update") + public ResponseEntity updateToBuys( + @Valid @RequestBody ToBuysDTO dto, + Authentication authentication) { + toBuysService.updateToBuys(dto, authentication); + return ResponseEntity.ok("Item updated to 'To Buys' successfully"); + } + + + /** * 指定されたユーザー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 8049ee9..68b6da8 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -85,6 +85,54 @@ public class ToBuysService { } + /** + * 購入リストに新しいアイテムを追加する + * + * @param toBuyDTO 追加する購入アイテムのデータ(DTO) + */ + public void updateToBuys(ToBuysDTO toBuyDTO, Authentication authentication) { + + // ユーザー情報を取得 + String username = authentication.getName(); + User user = userRepository.findByUsername(username) + .orElseThrow(() -> new RuntimeException("ユーザーが見つかりません: " + username)); + + Stuffs stuffs; + if (toBuyDTO.getStuff_id() == null) { + // 新しい材料を作成 + stuffs = new Stuffs(); + stuffs.setStuff_name(toBuyDTO.getStuff_name()); + stuffs.setCategory(toBuyDTO.getCategory()); + stuffs = stuffsRepository.save(stuffs); + } else { + // 材料情報を取得 + Optional optionalStuffs = stuffsRepository.findById(toBuyDTO.getStuff_id()); + if (!optionalStuffs.isPresent()) { + throw new RuntimeException("材料がありません"); + } + stuffs = optionalStuffs.get(); + + //update + // stuffs.setStuff_name(toBuyDTO.getStuff_name()); + // stuffs.setCategory(toBuyDTO.getCategory()); + stuffs = stuffsRepository.save(stuffs); + } + + + + ToBuys toBuys = new ToBuys(); + toBuys.setUser_id(user); + toBuys.setStuffs(stuffs); + toBuys.setAmount(toBuyDTO.getAmount()); + toBuys.setStore(toBuyDTO.getShop()); + + // データベースに保存 + toBuysRepository.save(toBuys); + + } + + + /** * 指定されたユーザーIDに基づいてすべての「買うもの」リストを取得する * From b1f8a53a31bfaff8bbd5faae6ff66296197bf5dd Mon Sep 17 00:00:00 2001 From: "zhang.pengcheng" Date: Thu, 5 Jun 2025 13:45:32 +0900 Subject: [PATCH 14/23] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/todoapp/service/ToBuysService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 68b6da8..3fcaee2 100644 --- a/backend/src/main/java/com/example/todoapp/service/ToBuysService.java +++ b/backend/src/main/java/com/example/todoapp/service/ToBuysService.java @@ -86,9 +86,9 @@ public class ToBuysService { } /** - * 購入リストに新しいアイテムを追加する + * 購入リストに新しいアイテムを変更する * - * @param toBuyDTO 追加する購入アイテムのデータ(DTO) + * @param toBuyDTO 変更する購入アイテムのデータ(DTO) */ public void updateToBuys(ToBuysDTO toBuyDTO, Authentication authentication) { @@ -131,8 +131,6 @@ public class ToBuysService { } - - /** * 指定されたユーザーIDに基づいてすべての「買うもの」リストを取得する * From f48014da093af3b59e1f08592ab07c73fef240da Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Fri, 6 Jun 2025 09:30:30 +0900 Subject: [PATCH 15/23] =?UTF-8?q?=E8=B2=B7=E3=81=86=E3=82=82=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=EF=BC=88=E6=9D=90=E6=96=99=E6=96=B0?= =?UTF-8?q?=E8=A6=8F=E8=BF=BD=E5=8A=A0=EF=BC=89=E3=81=AE=E5=8B=95=E4=BD=9C?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/constants/errorMessages.ts | 8 ++ frontend/src/pages/TaskListPage.tsx | 2 +- frontend/src/services/api.ts | 106 ++++++++++++------------ 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/frontend/src/constants/errorMessages.ts b/frontend/src/constants/errorMessages.ts index 3e7179d..909bbfa 100644 --- a/frontend/src/constants/errorMessages.ts +++ b/frontend/src/constants/errorMessages.ts @@ -21,3 +21,11 @@ export const TASK_ERRORS = { UPDATE_FAILED: 'タスクの更新に失敗しました', DELETE_FAILED: 'タスクの削除に失敗しました', }; + +// 買うものリスト関連のエラーメッセージ +export const TOBUY_ERRORS = { + FETCH_FAILED: '買うものリストの取得に失敗しました', + CREATE_FAILED: '買うものリストの作成に失敗しました', + UPDATE_FAILED: '買うものリストの更新に失敗しました', + DELETE_FAILED: '買うものリストの削除に失敗しました', +}; diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 975f836..5ec6c38 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -146,7 +146,7 @@ const TaskListPage: React.FC = () => {
{/* タスク一覧をマップして各タスクをリストアイテムとして表示 */} - {tobuys.map((tobuy) => ( + {tobuys && tobuys.map((tobuy) => ( => { - // const response = await fetch(`${API_BASE_URL}/api/tobuy/get`, { - // headers: getHeaders(), // 認証トークンを含むヘッダー - // }); - - // if (!response.ok) { - // throw new Error(TASK_ERRORS.FETCH_FAILED); - // } - - // return response.json(); + const response = await fetch(`${API_BASE_URL}/api/tobuy/get`, { + headers: getHeaders(), // 認証トークンを含むヘッダー + }); - return { - "tobuy_array": [ - { - "tobuy_id": 1, - "stuff_id": 2, - "stuff_name": "じゃがいも", - "amount": 3, - "shop": "shopXXX" - }, - { - "tobuy_id": 2, - "stuff_id": 5, - "stuff_name": "にんじん", - "amount": 1 - } - ] + if (!response.ok) { + throw new Error(TOBUY_ERRORS.FETCH_FAILED); } + const tobuy_array = await response.json(); + return {tobuy_array}; + + // return { + // "tobuy_array": [ + // { + // "tobuy_id": 1, + // "stuff_id": 2, + // "stuff_name": "じゃがいも", + // "amount": 3, + // "shop": "shopXXX" + // }, + // { + // "tobuy_id": 2, + // "stuff_id": 5, + // "stuff_name": "にんじん", + // "amount": 1 + // } + // ] + // } + }, /** @@ -129,24 +130,25 @@ export const toBuyApi = { * @returns 作成された材料情報 */ addToBuy: async (tobuy: Omit & { stuff_id: number | null, category: string }): Promise => { - // const response = await fetch(`${API_BASE_URL}/api/tasks`, { - // method: 'POST', - // headers: getHeaders(), - // body: JSON.stringify(tobuy), - // }); + const response = await fetch(`${API_BASE_URL}/api/tobuy/add`, { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(tobuy), + }); - // if (!response.ok) { - // throw new Error(TASK_ERRORS.CREATE_FAILED); - // } + if (!response.ok) { + throw new Error(TOBUY_ERRORS.CREATE_FAILED); + } // return response.json(); + return {result: true} - return { - "result": true, - "tobuy_id": 1, - "stuff_id": 6, - "message": "追加に成功しました", - } + // return { + // "result": true, + // "tobuy_id": 1, + // "stuff_id": 6, + // "message": "追加に成功しました", + // } }, @@ -155,19 +157,21 @@ export const toBuyApi = { * @param id 削除対象の買うものリストID */ deleteToBuy: async (tobuy_id: number): Promise<{ result: boolean }> => { - // const response = await fetch(`${API_BASE_URL}/api/tobuy/delete`, { - // method: 'DELETE', - // headers: getHeaders(), - // body: JSON.stringify({tobuy_id}), - // }); - - // if (!response.ok) { - // throw new Error(TASK_ERRORS.DELETE_FAILED); - // } + const response = await fetch(`${API_BASE_URL}/api/tobuy/delete`, { + method: 'DELETE', + headers: getHeaders(), + body: JSON.stringify({tobuy_id}), + }); - return { - "result": true + if (!response.ok) { + throw new Error(TOBUY_ERRORS.DELETE_FAILED); } + + return response.json() + + // return { + // "result": true + // } }, } From fbc186bcc017573508068257b2aaa2ef1d8962c4 Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Fri, 6 Jun 2025 09:43:36 +0900 Subject: [PATCH 16/23] =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=81=97=E3=81=9F?= =?UTF-8?q?=E6=96=99=E7=90=86=E3=81=AB=E5=BF=85=E8=A6=81=E3=81=AA=E6=9D=90?= =?UTF-8?q?=E6=96=99=E3=82=92=E5=85=A5=E5=8A=9B=E3=81=97=E3=80=81=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=83=9C=E3=82=BF=E3=83=B3=E3=82=92=E6=8A=BC=E3=81=99?= =?UTF-8?q?=E3=81=93=E3=81=A8=E3=81=A7=E7=94=BB=E9=9D=A2=E3=81=AB=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E5=86=85=E5=AE=B9=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddDishes1.tsx | 8 +- frontend/src/pages/AddDishes2.tsx | 257 +++++++++++++++++++++++++++--- 2 files changed, 241 insertions(+), 24 deletions(-) diff --git a/frontend/src/pages/AddDishes1.tsx b/frontend/src/pages/AddDishes1.tsx index 3175670..3d9f699 100644 --- a/frontend/src/pages/AddDishes1.tsx +++ b/frontend/src/pages/AddDishes1.tsx @@ -36,11 +36,12 @@ const AddDishes1: React.FC = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // フォームのデフォルト送信動作を防止 if (!dish.trim()) { + alert("エラー"); setError(true); } else { alert("送信成功!"); - localStorage.setItem("dishName", dish); - navigate('/add2', { state: dish }); // タスク一覧ページにリダイレクト + localStorage.setItem("dishName", dish); // ローカルストレージにフォームに入力された料理名を保存 + navigate('/add2', { state: dish }); // 料理名から材料名追加ページにリダイレクト } }; @@ -55,7 +56,6 @@ const AddDishes1: React.FC = () => { required // id="username" label="追加・編集したい料理名を入力" - placeholder='ここに料理名を入力' variant="outlined" InputLabelProps={{ style: { fontSize: "40px" }}} style={{width: "80%" }} @@ -71,7 +71,7 @@ const AddDishes1: React.FC = () => {
diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx index 394b76b..1885317 100644 --- a/frontend/src/pages/AddDishes2.tsx +++ b/frontend/src/pages/AddDishes2.tsx @@ -2,36 +2,253 @@ * テストページコンポーネント * 白紙の状態で表示されるテスト用のページ */ -import React from 'react'; -import { useLocation } from "react-router-dom"; +import React, { useState, useEffect } from 'react'; +import { taskApi } from '../services/api'; import { - AppBar, - Toolbar, - Typography, - Container, - Box, - Button, - Drawer, + Container, + Typography, + Tooltip, List, + ListItem, ListItemText, - ListItemIcon, - ListItemButton, - Divider, + ListItemSecondaryAction, IconButton, + Checkbox, + Fab, + Dialog, + DialogTitle, + DialogContent, + DialogActions, TextField, - Paper, - Alert, - Link, - Grid, + Button, + Box, + MenuItem, + Select, + FormControl, + InputLabel } from '@mui/material'; +import { + Add as AddIcon, Delete as DeleteIcon, ShoppingBasket as ShoppingBasketIcon, + SoupKitchen as SoupKitchenIcon +} from '@mui/icons-material'; +import { Task } from '../types/types'; +import { TASK_ERRORS } from '../constants/errorMessages'; +import { GENERAL_ERRORS } from '../constants/errorMessages'; +import CategoryDropDown from "../components/CategoryDropDown"; + +// 新規タスクの初期状態 +const EMPTY_TASK = { title: '', amount: 0, completed: false }; + +interface Empty_Task { + title: string; // 食材名 + amount: number; // 食材の個数 + completed: boolean; // +} const AddDishes2: React.FC = () => { const receivedData = localStorage.getItem("dishName"); + // タスク一覧の状態管理 + const [tasks, setTasks] = useState([]); + const [addtasks, setAddTasks] = useState([]); + // エラーメッセージの状態管理 + const [error, setError] = useState(false); + // 新規タスク作成ダイアログの表示状態 + const [openDialog, setOpenDialog] = useState(false); + // 新規タスクの入力内容 + const [newTask, setNewTask] = useState(EMPTY_TASK); + + // const fetchTasks = async () => { + // try { + // const tasks = await taskApi.getTasks(); + // setTasks(tasks); + // } catch (error) { + // console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); + // } + // }; + + // コンポーネントマウント時にタスク一覧を取得 + // useEffect(() => { + // fetchTasks(); + // }, []); + /** + * タスクを削除するハンドラー + * 指定されたIDのタスクをAPIを通じて削除 + */ + const handleDeleteTask = async (index: number) => { + try { + let newAddTasks = [...addtasks]; // 配列をコピー + newAddTasks.splice(index, 1); + setAddTasks(newAddTasks); + // fetchTasks(); // 削除後のタスク一覧を再取得 + } catch (error) { + console.error(`${TASK_ERRORS.DELETE_FAILED}:`, error); + } + }; + + /** + * 新規タスクを作成するハンドラー + * 入力されたタスク情報をAPIに送信して新規作成 + * 作成後はダイアログを閉じ、入力内容をリセット + */ + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); // フォームのデフォルト送信動作を防止 + if (addtasks[0] == null) { + setError(true); + alert("食材を追加してください") + } else { + alert("送信成功!"); + // localStorage.setItem("dishName", dish); // ローカルストレージにフォームに入力された料理名を保存 + // navigate('/add2', { state: dish }); // 料理名から材料名追加ページにリダイレクト + } + }; + const handleCreateTask = async () => { + try { + // await taskApi.createTask(newTask); + let newAddTasks = [...addtasks]; // 配列をコピー + newAddTasks.push(newTask); + setAddTasks(newAddTasks); + setOpenDialog(false); // ダイアログを閉じる + setNewTask(EMPTY_TASK); // 入力内容をリセット + // fetchTasks(); // 作成後のタスク一覧を再取得 + } catch (error) { + console.error(`${TASK_ERRORS.CREATE_FAILED}:`, error); + } + }; return ( -
-

追加する料理名

-

{receivedData}

-
+ +
+

追加する料理名

+

{receivedData}

+
+ + {/* タスク一覧をマップして各タスクをリストアイテムとして表示 */} + {addtasks.map((task, index) => ( + + {/* タスク完了状態を切り替えるチェックボックス + handleToggleComplete(task.id)} + /> */} + {/* タスクのタイトルと説明 - 完了状態に応じて取り消し線を表示 */} + + {/* 食材の個数を表示 */} + 個数
+ {task.amount} + + } + // secondary={task.description} + primaryTypographyProps={{ align: "right", marginRight: "20%", fontSize: "20px" }} + /> + {/* 買い物リスト:食材情報記入ボタン */} + + + handleDeleteTask(task.id)} + > + + + + {/* 買い物リスト:食材削除ボタン */} + + + handleDeleteTask(index)} + > + + + + + +
+ ))} +
+
+ +
+
+ +
+ {/* 新規タスク作成ダイアログ */} + setOpenDialog(false)} disableScrollLock={true}> + 材料の追加 + + + {/*材料カテゴリ選択 */} + + {/* タスクタイトル入力フィールド */} + setNewTask({ ...newTask, title: e.target.value })} + sx={{ marginBottom: 2 }} + /> + {/* 数量入力フィールド */} + { + const value = e.target.value; + const parsedValue = parseInt(value, 10); // 数値に変換 + if (!isNaN(parsedValue)) { + setNewTask({ ...newTask, amount: parsedValue }); // number型で保存 + } + }} + sx={{ width: "20%" }} + type="number" + inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} // ここで整数のみ許可 + /> + + + + + + + +
); }; From 3f208a86bb630cca4bef398068eab26333b14c1f Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Fri, 6 Jun 2025 10:12:29 +0900 Subject: [PATCH 17/23] =?UTF-8?q?=E6=97=A2=E5=AD=98=E3=81=AE=E9=A3=9F?= =?UTF-8?q?=E6=9D=90=E8=BF=BD=E5=8A=A0=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/CategoryDropDown.tsx | 2 +- frontend/src/pages/StockPage.tsx | 1 - frontend/src/pages/TaskListPage.tsx | 4 +--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/CategoryDropDown.tsx b/frontend/src/components/CategoryDropDown.tsx index fce3e55..74ded65 100644 --- a/frontend/src/components/CategoryDropDown.tsx +++ b/frontend/src/components/CategoryDropDown.tsx @@ -16,7 +16,7 @@ const CategoryDropDown = () => { onChange={(event) => setSelectedValue(event.target.value)} > 乳製品 - 肉・魚 + 魚・肉 野菜 調味料 その他 diff --git a/frontend/src/pages/StockPage.tsx b/frontend/src/pages/StockPage.tsx index e305d3b..049ae97 100644 --- a/frontend/src/pages/StockPage.tsx +++ b/frontend/src/pages/StockPage.tsx @@ -19,7 +19,6 @@ import { } from '@mui/material'; import { TASK_ERRORS } from '../constants/errorMessages'; -import CategoryDropDown from "../components/CategoryDropDown"; const StockPage: React.FC = () => { diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 5ec6c38..4eccf04 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -36,8 +36,6 @@ import { import { Task, ToBuy, Stuff } from '../types/types'; import { TASK_ERRORS } from '../constants/errorMessages'; //import { FaCarrot } from "react-icons/fa6"; //エラー起きる いったん保留 -import CategoryDropDown from "../components/CategoryDropDown"; - @@ -258,7 +256,7 @@ const TaskListPage: React.FC = () => { onChange={(e) => onChangeCategory(e.target.value) } > 乳製品 - 肉・魚 + 魚・肉 野菜 調味料 その他 From 9af89cc6e5257df8ce8c9d9e5bc62268f0bfb528 Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Fri, 6 Jun 2025 10:42:20 +0900 Subject: [PATCH 18/23] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E6=99=82=E3=81=AB=E6=98=8E=E7=A4=BA=E7=9A=84=E3=81=ABnull?= =?UTF-8?q?=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/TaskListPage.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 4eccf04..fc90c73 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -126,6 +126,10 @@ const TaskListPage: React.FC = () => { */ const handleCreateTask = async () => { try { + if (newToBuy.newAddition) { + newToBuy.stuff_id = null; + } + console.log(newToBuy) await toBuyApi.addToBuy(newToBuy); setOpenDialog(false); // ダイアログを閉じる setNewToBuy(EMPTY_TASK); // 入力内容をリセット From b17537cb716fb70b73088d774169dd5d9adf0583 Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Fri, 6 Jun 2025 10:50:30 +0900 Subject: [PATCH 19/23] =?UTF-8?q?=E8=B3=BC=E5=85=A5=E3=83=9C=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=82=92=E6=8A=BC=E3=81=97=E3=81=A6=E3=82=82=E3=83=AA?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=8B=E3=82=89=E6=B6=88=E3=81=88=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/TaskListPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 76d8be7..11229ec 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -181,7 +181,7 @@ const TaskListPage: React.FC = () => { onClick={() => { setOpenInfoDialog(true) setSelectedTask(tobuy.tobuy_id) - handleDeleteTask(tobuy.tobuy_id) + // handleDeleteTask(tobuy.tobuy_id) }} > From 43d69e2f8e80364411e1ab74c9a08de1f942dced Mon Sep 17 00:00:00 2001 From: "masato.fujita" Date: Fri, 6 Jun 2025 10:51:01 +0900 Subject: [PATCH 20/23] =?UTF-8?q?=E6=96=99=E7=90=86=E3=81=AB=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E9=A3=9F=E6=9D=90=E3=82=92=E3=82=BF=E3=82=B9?= =?UTF-8?q?=E3=82=AF=E4=B8=80=E8=A6=A7=E3=81=AB=E8=A1=A8=E7=A4=BA=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddDishes1.tsx | 20 +++++------ frontend/src/pages/AddDishes2.tsx | 57 ++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/frontend/src/pages/AddDishes1.tsx b/frontend/src/pages/AddDishes1.tsx index 3d9f699..d003ebd 100644 --- a/frontend/src/pages/AddDishes1.tsx +++ b/frontend/src/pages/AddDishes1.tsx @@ -34,16 +34,16 @@ const AddDishes1: React.FC = () => { setDish(event.target.value); }; const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); // フォームのデフォルト送信動作を防止 - if (!dish.trim()) { - alert("エラー"); - setError(true); - } else { - alert("送信成功!"); - localStorage.setItem("dishName", dish); // ローカルストレージにフォームに入力された料理名を保存 - navigate('/add2', { state: dish }); // 料理名から材料名追加ページにリダイレクト - } - }; + e.preventDefault(); // フォームのデフォルト送信動作を防止 + if (!dish.trim()) { + alert("エラー"); + setError(true); + } else { + alert("送信成功!"); + localStorage.setItem("dishName", dish); // ローカルストレージにフォームに入力された料理名を保存 + navigate('/add2', { state: dish }); // 料理名から材料名追加ページにリダイレクト + } + }; return (
diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx index 1885317..2e319d9 100644 --- a/frontend/src/pages/AddDishes2.tsx +++ b/frontend/src/pages/AddDishes2.tsx @@ -36,8 +36,11 @@ import { TASK_ERRORS } from '../constants/errorMessages'; import { GENERAL_ERRORS } from '../constants/errorMessages'; import CategoryDropDown from "../components/CategoryDropDown"; -// 新規タスクの初期状態 -const EMPTY_TASK = { title: '', amount: 0, completed: false }; +// 新規タスクの初期状態(画面表示用) +const EMPTY_TASK = { id: 0, title: '', amount: 0, completed: false }; + +// 新規タスクの初期状態(データベース登録用) +const EMPTY_TASK_DATA_BASE = { id: 0, title: '', amount: 0, completed: false }; interface Empty_Task { title: string; // 食材名 @@ -49,6 +52,7 @@ const AddDishes2: React.FC = () => { const receivedData = localStorage.getItem("dishName"); // タスク一覧の状態管理 const [tasks, setTasks] = useState([]); + const [addtasks, setAddTasks] = useState([]); // エラーメッセージの状態管理 const [error, setError] = useState(false); @@ -57,19 +61,23 @@ const AddDishes2: React.FC = () => { // 新規タスクの入力内容 const [newTask, setNewTask] = useState(EMPTY_TASK); - // const fetchTasks = async () => { - // try { - // const tasks = await taskApi.getTasks(); - // setTasks(tasks); - // } catch (error) { - // console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); - // } - // }; - // コンポーネントマウント時にタスク一覧を取得 - // useEffect(() => { - // fetchTasks(); - // }, []); + useEffect(() => { + fetchTasks(); + }, []); + + /** + * APIからタスク一覧を取得する関数 + * 取得したタスクをstate(tasks)に設定 + */ + const fetchTasks = async () => { + try { + const tasks = await taskApi.getTasks(); + setTasks(tasks); + } catch (error) { + console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); + } + }; /** * タスクを削除するハンドラー * 指定されたIDのタスクをAPIを通じて削除 @@ -94,14 +102,15 @@ const AddDishes2: React.FC = () => { e.preventDefault(); // フォームのデフォルト送信動作を防止 if (addtasks[0] == null) { setError(true); - alert("食材を追加してください") + alert("食材を追加してください"); } else { alert("送信成功!"); + handleCreateTask_DataBase(); // localStorage.setItem("dishName", dish); // ローカルストレージにフォームに入力された料理名を保存 // navigate('/add2', { state: dish }); // 料理名から材料名追加ページにリダイレクト } }; - const handleCreateTask = async () => { + const handleCreateTask_Temp = async () => { try { // await taskApi.createTask(newTask); let newAddTasks = [...addtasks]; // 配列をコピー @@ -114,6 +123,20 @@ const AddDishes2: React.FC = () => { console.error(`${TASK_ERRORS.CREATE_FAILED}:`, error); } }; + + const handleCreateTask_DataBase = async () => { + try { + for (let i = 0; i < addtasks.length; i++) { + await taskApi.createTask(addtasks[i]); + } + setOpenDialog(false); // ダイアログを閉じる + setNewTask(EMPTY_TASK); // 入力内容をリセット + // fetchTasks(); // 作成後のタスク一覧を再取得 + } catch (error) { + console.error(`${TASK_ERRORS.CREATE_FAILED}:`, error); + } + }; + return (
@@ -243,7 +266,7 @@ const AddDishes2: React.FC = () => { - From 161028fb9b7ebaa3b9462ae4e41d602e85606917 Mon Sep 17 00:00:00 2001 From: "akito.nishiwaki" Date: Fri, 6 Jun 2025 10:57:19 +0900 Subject: [PATCH 21/23] =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E3=82=B3?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=A2=E3=82=A6=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddDishes2.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx index 2e319d9..19f8d51 100644 --- a/frontend/src/pages/AddDishes2.tsx +++ b/frontend/src/pages/AddDishes2.tsx @@ -126,12 +126,12 @@ const AddDishes2: React.FC = () => { const handleCreateTask_DataBase = async () => { try { - for (let i = 0; i < addtasks.length; i++) { - await taskApi.createTask(addtasks[i]); - } - setOpenDialog(false); // ダイアログを閉じる - setNewTask(EMPTY_TASK); // 入力内容をリセット - // fetchTasks(); // 作成後のタスク一覧を再取得 + // for (let i = 0; i < addtasks.length; i++) { + // await taskApi.createTask(addtasks[i]); + // } + // setOpenDialog(false); // ダイアログを閉じる + // setNewTask(EMPTY_TASK); // 入力内容をリセット + // // fetchTasks(); // 作成後のタスク一覧を再取得 } catch (error) { console.error(`${TASK_ERRORS.CREATE_FAILED}:`, error); } From aa2dfdfaf96651e1e265c644ff6f1e8c3b4895f6 Mon Sep 17 00:00:00 2001 From: "akito.nishiwaki" Date: Fri, 6 Jun 2025 10:59:42 +0900 Subject: [PATCH 22/23] =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=A2=E3=82=A6?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/AddDishes2.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/AddDishes2.tsx b/frontend/src/pages/AddDishes2.tsx index 19f8d51..d8aa62c 100644 --- a/frontend/src/pages/AddDishes2.tsx +++ b/frontend/src/pages/AddDishes2.tsx @@ -3,7 +3,7 @@ * 白紙の状態で表示されるテスト用のページ */ import React, { useState, useEffect } from 'react'; -import { taskApi } from '../services/api'; +import { taskApi, toBuyApi } from '../services/api'; import { Container, Typography, @@ -127,11 +127,12 @@ const AddDishes2: React.FC = () => { const handleCreateTask_DataBase = async () => { try { // for (let i = 0; i < addtasks.length; i++) { - // await taskApi.createTask(addtasks[i]); + // // await taskApi.createTask(addtasks[i]); + // await toBuyApi.addToBuy(addtasks[i]); // } - // setOpenDialog(false); // ダイアログを閉じる - // setNewTask(EMPTY_TASK); // 入力内容をリセット - // // fetchTasks(); // 作成後のタスク一覧を再取得 + setOpenDialog(false); // ダイアログを閉じる + setNewTask(EMPTY_TASK); // 入力内容をリセット + // fetchTasks(); // 作成後のタスク一覧を再取得 } catch (error) { console.error(`${TASK_ERRORS.CREATE_FAILED}:`, error); } From 7c7677e469b1062957f30945e8424270d4ba401f Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Mon, 9 Jun 2025 10:47:04 +0900 Subject: [PATCH 23/23] =?UTF-8?q?=E3=80=8C=E8=B2=B7=E3=81=86=E3=82=82?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=82=B9=E3=83=88=E3=80=8D=E3=81=AE=E3=82=BF?= =?UTF-8?q?=E3=82=A4=E3=83=88=E3=83=AB=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/TaskListPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index 11229ec..cc97ec7 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -141,7 +141,7 @@ const TaskListPage: React.FC = () => { return ( - タスク一覧 + 買うものリスト {/* タスク一覧表示エリア - 青い背景のコンテナ */}