This commit is contained in:
2026-09-17 12:37:53 +09:00
9 changed files with 196 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
package com.example.demo.app.domain.model;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class UserModel {
private Long userId;
private String userName;
private String emailAddress;
private String password;
private Integer secretQuestionId;
private String secretAnswer;
private LocalDate brithDate;
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;
private Integer goalId;
private Integer courseId;
private Integer deleteFlag;
}

View File

@@ -0,0 +1,9 @@
package com.example.demo.app.domain.service;
import com.example.demo.app.infra.entity.UserEntity;
public interface LoginService {
UserEntity login(String mailAddress, String password);
}

View File

@@ -0,0 +1,25 @@
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.service.LoginService;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class LoginServiceImpl implements LoginService {
private final UserRepository userRepository;
@Override
public UserEntity login(String mailAddress, String password) {
return userRepository.findByMailAddressAndPassword(
mailAddress,
password).orElse(null);
}
}

View File

@@ -20,7 +20,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "user")
@Table(name = "user_t")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -59,10 +59,10 @@ public class UserEntity {
private Integer deleteFlag;
@OneToMany(mappedBy = "userEntity")
private List<TransactionEntity> transactionEntity;
private List<TransactionEntity> transactionEntityList;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id")
@JoinColumn(name = "secret_question_id")
private QuestionEntity questionEntity;
@OneToOne(fetch = FetchType.LAZY)

View File

@@ -21,5 +21,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);
}

View File

@@ -0,0 +1,15 @@
package com.example.demo.app.infra.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.app.infra.entity.UserEntity;
@Repository
public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<UserEntity> findByMailAddressAndPassword(String mailAddress, String password);
}

View File

@@ -0,0 +1,55 @@
package com.example.demo.app.presentation.controller;
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 com.example.demo.app.domain.service.LoginService;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.presentation.form.LoginForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class LoginController {
private final LoginService loginService;
@GetMapping("/login")
public String showLogin(Model model) {
model.addAttribute(
"loginForm",
new LoginForm());
return "login";
}
@PostMapping("/login")
public String login(
@ModelAttribute LoginForm loginForm,
Model model, HttpSession session) {
UserEntity loginUser = loginService.login(
loginForm.getMailAddress(),
loginForm.getPassword());
if (loginUser == null) {
model.addAttribute(
"errorMessage",
"Email address or password is incorrect.");
return "login";
}
session.setAttribute("loginUser", loginUser);
return "menu";
}
}

View File

@@ -0,0 +1,15 @@
package com.example.demo.app.presentation.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginForm {
private String mailAddress;
private String password;
}

View File

@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="ja"xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>ログイン</title>
</head>
<body>
<header></header>
<main>
<h1>ログイン</h1>
<div th:if="${errorMessage}" th:text="${errorMessage}"></div>
<form th:action="@{/login}" th:object="${loginForm}" method="post">
<div>
<label for="emailAddress">メールアドレス</label>
<input type="email"
id="emailAddress"
th:field="{emailAddress}"
required>
</div>
<div>
<label for="password">パスワード</label>
<input type="password"
id="password"
th:field="{password}"
required>
</div>
<div>
<button type="submit">ログイン</button>
</div>
</form>
<div>
<a href="@{user/register}">新規会員登録</a>
</div>
<div>
<a href="@{password/authentication}">パスワードを忘れた方</a>
</div>
</main>
</body>
</html>