diff --git a/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookController.java b/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookController.java index 934e428..0b33084 100644 --- a/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookController.java +++ b/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookController.java @@ -1,6 +1,7 @@ package com.ip.library.controllers.books; import java.util.Map; +import java.util.List; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Controller; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.ip.library.controllers.authors.AuthorEntity; import com.ip.library.controllers.types.TypeService; import com.ip.library.core.api.PageAttributesMapper; import com.ip.library.core.configuration.Constants; @@ -43,7 +45,18 @@ public class BookController { private BookDto toBookDto (BookEntity entity) { BookDto bookDto = modelMapper.map(entity, BookDto.class); - bookDto.setAuthorId(entity.getAuthorsBooks().stream().map(x -> x.getAuthor().getId()).toList()); + List authors = entity.getAuthorsBooks().stream().map(x -> x.getAuthor()).toList(); + bookDto.setAuthorsId(authors.stream().map(x -> x.getId()).toList()); + bookDto.setTypeName(entity.getType().getName()); + StringBuilder authorName = new StringBuilder(); + for (AuthorEntity authorEntity : authors) { + authorName.append(", ").append(authorEntity.getName()); + } + if (authorName.length() > 0) { + bookDto.setAuthorName(authorName.toString().substring(2)); + } else { + bookDto.setAuthorName("Неизвестен"); + } return bookDto; } diff --git a/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookDto.java b/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookDto.java index 5733df3..3270a6c 100644 --- a/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookDto.java +++ b/SpringApp/library/src/main/java/com/ip/library/controllers/books/BookDto.java @@ -11,6 +11,10 @@ import jakarta.validation.constraints.NotNull; public class BookDto { @JsonProperty(access = JsonProperty.Access.READ_ONLY) private Long id; + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private String authorName; + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private String typeName; @NotBlank private String name; @NotNull @@ -27,6 +31,22 @@ public class BookDto { this.id = id; } + public String getAuthorName() { + return authorName; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + public String getName() { return name; } @@ -47,7 +67,7 @@ public class BookDto { return authorsId; } - public void setAuthorId(List authorsId) { + public void setAuthorsId(List authorsId) { this.authorsId = authorsId; } } diff --git a/SpringApp/library/src/main/resources/templates/book.html b/SpringApp/library/src/main/resources/templates/book.html index 06b6c17..5403b1b 100644 --- a/SpringApp/library/src/main/resources/templates/book.html +++ b/SpringApp/library/src/main/resources/templates/book.html @@ -21,6 +21,7 @@ ID Название Жанр + Автор @@ -29,7 +30,8 @@ - + +