Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example.demo.app.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginModel {
|
||||||
|
private Long userId;
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.example.demo.app.domain.service;
|
package com.example.demo.app.domain.service;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
|
|
||||||
public interface LoginService {
|
public interface LoginService {
|
||||||
|
|
||||||
UserEntity login(String mailAddress, String password);
|
LoginModel login(String mailAddress, String password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.AnalysisModel;
|
import com.example.demo.app.domain.model.AnalysisModel;
|
||||||
|
import com.example.demo.app.domain.service.AnalysisService;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ package com.example.demo.app.domain.service.impl;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
import com.example.demo.app.domain.service.LoginService;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.infra.entity.UserEntity;
|
||||||
import com.example.demo.app.infra.repository.UserRepository;
|
import com.example.demo.app.infra.repository.UserRepository;
|
||||||
@@ -15,11 +16,16 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserEntity login(String mailAddress, String password) {
|
public LoginModel login(String mailAddress, String password) {
|
||||||
|
|
||||||
return userRepository.findByMailAddressAndPassword(
|
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
|
||||||
mailAddress,
|
mailAddress,
|
||||||
password).orElse(null);
|
password).orElse(null);
|
||||||
|
|
||||||
|
if (userEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LoginModel(userEntity.getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ 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")
|
@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);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
import com.example.demo.app.domain.service.LoginService;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
import com.example.demo.app.presentation.form.LoginForm;
|
import com.example.demo.app.presentation.form.LoginForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -33,13 +33,14 @@ public class LoginController {
|
|||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public String login(
|
public String login(
|
||||||
@ModelAttribute LoginForm loginForm,
|
@ModelAttribute LoginForm loginForm,
|
||||||
Model model, HttpSession session) {
|
Model model,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
UserEntity loginUser = loginService.login(
|
LoginModel loginModel = loginService.login(
|
||||||
loginForm.getMailAddress(),
|
loginForm.getMailAddress(),
|
||||||
loginForm.getPassword());
|
loginForm.getPassword());
|
||||||
|
|
||||||
if (loginUser == null) {
|
if (loginModel == null) {
|
||||||
model.addAttribute(
|
model.addAttribute(
|
||||||
"errorMessage",
|
"errorMessage",
|
||||||
"Email address or password is incorrect.");
|
"Email address or password is incorrect.");
|
||||||
@@ -47,9 +48,8 @@ public class LoginController {
|
|||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setAttribute("loginUser", loginUser);
|
session.setAttribute("loginUser", loginModel);
|
||||||
|
|
||||||
return "menu";
|
return "menu";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user