途中
This commit is contained in:
@@ -5,22 +5,66 @@ import java.util.logging.Logger;
|
|||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import com.example.demo.entity.BookCollection;
|
import com.example.demo.common.BusinessException;
|
||||||
import com.example.demo.entity.BorrowBook;
|
import com.example.demo.common.LoginUser;
|
||||||
|
import com.example.demo.form.RentalForm;
|
||||||
|
import com.example.demo.service.LoanService;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AdminLoanController {
|
public class AdminLoanController {
|
||||||
|
|
||||||
// ログ出力用インスタンス
|
// ログ出力用インスタンス
|
||||||
private final static Logger LOGGER = Logger.getLogger(AdminLoanController.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(AdminLoanController.class.getName());
|
||||||
|
|
||||||
// エラーメッセージ用の定数フィールド
|
// エラーメッセージ用の定数フィールド
|
||||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
HttpSession httpSession;
|
|
||||||
BookCollection bookcollection;
|
|
||||||
BorrowBook borrowBook;
|
|
||||||
|
|
||||||
|
|
||||||
|
private final LoanService loanService;
|
||||||
|
|
||||||
|
public AdminLoanController(LoanService loanService) {
|
||||||
|
this.loanService = loanService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/submit")
|
||||||
|
public String executeApproval(
|
||||||
|
@ModelAttribute("approvalConfilm") RentalForm form,
|
||||||
|
@RequestParam("action")
|
||||||
|
String action,
|
||||||
|
HttpSession session,
|
||||||
|
RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
|
// セッションからログイン中の管理者情報を取得
|
||||||
|
LoginUser loginUser = (LoginUser) session.getAttribute("LOGIN_USER");
|
||||||
|
if (loginUser == null) {
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ("approve".equals(action)) {
|
||||||
|
// 確定したLoanServiceのインスタンスメソッド呼び出し
|
||||||
|
loanService.approve(form.getIdRequest(), loginUser);
|
||||||
|
redirectAttributes.addFlashAttribute("successMessage", "申請を承認しました。");
|
||||||
|
|
||||||
|
} else if ("reject".equals(action)) {
|
||||||
|
// 確定したLoanServiceのインスタンスメソッドを呼び出し、IDにはidRequestを渡す
|
||||||
|
loanService.reject(form.getIdRequest(), loginUser);
|
||||||
|
redirectAttributes.addFlashAttribute("successMessage", "申請を却下しました。");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("不正な操作が行われました。");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
|
||||||
|
return "redirect:/admin/rental/detail/" + form.getIdRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "redirect:/applicationList";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user