3 Commits

Author SHA1 Message Date
s-choi
67ad98b0ae Merge remote-tracking branch 'origin/s-morimto' into s-choi 2026-09-17 13:02:40 +09:00
79cbbc1f2b [EDIT]serviceとcontrollerの修正 2026-09-17 12:59:17 +09:00
1170c710e3 [EDIT]repositoryの修正 2026-09-17 12:41:41 +09:00
4 changed files with 23 additions and 12 deletions

View File

@@ -1,9 +1,9 @@
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 {
UserEntity login(String mailAddress, String password);
LoginModel login(String mailAddress, String password);
}

View File

@@ -2,6 +2,7 @@ package com.example.demo.app.domain.service.impl;
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.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.UserRepository;
@@ -15,11 +16,16 @@ public class LoginServiceImpl implements LoginService {
private final UserRepository userRepository;
@Override
public UserEntity login(String mailAddress, String password) {
public LoginModel login(String mailAddress, String password) {
return userRepository.findByMailAddressAndPassword(
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
mailAddress,
password).orElse(null);
if (userEntity == null) {
return null;
}
return new LoginModel(userEntity.getUserId());
}
}

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.infra.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.example.demo.app.infra.entity.UserEntity;
@@ -10,6 +11,10 @@ import com.example.demo.app.infra.entity.UserEntity;
@Repository
public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<UserEntity> findByMailAddressAndPassword(String mailAddress, String password);
@Query("select u from UserEntity u where u.mailAddress = :mailAddress and u.password = :password and u.deleteFlag = 0")
Optional<UserEntity> findByMailAddressAndPassword(
String mailAddress,
String password);
}

View File

@@ -8,8 +8,8 @@ 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.model.LoginModel;
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;
@@ -33,13 +33,14 @@ public class LoginController {
@PostMapping("/login")
public String login(
@ModelAttribute LoginForm loginForm,
Model model, HttpSession session) {
Model model,
HttpSession session) {
UserEntity loginUser = loginService.login(
LoginModel loginModel = loginService.login(
loginForm.getMailAddress(),
loginForm.getPassword());
if (loginUser == null) {
if (loginModel == null) {
model.addAttribute(
"errorMessage",
"Email address or password is incorrect.");
@@ -47,9 +48,8 @@ public class LoginController {
return "login";
}
session.setAttribute("loginUser", loginUser);
session.setAttribute("loginUser", loginModel);
return "menu";
}
}