[EDIT]プロフィールの編集
This commit is contained in:
@@ -4,4 +4,5 @@ import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
public interface ProfileService {
|
||||
ProfileModel findOne(Long userId);
|
||||
void withdraw(Long userId);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,13 @@
|
||||
</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">
|
||||
<button type="submit">脱退</button>
|
||||
<form th:action="@{/withdraw}" method="post"
|
||||
onsubmit="return confirm('本当に脱退しますか?');">
|
||||
<button type="submit">脱退</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user