From 60159ea3fe01da408f050e87df40fffd9ead89b3 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 10:56:45 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[FIX]=20User=E3=81=AE=E4=B8=BB=E3=82=AD?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E5=9E=8B=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/demo/app/infra/entity/UserEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/app/infra/entity/UserEntity.java b/src/main/java/com/example/demo/app/infra/entity/UserEntity.java index ef70930..a6797ee 100644 --- a/src/main/java/com/example/demo/app/infra/entity/UserEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/UserEntity.java @@ -29,7 +29,7 @@ public class UserEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id") - private Integer userId; + private Long userId; @Column(name = "user_name", nullable = false) private String userName; From 555d8ceb8721dc1d174aca2665845a01b04353ce Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 10:57:22 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[EDIT]=20Entity=E3=81=8B=E3=82=89Model?= =?UTF-8?q?=E3=81=B8=E3=81=AE=E5=A4=89=E6=8F=9B=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/TransactionModel.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/example/demo/app/domain/model/TransactionModel.java b/src/main/java/com/example/demo/app/domain/model/TransactionModel.java index d985844..dc01b88 100644 --- a/src/main/java/com/example/demo/app/domain/model/TransactionModel.java +++ b/src/main/java/com/example/demo/app/domain/model/TransactionModel.java @@ -1,6 +1,9 @@ package com.example.demo.app.domain.model; import java.time.LocalDate; +import java.util.List; + +import com.example.demo.app.infra.entity.TransactionEntity; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,4 +22,17 @@ public class TransactionModel { private LocalDate transactionDate; + public static TransactionModel convertFrom(TransactionEntity transactionEntity) { + return new TransactionModel( + transactionEntity.getTransactionId(), + transactionEntity.getUserEntity().getUserId(), + transactionEntity.getCategoryEntity().getCategoryId(), + transactionEntity.getAmount(), + transactionEntity.getTransactionDate()); + } + + public static List convertFrom(List transactionEntityList) { + return transactionEntityList.stream().map(TransactionModel::convertFrom).toList(); + } + } \ No newline at end of file From 534fc2683d384c7df691544e474937260b27a0ef Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 10:57:53 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[EDIT]=20Form=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=81=B8=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/form/TransactionForm.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/demo/app/presentation/form/TransactionForm.java b/src/main/java/com/example/demo/app/presentation/form/TransactionForm.java index 0f571c7..d43c944 100644 --- a/src/main/java/com/example/demo/app/presentation/form/TransactionForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/TransactionForm.java @@ -23,18 +23,39 @@ public class TransactionForm { private Integer amount; private LocalDate transactionDate; - - public static TransactionForm convertFrom(TransactionModel transactionModel) { + + private String categoryName; + + private Integer income; + + private Integer expense; + + private Integer transactionType; + + public static TransactionForm convertFrom(TransactionModel transactionModel, String categoryName, int income, int expense, int transactionType) { return new TransactionForm( transactionModel.getTransactionId(), transactionModel.getUserId(), transactionModel.getCategoryId(), transactionModel.getAmount(), - transactionModel.getTransactionDate()); + transactionModel.getTransactionDate(), + categoryName, + income, + expense, + transactionType); } - public static List convertFrom(List transactionModelList) { - return transactionModelList.stream().map(TransactionForm::convertFrom).toList(); + public static List convertFrom(List transactionModelList, String categoryName, int income, int expense, int transactionType ) { + return transactionModelList.stream().map(transactionModel -> TransactionForm.convertFrom(transactionModel, categoryName, income, expense, transactionType)).toList(); } + public static TransactionModel convertTo(TransactionForm transactionForm) { + return new TransactionModel( + transactionForm.getTransactionId(), + transactionForm.getUserId(), + transactionForm.getCategoryId(), + transactionForm.getAmount(), + transactionForm.getTransactionDate()); + } + } From 036a495bc7ae77d1d21e5943f75ff932e8aa450f Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 11:00:40 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[EDIT]=20userId=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E5=8F=8E=E6=94=AF=E6=A4=9C=E7=B4=A2=E3=80=81=E6=9C=9F=E9=96=93?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E6=A9=9F=E8=83=BD=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E3=80=81=E5=8F=8E=E5=85=A5=E3=83=BB=E6=94=AF?= =?UTF-8?q?=E5=87=BA=E3=81=AE=E6=A4=9C=E7=B4=A2=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/TransactionRepository.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java index 4d768bc..a65d524 100644 --- a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java @@ -1,9 +1,26 @@ package com.example.demo.app.infra.repository; +import java.time.LocalDate; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.example.demo.app.infra.entity.TransactionEntity; -public interface TransactionRepository extends JpaRepository{ +public interface TransactionRepository extends JpaRepository { + + @Query("select t from TransactionEntity t where t.userEntity.userId = :userId") + public TransactionEntity findByUserId(@Param("userId") Long userId); + + @Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc") + public List findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId); + + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0") + public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId); + + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1") + public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId); } From 6847f225c4f64e9f0a2b945fb2d12bb953855ea2 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 11:01:39 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[EDIT]=20userId=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E5=8F=8E=E6=94=AF=E6=A4=9C=E7=B4=A2=E3=80=81=E6=9C=9F=E9=96=93?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E6=A9=9F=E8=83=BD=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E3=80=81=E5=8F=8E=E5=85=A5=E3=83=BB=E6=94=AF?= =?UTF-8?q?=E5=87=BA=E3=81=AE=E6=A4=9C=E7=B4=A2=E6=A9=9F=E8=83=BD=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E6=AE=B5=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/TransactionService.java | 14 +++++ .../service/impl/TransactionServiceImpl.java | 52 ++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/app/domain/service/TransactionService.java b/src/main/java/com/example/demo/app/domain/service/TransactionService.java index bcdf8ff..fe437f9 100644 --- a/src/main/java/com/example/demo/app/domain/service/TransactionService.java +++ b/src/main/java/com/example/demo/app/domain/service/TransactionService.java @@ -1,5 +1,19 @@ package com.example.demo.app.domain.service; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; + +import com.example.demo.app.domain.model.TransactionModel; + public interface TransactionService { + public Map> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId); + + public TransactionModel findByUserId(TransactionModel transactionModel); + + public int findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId); + + public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId); + } diff --git a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java index 3484d9e..a4d1712 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java @@ -1,10 +1,60 @@ package com.example.demo.app.domain.service.impl; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; +import com.example.demo.app.domain.model.TransactionModel; import com.example.demo.app.domain.service.TransactionService; +import com.example.demo.app.infra.entity.TransactionEntity; +import com.example.demo.app.infra.repository.TransactionRepository; + +import lombok.RequiredArgsConstructor; @Service -public class TransactionServiceImpl implements TransactionService{ +@RequiredArgsConstructor +public class TransactionServiceImpl implements TransactionService { + + private final TransactionRepository transactionRepository; + + public Map> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId) { + + List transactionEntityList = transactionRepository.findAllByDateAndUserId(startDate, endDate, + userId); + + List transactionModelList = TransactionModel + .convertFrom(transactionEntityList); + + Map> transactionModelMap = transactionModelList.stream() + .collect(Collectors.groupingBy(TransactionModel::getTransactionDate)); + + return transactionModelMap; + + } + + public int findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId) { + + return transactionRepository.findTotalIncome(startDate, endDate, userId); + + } + public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId) { + + return transactionRepository.findTotalIncome(startDate, endDate, userId); + + } + + public TransactionModel findByUserId(TransactionModel transactionModel) { + + TransactionEntity transactionEntity = transactionRepository.findByUserId(transactionModel.getUserId()); + + if (transactionEntity == null) { + return null; + } + + return TransactionModel.convertFrom(transactionEntity); + } } From 544ce423d0c7cec9f29522016e64d9fa78edfd6d Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 11:12:26 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[EDIT]=20userId=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E6=A9=9F=E8=83=BD=E3=81=AB=E6=97=A5=E4=BB=98?= =?UTF-8?q?=E3=82=82=E5=85=A5=E5=8A=9B=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/TransactionService.java | 2 +- .../service/impl/TransactionServiceImpl.java | 9 +-- .../repository/TransactionRepository.java | 5 +- .../controller/TransactionController.java | 76 +++++++++++++++++-- 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/service/TransactionService.java b/src/main/java/com/example/demo/app/domain/service/TransactionService.java index fe437f9..86b85d5 100644 --- a/src/main/java/com/example/demo/app/domain/service/TransactionService.java +++ b/src/main/java/com/example/demo/app/domain/service/TransactionService.java @@ -10,7 +10,7 @@ public interface TransactionService { public Map> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId); - public TransactionModel findByUserId(TransactionModel transactionModel); + public List findByUserIdAndDate(LocalDate todayDate, Long userId); public int findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId); diff --git a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java index a4d1712..771d267 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java @@ -46,15 +46,10 @@ public class TransactionServiceImpl implements TransactionService { } - public TransactionModel findByUserId(TransactionModel transactionModel) { + public List findByUserIdAndDate(LocalDate todayDate, Long userId) { - TransactionEntity transactionEntity = transactionRepository.findByUserId(transactionModel.getUserId()); + return TransactionModel.convertFrom(transactionRepository.findByUserIdAndDate(todayDate, userId)); - if (transactionEntity == null) { - return null; - } - - return TransactionModel.convertFrom(transactionEntity); } } diff --git a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java index a65d524..933aa4f 100644 --- a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java @@ -5,14 +5,13 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import com.example.demo.app.infra.entity.TransactionEntity; public interface TransactionRepository extends JpaRepository { - @Query("select t from TransactionEntity t where t.userEntity.userId = :userId") - public TransactionEntity findByUserId(@Param("userId") Long userId); + @Query("select t from TransactionEntity t where t.userEntity.userId = :userId and t.transactionDate = :transactionDate") + public List findByUserIdAndDate(LocalDate todayDate, Long userId); @Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc") public List findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId); diff --git a/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java b/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java index fca93d3..5e51565 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java @@ -1,17 +1,83 @@ package com.example.demo.app.presentation.controller; -import org.springframework.stereotype.Controller; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import jakarta.servlet.http.HttpSession; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import com.example.demo.app.domain.service.CategoryService; import com.example.demo.app.domain.service.TransactionService; +import com.example.demo.app.presentation.form.CategoryForm; +import com.example.demo.app.presentation.form.TransactionForm; import lombok.RequiredArgsConstructor; @Controller @RequiredArgsConstructor public class TransactionController { - + private final TransactionService transactionService; - - - + private final CategoryService categoryService; + + // 一覧画面 + + @GetMapping("/transaction/list") + public String transactionList(@RequestParam LocalDate startDate, @RequestParam LocalDate endDate, Model model, + HttpSession session) { + + LoginUser loginUser = (LoginUser) session.getAttribute("loginUser"); + + Map> transactionFormMap = new HashMap<>(); + + + transactionService.findAll(startDate, endDate, loginUser.getUserId).forEach((date, list) -> { + List transactionFormList = list.stream().map(transaction -> { + TransactionForm transactionForm = TransactionForm.convertFrom( + transaction, + CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId())).getCategoryName(), + transactionService.findTotalexpense(startDate, endDate, loginUser.getUserId), + transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId), + CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId())).getTransactionType() + ); + return transactionForm; + }).collect(Collectors.toList()); + transactionFormMap.put(date, transactionFormList); + }); + + model.addAttribute("transactionFormMap", transactionFormMap); + + return "transactionList"; + } + + // 詳細画面 + @GetMapping() + public String findOne(@RequestParam LocalDate todayDate, Model model, HttpSession session) { + + LoginUser loginUser = (LoginUser) session.getAttribute("loginUser"); + + List transactionFormList = transactionService.findByUserIdAndDate(todayDate, ((LoginUser)session.getAttribute("loginUser")).getUserId).stream().map(transaction -> { + TransactionForm transactionForm = TransactionForm.convertFrom( + transaction, + CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId())).getCategoryName(), + transactionService.findTotalexpense(todayDate, todayDate, loginUser.getUserId), + transactionService.findTotalIncome(todayDate, todayDate, loginUser.getUserId), + CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId())).getTransactionType() + ); + return transactionForm; + }).collect(Collectors.toList()); + + + model.addAttribute("transactionFormList", transactionFormList); + + return ""; + } + }