Merge branch 'h-seya' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/ShareBooks_new into s-tajihi
This commit is contained in:
@@ -1,24 +1,62 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.BookServiceImpl;
|
||||
import com.example.demo.service.EmployeeService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class BookLendController {
|
||||
|
||||
@Autowired
|
||||
private final BookServiceImpl bookServiceImpl;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@PostMapping("/bookLend")
|
||||
public String bookLend(Model model) {
|
||||
// @PostMapping("/bookLend")
|
||||
// public String bookLend(Model model) {
|
||||
// return "bookLend";
|
||||
// }
|
||||
|
||||
// @PostMapping("/bookLend/{id}")
|
||||
// public String bookLend(@PathVariable int id, Model model) {
|
||||
// System.out.println(id);
|
||||
// model.addAttribute("book", bookServiceImpl.findById(id));
|
||||
// return "bookLend";
|
||||
// }
|
||||
|
||||
@PostMapping("/bookLend/{id}")
|
||||
public String bookLend(@PathVariable int id,Employee employee, Model model) {
|
||||
|
||||
// 図書ID取得
|
||||
model.addAttribute("book", bookServiceImpl.findById(id));
|
||||
|
||||
// 社員ID取得(プルダウン用)
|
||||
List<Employee> empList = employeeService.findAll();
|
||||
|
||||
model.addAttribute("bookLend", employeeService.findAll());
|
||||
|
||||
// model.addAttribute("employeeList", employeeRepository.findByEmployeeId(employee.getEmployeeId()));
|
||||
// model.addAttribute("bookLend", employee);
|
||||
|
||||
return "bookLend";
|
||||
}
|
||||
|
||||
|
||||
// 社員IDを取得してプルダウンに表示させる
|
||||
@PostMapping("/bookLend/employeeId")
|
||||
public String selectEmployeeId(Employee employee, Model model) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public class BookLendService {
|
||||
private BookLendRepository bookLendRepository;
|
||||
|
||||
public List<BookLend> findAll() {
|
||||
return bookLendRepository.findBybookStatus(1);
|
||||
return bookLendRepository.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.example.demo.entity.Book;
|
||||
import com.example.demo.repository.BookRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BookServiceImpl {
|
||||
|
||||
@Autowired
|
||||
@@ -17,9 +23,19 @@ public class BookServiceImpl {
|
||||
public List<Book> findAll() {
|
||||
return bookRepository.findAll();
|
||||
}
|
||||
|
||||
public List<Book> findBooks(String keyword){
|
||||
|
||||
public List<Book> findBooks(String keyword) {
|
||||
return bookRepository.searchBooks(keyword);
|
||||
}
|
||||
|
||||
public Book findById(int bookId) {
|
||||
Optional<Book> book = bookRepository.findById(bookId);
|
||||
if (book.isEmpty()) {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "図書情報が見つかりません");
|
||||
}
|
||||
|
||||
return book.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<tbody>
|
||||
<tr th:each="book : ${book}" th:if="${book.bookManageId != null}">
|
||||
|
||||
<td th:hidden="*{book.bookId}"></td>
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
<td th:text="*{book.isbn}"></td>
|
||||
<td th:text="*{book.title}"></td>
|
||||
@@ -106,8 +107,8 @@
|
||||
|
||||
<td th:if="${session.loginEmployee.adminFlag == 1}">
|
||||
|
||||
<form method="post" action="/bookLend">
|
||||
<input type="hidden" name="bookManageId" th:value="*{book.bookManageId}">
|
||||
<form method="post" th:action="@{/bookLend/{id}(id=${book.bookId})}">
|
||||
<input type="hidden" name="id" th:value="*{book.bookId}">
|
||||
<button type="submit"
|
||||
th:disabled="*{book.bookLends != null && book.bookLends.bookStatus == 1}">
|
||||
貸出
|
||||
|
||||
Reference in New Issue
Block a user