22 Commits

Author SHA1 Message Date
s-choi
c7e68f6a4f [EDIT] Table名を変更しました。 2026-09-17 14:03:13 +09:00
s-choi
083ad8644d [EDIT] Viewの遷移先アドレスを変更しました。 2026-09-17 14:02:54 +09:00
s-choi
7e648b9466 Merge remote-tracking branch 'origin/s-morimto' into s-choi 2026-09-17 14:00:47 +09:00
s-choi
19989111ec [EDIT] 改行・コード位置を調整しました。 2026-09-17 13:48:08 +09:00
s-choi
4f49c24c99 [EDIT] ModelからEntityへ変換するメソッドを作成しました。 2026-09-17 13:47:39 +09:00
s-choi
8763f88de4 [EDIT] 収支の登録・修正機能を追加しました。日付のDefault値を設定し、Session
Attribute・オブジェクトの型を修正しました。
2026-09-17 13:47:01 +09:00
s-choi
5ab8109504 [EDIT] 名前で検索できる機能を追加しました。 2026-09-17 13:44:57 +09:00
s-choi
d31d6aaf2d [EDIT] 名前で検索できる機能を追加しました。 2026-09-17 13:44:33 +09:00
s-choi
42bb3c608f Merge remote-tracking branch 'origin/s-morimto' into s-choi 2026-09-17 13:06:35 +09:00
s-choi
67ad98b0ae Merge remote-tracking branch 'origin/s-morimto' into s-choi 2026-09-17 13:02:40 +09:00
d65a84ea79 [EDIT]transactionRepositoryにカテゴリ別集計を追記しました。 2026-09-17 13:00:25 +09:00
fbd1746776 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito 2026-09-17 12:37:53 +09:00
s-choi
073ed5e864 [STYLE] 改行を追加しました。 2026-09-17 12:36:35 +09:00
9bc5bd20ac [DELETE&ADD]AnalysisServiceImpl.javaのファイル位置を修正しました 2026-09-17 11:29:54 +09:00
5506f5884b [EDIT]AllocationRepositoryにcategoryId取得の作成 2026-09-17 11:24:37 +09:00
a6a9cb0b63 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito 2026-09-17 11:16:43 +09:00
kkazuya
1369d839af Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 11:16:21 +09:00
kkazuya
7f454b852a [ADD] AllocationRepositoryを作成しました。 2026-09-17 11:16:12 +09:00
83e97b7ec1 [ADD]支出分析画面(骨組み)の作成 2026-09-17 10:56:57 +09:00
kkazuya
f1b5e3eaf8 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 10:49:58 +09:00
kkazuya
59cec2fed7 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 10:47:23 +09:00
kkazuya
743fe20e9a Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 10:36:08 +09:00
16 changed files with 267 additions and 54 deletions

View File

@@ -3,7 +3,9 @@ package com.example.demo.app.domain.model;
import java.time.LocalDate;
import java.util.List;
import com.example.demo.app.infra.entity.CategoryEntity;
import com.example.demo.app.infra.entity.TransactionEntity;
import com.example.demo.app.infra.entity.UserEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -35,4 +37,13 @@ public class TransactionModel {
return transactionEntityList.stream().map(TransactionModel::convertFrom).toList();
}
public static TransactionEntity convertTo(TransactionModel transactionModel, UserEntity userEntity, CategoryEntity categoryEntity) {
return new TransactionEntity(
transactionModel.getTransactionId(),
userEntity,
categoryEntity,
transactionModel.getAmount(),
transactionModel.getTransactionDate());
}
}

View File

@@ -9,4 +9,6 @@ public interface CategoryService {
public List<CategoryModel> findAll();
public CategoryModel findOne(Long categoryId);
public CategoryModel findOneByCategoryName(String categoryName);
}

View File

@@ -16,4 +16,8 @@ public interface TransactionService {
public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId);
public int createTransaction(TransactionModel transactionModel);
public int updateTransaction(TransactionModel transactionModel);
}

View File

@@ -1,8 +1,9 @@
package com.example.demo.app.domain.service;
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.AnalysisModel;
import com.example.demo.app.domain.service.AnalysisService;
import lombok.RequiredArgsConstructor;

View File

@@ -14,7 +14,7 @@ import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService{
public class CategoryServiceImpl implements CategoryService {
private final CategoryRepository categoryRepository;
@@ -36,4 +36,16 @@ public class CategoryServiceImpl implements CategoryService{
}
public CategoryModel findOneByCategoryName(String categoryName) {
CategoryEntity categoryModel = categoryRepository.findByCategoryName(categoryName);
if (categoryModel == null) {
return null;
}
return CategoryModel.convertFrom(categoryModel);
}
}

View File

@@ -3,14 +3,19 @@ package com.example.demo.app.domain.service.impl;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Optional;
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.CategoryEntity;
import com.example.demo.app.infra.entity.TransactionEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.CategoryRepository;
import com.example.demo.app.infra.repository.TransactionRepository;
import com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor;
@@ -19,6 +24,8 @@ import lombok.RequiredArgsConstructor;
public class TransactionServiceImpl implements TransactionService {
private final TransactionRepository transactionRepository;
private final UserRepository userRepository;
private final CategoryRepository categoryRepository;
public Map<LocalDate, List<TransactionModel>> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId) {
@@ -40,6 +47,7 @@ public class TransactionServiceImpl implements TransactionService {
return transactionRepository.findTotalIncome(startDate, endDate, userId);
}
public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId) {
return transactionRepository.findTotalIncome(startDate, endDate, userId);
@@ -52,4 +60,59 @@ public class TransactionServiceImpl implements TransactionService {
}
public int createTransaction(TransactionModel transactionModel) {
Optional<UserEntity> userEntityOptional = userRepository.findById(transactionModel.getUserId());
if (userEntityOptional.isEmpty()) {
return -1;
}
Optional<CategoryEntity> categoryEntityOptional = categoryRepository.findById(transactionModel.getCategoryId());
if (categoryEntityOptional.isEmpty()) {
return -1;
}
TransactionEntity transactionEntity = TransactionModel.convertTo(
transactionModel,
userEntityOptional.get(),
categoryEntityOptional.get());
if (transactionRepository.save(transactionEntity) != null) {
return 0;
} else {
return -1;
}
}
public int updateTransaction(TransactionModel transactionModel) {
if (!transactionRepository.existsById(transactionModel.getTransactionId())) {
return -1;
}
Optional<UserEntity> userEntityOptional = userRepository.findById(transactionModel.getUserId());
if (userEntityOptional.isEmpty()) {
return -1;
}
Optional<CategoryEntity> categoryEntityOptional = categoryRepository.findById(transactionModel.getCategoryId());
if (categoryEntityOptional.isEmpty()) {
return -1;
}
TransactionEntity transactionEntity = TransactionModel.convertTo(
transactionModel,
userEntityOptional.get(),
categoryEntityOptional.get());
if (transactionRepository.save(transactionEntity) != null) {
return 0;
} else {
return -1;
}
}
}

View File

@@ -15,7 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "category")
@Table(name = "category_t")
@Data
@NoArgsConstructor
@AllArgsConstructor

View File

@@ -15,7 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "goal")
@Table(name = "goal_t")
@Data
@NoArgsConstructor
@AllArgsConstructor

View File

@@ -15,7 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "question")
@Table(name = "question_m")
@Data
@NoArgsConstructor
@AllArgsConstructor

View File

@@ -17,7 +17,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "transaction")
@Table(name = "transaction_t")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -28,12 +28,6 @@ public class TransactionEntity {
@Column(name = "transaction_id")
private Long transactionId;
@Column(name = "amount", nullable = false)
private Integer amount;
@Column(name = "transaction_date", nullable = false)
private LocalDate transactionDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private UserEntity userEntity;
@@ -42,4 +36,10 @@ public class TransactionEntity {
@JoinColumn(name = "category_id")
private CategoryEntity categoryEntity;
@Column(name = "amount", nullable = false)
private Integer amount;
@Column(name = "transaction_date", nullable = false)
private LocalDate transactionDate;
}

View File

@@ -1,9 +1,12 @@
package com.example.demo.app.infra.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.demo.app.infra.entity.AllocationEntity;
public interface AllocationRepository extends JpaRepository<AllocationEntity, Long>{
List<AllocationEntity> findByCourseId(Long courseId);
}

View File

@@ -1,9 +1,15 @@
package com.example.demo.app.infra.repository;
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.CategoryEntity;
public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {
@Query("select c from CategoryEntity c where c.categoryName = :categoryName")
public CategoryEntity findByCategoryName(@Param("categoryName") String categoryName);
}

View File

@@ -22,4 +22,6 @@ public interface TransactionRepository extends JpaRepository<TransactionEntity,
@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);
@Query("select sum(t.amount) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate")
public Integer findCategoryExpense(LocalDate startDate, LocalDate endDate, Long userId, Long categoryId);
}

View File

@@ -11,8 +11,11 @@ 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.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CategoryService;
import com.example.demo.app.domain.service.TransactionService;
import com.example.demo.app.presentation.form.CategoryForm;
@@ -26,27 +29,32 @@ 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,
public String transactionList(@RequestParam(required = false) LocalDate startDates,
@RequestParam(required = false) LocalDate endDates, Model model,
HttpSession session) {
LoginUser loginUser = (LoginUser) session.getAttribute("loginUser");
LocalDate startDate = (startDates == null) ? LocalDate.now().withDayOfMonth(1) : startDates;
LocalDate endDate = (endDates == null) ? LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth())
: endDates;
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Map<LocalDate, List<TransactionForm>> transactionFormMap = new HashMap<>();
transactionService.findAll(startDate, endDate, loginUser.getUserId).forEach((date, list) -> {
transactionService.findAllByDate(startDate, endDate, loginUser.getUserId()).forEach((date, list) -> {
List<TransactionForm> 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()
);
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);
@@ -54,30 +62,69 @@ public class TransactionController {
model.addAttribute("transactionFormMap", transactionFormMap);
return "transactionList";
return "transaction_list";
}
// 詳細画面
@GetMapping()
public String findOne(@RequestParam LocalDate todayDate, Model model, HttpSession session) {
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
LoginUser loginUser = (LoginUser) session.getAttribute("loginUser");
LocalDate todayDate = (todayDates == null) ? LocalDate.now() : todayDates;
List<TransactionForm> transactionFormList = transactionService.findByUserIdAndDate(todayDate, ((LoginUser)session.getAttribute("loginUser")).getUserId).stream().map(transaction -> {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
List<TransactionForm> transactionFormList = transactionService
.findByUserIdAndDate(todayDate, 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()
);
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 "";
}
@GetMapping("")
public String createOneGet(@ModelAttribute TransactionForm transactionForm) {
return "";
}
@PostMapping()
public String createOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
if (transactionService.createTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
return "error";
}
return "";
}
@GetMapping("")
public String updateOneGet(@ModelAttribute TransactionForm transactionForm) {
return "";
}
@PostMapping()
public String updateOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
return "error";
}
return "";
}
}

View File

@@ -32,6 +32,7 @@ public class TransactionForm {
private Integer transactionType;
public static TransactionForm convertFrom(TransactionModel transactionModel, String categoryName, int income, int expense, int transactionType) {
return new TransactionForm(
transactionModel.getTransactionId(),
@@ -45,6 +46,7 @@ public class TransactionForm {
transactionType);
}
public static List<TransactionForm> convertFrom(List<TransactionModel> transactionModelList, String categoryName, int income, int expense, int transactionType ) {
return transactionModelList.stream().map(transactionModel -> TransactionForm.convertFrom(transactionModel, categoryName, income, expense, transactionType)).toList();
}

View File

@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>分析画面</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h2 class="text-center">支出分析</h2>
<table class="table text-center">
<thead>
<tr>
<th scope="col">カテゴリ別</th>
<th scope="col">支出</th>
<th scope="col">前月比</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">総支出</th>
<td>¥234,000</td>
<td>+¥38,000</td>
</tr>
</tbody>
</table>
<hr class="border border-primary border-2 opacity-50">
<table class="table text-center">
<thead>
<tr>
<th scope="col">カテゴリ別</th>
<th scope="col">支出</th>
<th scope="col">前月比<br>コース比</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">食費</th>
<td>¥34,000</td>
<td>+¥8,000<br>+¥1,100</td>
</tr>
<tr>
<th scope="row">交通費</th>
<td>¥14,000</td>
<td>+¥8,000<br>+¥1,100</td>
</tr>
<tr>
<th scope="row">日用品</th>
<td>¥4,000</td>
<td>+¥8,000<br>+¥1,100</td>
</tr>
</tbody>
</table>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>