Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
<version>42.3.2</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/group4/controller/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public String listBooks(Model model) {
@GetMapping(value = "/add")
public String create(Model model) {
model.addAttribute("book", new Book());
model.addAttribute("author",new Author());
model.addAttribute("author", new Author());
return "create-book";
}

@PostMapping(value = "/add")
public String create(@Validated @ModelAttribute ("author") Author author, @Validated @ModelAttribute("book") Book book, BindingResult result) {
public String create(@Validated @ModelAttribute("author") Author author, @Validated @ModelAttribute("book") Book book, BindingResult result) {
if (result.hasErrors()) {
return "create-book";
}
Expand All @@ -64,9 +64,16 @@ public String update(@PathVariable("id") int id, Model model) {
}

@GetMapping("book-date/{id}")
public String bookData(@PathVariable("id")int id, Model model){
public String bookData(@PathVariable("id") int id, Model model) {
model.addAttribute("book", bookService.getBookById(id));

return "book-date";
}

@GetMapping("take-book/{id}")
public String getBook(@PathVariable("id") int id, Model model) {
model.addAttribute("book", bookService.getBookById(id));
return "take-book";
}

}
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/list-books.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2><br>Books list</h2>
<a th:href="@{|/books/update/${book.getId()}|}">Update</a>
</td>
<td>
<a th:href="@{|/books/read/${book.getId()}|}">Take book</a>
<a th:href="@{|/books/take-book/${book.getId()}|}">Take book</a>
</td>
<td>
<a th:href="@{|/books/remove/${book.getId()}|}">Delete</a>
Expand Down
36 changes: 36 additions & 0 deletions src/main/webapp/WEB-INF/views/take-book.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<meta charset="UTF-8">
<title>Books list</title>
</head>
<body>

<div class="container">
<a href="/"><br>Home</a>
<h2><br>Book </h2>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Id</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Available</th>
<!-- <th colspan="3" >Operations</th>-->
</tr>
</thead>
<tbody>
<tr th:each="book, el: ${book}">
<td th:text="${el.index + 1}"></td>
<td th:text="${book.id}"></td>
<td th:text="${book.title}"></td>
<td th:text="${book.mainAuthor.getLastName() + ' ' + book.mainAuthor.getFirstName()}"></td>
<td th:text="${book.availableAmount}"></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>