[EDIT]プロフィールの編集

This commit is contained in:
2026-09-18 14:57:43 +09:00
parent 11fbec6d8c
commit f588e29b46
4 changed files with 43 additions and 4 deletions

View File

@@ -4,4 +4,5 @@ import com.example.demo.app.domain.model.ProfileModel;
public interface ProfileService {
ProfileModel findOne(Long userId);
void withdraw(Long userId);
}

View File

@@ -31,4 +31,16 @@ public class ProfileServiceImpl implements ProfileService{
userEntity.getAnnualIncome(),
userEntity.getMonthlyBudget());
}
@Override
public void withdraw(Long userId) {
UserEntity userEntity =userRepository.findById(userId).orElse(null);
if (userEntity == null) {
return;
}
userEntity.setDeleteFlag(1);
userRepository.save(userEntity);
}
}

View File

@@ -5,6 +5,7 @@ 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.PostMapping;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.model.ProfileModel;
@@ -29,4 +30,28 @@ public class ProfileController {
model.addAttribute("profileForm", profileForm);
return "profile";
}
@GetMapping("/profile/edit")
public String showEditProfile() {
return "profile_edit";
}
@PostMapping("/withdraw")
public String withdraw(HttpSession session) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
profileService.withdraw(loginUser.getUserId());
session.invalidate();
return "redirect:/login";
}
@PostMapping("/logout")
public String logout(HttpSession session) {
session.invalidate();
return "redirect:/login";
}
}

View File

@@ -51,11 +51,12 @@
</form>
</div>
<form th:action="@{/login}" method="post">
<form th:action="@{/logout}" method="post">
<button type="submit">ログアウト</button>
</form>
<form th:action="@{/aaa}" method="post">
<form th:action="@{/withdraw}" method="post"
onsubmit="return confirm('本当に脱退しますか?');">
<button type="submit">脱退</button>
</form>
</main>