diff --git a/templates/hw01-xml-config/pom.xml b/templates/hw01-xml-config/pom.xml index a16f06356..cd2909ecb 100644 --- a/templates/hw01-xml-config/pom.xml +++ b/templates/hw01-xml-config/pom.xml @@ -13,12 +13,12 @@ 17 17 UTF-8 - 6.0.12 + 6.0.13 5.8 5.10.0 5.4.0 3.24.2 - 1.18.28 + 1.18.30 3.2.2 10.11.0 diff --git a/templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppConfig.java b/templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppProperties.java similarity index 75% rename from templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppConfig.java rename to templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppProperties.java index def57dd36..08f8f182d 100644 --- a/templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppConfig.java +++ b/templates/hw01-xml-config/src/main/java/ru/otus/hw/config/AppProperties.java @@ -5,7 +5,7 @@ @AllArgsConstructor @Data -public class AppConfig implements TestFileNameProvider { +public class AppProperties implements TestFileNameProvider { private String testFileName; diff --git a/templates/hw01-xml-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java b/templates/hw01-xml-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java index 3941a647d..b77547f3d 100644 --- a/templates/hw01-xml-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java +++ b/templates/hw01-xml-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java @@ -16,6 +16,7 @@ public List findAll() { // Использовать CsvToBean // https://opencsv.sourceforge.net/#collection_based_bean_fields_one_to_many_mappings // Использовать QuestionReadException + // Про ресурсы: https://mkyong.com/java/java-read-a-file-from-resources-folder/ return new ArrayList<>(); } diff --git a/templates/hw02-annotation-config/pom.xml b/templates/hw02-annotation-config/pom.xml index c99477bcd..8faef9826 100644 --- a/templates/hw02-annotation-config/pom.xml +++ b/templates/hw02-annotation-config/pom.xml @@ -13,12 +13,12 @@ 17 17 UTF-8 - 6.0.12 + 6.0.13 5.8 5.10.0 5.4.0 3.24.2 - 1.18.28 + 1.18.30 3.2.2 10.11.0 diff --git a/templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppConfig.java b/templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppProperties.java similarity index 79% rename from templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppConfig.java rename to templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppProperties.java index 974574881..6ff25ebad 100644 --- a/templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppConfig.java +++ b/templates/hw02-annotation-config/src/main/java/ru/otus/hw/config/AppProperties.java @@ -1,8 +1,10 @@ package ru.otus.hw.config; +import lombok.Setter; import org.springframework.beans.factory.annotation.Value; -public class AppConfig implements TestConfig, TestFileNameProvider { +@Setter +public class AppProperties implements TestConfig, TestFileNameProvider { // внедрить свойство из application.properties private int rightAnswersCountToPass; diff --git a/templates/hw02-annotation-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java b/templates/hw02-annotation-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java index 3941a647d..b77547f3d 100644 --- a/templates/hw02-annotation-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java +++ b/templates/hw02-annotation-config/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java @@ -16,6 +16,7 @@ public List findAll() { // Использовать CsvToBean // https://opencsv.sourceforge.net/#collection_based_bean_fields_one_to_many_mappings // Использовать QuestionReadException + // Про ресурсы: https://mkyong.com/java/java-read-a-file-from-resources-folder/ return new ArrayList<>(); } diff --git a/templates/hw03-spring-boot/pom.xml b/templates/hw03-spring-boot/pom.xml index dc0ff1ef2..6647c64ac 100644 --- a/templates/hw03-spring-boot/pom.xml +++ b/templates/hw03-spring-boot/pom.xml @@ -20,7 +20,7 @@ 17 UTF-8 5.8 - 1.18.28 + 1.18.30 3.2.2 10.11.0 diff --git a/templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppConfig.java b/templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppProperties.java similarity index 87% rename from templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppConfig.java rename to templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppProperties.java index c202024d2..4ffaf6877 100644 --- a/templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppConfig.java +++ b/templates/hw03-spring-boot/src/main/java/ru/otus/hw/config/AppProperties.java @@ -9,9 +9,8 @@ @Setter // Использовать @ConfigurationProperties. // Сейчас класс соответствует файлу настроек. Чтобы они сюда отобразились нужно только правильно разместить аннотации -public class AppConfig implements TestConfig, TestFileNameProvider, LocaleConfig { +public class AppProperties implements TestConfig, TestFileNameProvider, LocaleConfig { - @Getter private int rightAnswersCountToPass; @Getter diff --git a/templates/hw03-spring-boot/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java b/templates/hw03-spring-boot/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java index 9551a8b7a..f940d8cae 100644 --- a/templates/hw03-spring-boot/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java +++ b/templates/hw03-spring-boot/src/main/java/ru/otus/hw/dao/CsvQuestionDao.java @@ -18,6 +18,7 @@ public List findAll() { // Использовать CsvToBean // https://opencsv.sourceforge.net/#collection_based_bean_fields_one_to_many_mappings // Использовать QuestionReadException + // Про ресурсы: https://mkyong.com/java/java-read-a-file-from-resources-folder/ return new ArrayList<>(); } diff --git a/templates/hw05-jdbc-simple-template/.gitignore b/templates/hw05-jdbc-hard/.gitignore similarity index 94% rename from templates/hw05-jdbc-simple-template/.gitignore rename to templates/hw05-jdbc-hard/.gitignore index b96df348b..5ae18aca6 100644 --- a/templates/hw05-jdbc-simple-template/.gitignore +++ b/templates/hw05-jdbc-hard/.gitignore @@ -16,7 +16,6 @@ HELP.md *.iws *.iml *.ipr -spring-shell.log ### NetBeans ### /nbproject/private/ @@ -28,3 +27,5 @@ spring-shell.log ### VS Code ### .vscode/ + +spring-shell.log \ No newline at end of file diff --git a/templates/hw05-jdbc-hard-template/pom.xml b/templates/hw05-jdbc-hard/pom.xml similarity index 99% rename from templates/hw05-jdbc-hard-template/pom.xml rename to templates/hw05-jdbc-hard/pom.xml index 86f97d4b4..9c467b1a2 100644 --- a/templates/hw05-jdbc-hard-template/pom.xml +++ b/templates/hw05-jdbc-hard/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.1.5 diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/Application.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/Application.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/Application.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/Application.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/AuthorCommands.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/AuthorCommands.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/AuthorCommands.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/AuthorCommands.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/BookCommands.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/BookCommands.java similarity index 84% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/BookCommands.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/BookCommands.java index 0716dd6a7..9189a8c60 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/BookCommands.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/BookCommands.java @@ -6,9 +6,10 @@ import ru.otus.hw.converters.BookConverter; import ru.otus.hw.services.BookService; -import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +@SuppressWarnings({"SpellCheckingInspection", "unused"}) @RequiredArgsConstructor @ShellComponent public class BookCommands { @@ -31,16 +32,16 @@ public String findBookById(long id) { .orElse("Book with id %d not found".formatted(id)); } - //bins aaaaaaaaaaaaa 1 1,6//bins aaaaaaaaaaaaa 1 1,6 + // bins newBook 1 1,6 @ShellMethod(value = "Insert book", key = "bins") - public String insertBook(String title, long authorId, List genresIds) { + public String insertBook(String title, long authorId, Set genresIds) { var savedBook = bookService.insert(title, authorId, genresIds); return bookConverter.bookToString(savedBook); } - //bupd 4 dfasdfasdfasd 3 2,5 + // bupd 4 editedBook 3 2,5 @ShellMethod(value = "Update book", key = "bupd") - public String updateBook(long id, String title, long authorId, List genresIds) { + public String updateBook(long id, String title, long authorId, Set genresIds) { var savedBook = bookService.update(id, title, authorId, genresIds); return bookConverter.bookToString(savedBook); } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/GenreCommands.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/GenreCommands.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/commands/GenreCommands.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/commands/GenreCommands.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/AuthorConverter.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/AuthorConverter.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/AuthorConverter.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/AuthorConverter.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/BookConverter.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/BookConverter.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/BookConverter.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/BookConverter.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/GenreConverter.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/GenreConverter.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/converters/GenreConverter.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/converters/GenreConverter.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Author.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Author.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Author.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Author.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Book.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Book.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Book.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Book.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Genre.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Genre.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/models/Genre.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/models/Genre.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/AuthorRepository.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/AuthorRepository.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/AuthorRepository.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/AuthorRepository.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/BookRepository.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/BookRepository.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/BookRepository.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/BookRepository.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepository.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/GenreRepository.java similarity index 69% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepository.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/GenreRepository.java index 02e87b108..06d63458d 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepository.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/GenreRepository.java @@ -3,9 +3,10 @@ import ru.otus.hw.models.Genre; import java.util.List; +import java.util.Set; public interface GenreRepository { List findAll(); - List findAllByIds(List ids); + List findAllByIds(Set ids); } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java similarity index 91% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java index b12c0c2c1..892acbcc2 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; @Repository -public class AuthorRepositoryJdbc implements AuthorRepository { +public class JdbcAuthorRepository implements AuthorRepository { @Override public List findAll() { diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java similarity index 86% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java index bb99e66e0..43e13c6d4 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java @@ -17,7 +17,7 @@ @Repository @RequiredArgsConstructor -public class BookRepositoryJdbc implements BookRepository { +public class JdbcBookRepository implements BookRepository { private final GenreRepository genreRepository; @@ -75,6 +75,7 @@ private Book insert(Book book) { private Book update(Book book) { //... + // Выбросить EntityNotFoundException если не обновлено ни одной записи в БД removeGenresRelationsFor(book); batchInsertGenresRelationsFor(book); @@ -82,7 +83,7 @@ private Book update(Book book) { } private void batchInsertGenresRelationsFor(Book book) { - // batchUpdate + // Использовать метод batchUpdate } private void removeGenresRelationsFor(Book book) { @@ -97,13 +98,14 @@ public Book mapRow(ResultSet rs, int rowNum) throws SQLException { } } + // Использовать для findById @SuppressWarnings("ClassCanBeRecord") @RequiredArgsConstructor - private static class BookResultSetExtractor implements ResultSetExtractor> { + private static class BookResultSetExtractor implements ResultSetExtractor { @Override - public List extractData(ResultSet rs) throws SQLException, DataAccessException { - return new ArrayList<>(); + public Book extractData(ResultSet rs) throws SQLException, DataAccessException { + return null; } } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java similarity index 82% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java index e87daa58f..2886574a5 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java @@ -8,9 +8,10 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Set; @Repository -public class GenreRepositoryJdbc implements GenreRepository { +public class JdbcGenreRepository implements GenreRepository { @Override public List findAll() { @@ -18,7 +19,7 @@ public List findAll() { } @Override - public List findAllByIds(List ids) { + public List findAllByIds(Set ids) { return new ArrayList<>(); } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/AuthorService.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/AuthorService.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/AuthorService.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/AuthorService.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookService.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookService.java similarity index 59% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookService.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookService.java index 8b37a4b02..b7c1b3861 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookService.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookService.java @@ -4,15 +4,16 @@ import java.util.List; import java.util.Optional; +import java.util.Set; public interface BookService { Optional findById(long id); List findAll(); - Book insert(String title, long authorId, List genresIds); + Book insert(String title, long authorId, Set genresIds); - Book update(long id, String title, long authorId, List genresIds); + Book update(long id, String title, long authorId, Set genresIds); void deleteById(long id); } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookServiceImpl.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookServiceImpl.java similarity index 71% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookServiceImpl.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookServiceImpl.java index a6495210f..d008d13df 100644 --- a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/BookServiceImpl.java +++ b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/BookServiceImpl.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Optional; +import java.util.Set; import static org.springframework.util.CollectionUtils.isEmpty; @@ -33,12 +34,12 @@ public List findAll() { } @Override - public Book insert(String title, long authorId, List genresIds) { + public Book insert(String title, long authorId, Set genresIds) { return save(0, title, authorId, genresIds); } @Override - public Book update(long id, String title, long authorId, List genresIds) { + public Book update(long id, String title, long authorId, Set genresIds) { return save(id, title, authorId, genresIds); } @@ -47,13 +48,18 @@ public void deleteById(long id) { bookRepository.deleteById(id); } - private Book save(long id, String title, long authorId, List genresIds) { + private Book save(long id, String title, long authorId, Set genresIds) { + if (isEmpty(genresIds)) { + throw new IllegalArgumentException("Genres ids must not be null"); + } + var author = authorRepository.findById(authorId) .orElseThrow(() -> new EntityNotFoundException("Author with id %d not found".formatted(authorId))); var genres = genreRepository.findAllByIds(genresIds); - if (isEmpty(genres)) { - throw new EntityNotFoundException("Genres with ids %s not found".formatted(genresIds)); + if (isEmpty(genres) || genresIds.size() != genres.size()) { + throw new EntityNotFoundException("One or all genres with ids %s not found".formatted(genresIds)); } + var book = new Book(id, title, author, genres); return bookRepository.save(book); } diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/GenreService.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/GenreService.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/GenreService.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/GenreService.java diff --git a/templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/GenreServiceImpl.java b/templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/GenreServiceImpl.java similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/java/ru/otus/hw/services/GenreServiceImpl.java rename to templates/hw05-jdbc-hard/src/main/java/ru/otus/hw/services/GenreServiceImpl.java diff --git a/templates/hw05-jdbc-hard-template/src/main/resources/application.yml b/templates/hw05-jdbc-hard/src/main/resources/application.yml similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/resources/application.yml rename to templates/hw05-jdbc-hard/src/main/resources/application.yml diff --git a/templates/hw05-jdbc-hard-template/src/main/resources/data.sql b/templates/hw05-jdbc-hard/src/main/resources/data.sql similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/resources/data.sql rename to templates/hw05-jdbc-hard/src/main/resources/data.sql diff --git a/templates/hw05-jdbc-hard-template/src/main/resources/schema.sql b/templates/hw05-jdbc-hard/src/main/resources/schema.sql similarity index 100% rename from templates/hw05-jdbc-hard-template/src/main/resources/schema.sql rename to templates/hw05-jdbc-hard/src/main/resources/schema.sql diff --git a/templates/hw05-jdbc-hard-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java b/templates/hw05-jdbc-hard/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java similarity index 96% rename from templates/hw05-jdbc-hard-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java rename to templates/hw05-jdbc-hard/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java index a226d7ab7..8c6bcfdec 100644 --- a/templates/hw05-jdbc-hard-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java +++ b/templates/hw05-jdbc-hard/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java @@ -19,11 +19,11 @@ @DisplayName("Репозиторий на основе Jdbc для работы с книгами ") @JdbcTest -@Import({BookRepositoryJdbc.class, GenreRepositoryJdbc.class}) -class BookRepositoryJdbcTest { +@Import({JdbcBookRepository.class, JdbcGenreRepository.class}) +class JdbcBookRepositoryTest { @Autowired - private BookRepositoryJdbc repositoryJdbc; + private JdbcBookRepository repositoryJdbc; private List dbAuthors; diff --git a/templates/hw05-jdbc-hard-template/src/test/resources/application.yml b/templates/hw05-jdbc-hard/src/test/resources/application.yml similarity index 100% rename from templates/hw05-jdbc-hard-template/src/test/resources/application.yml rename to templates/hw05-jdbc-hard/src/test/resources/application.yml diff --git a/templates/hw05-jdbc-hard-template/src/test/resources/data.sql b/templates/hw05-jdbc-hard/src/test/resources/data.sql similarity index 100% rename from templates/hw05-jdbc-hard-template/src/test/resources/data.sql rename to templates/hw05-jdbc-hard/src/test/resources/data.sql diff --git a/templates/hw05-jdbc-hard-template/.gitignore b/templates/hw05-jdbc-simple/.gitignore similarity index 94% rename from templates/hw05-jdbc-hard-template/.gitignore rename to templates/hw05-jdbc-simple/.gitignore index b96df348b..5ae18aca6 100644 --- a/templates/hw05-jdbc-hard-template/.gitignore +++ b/templates/hw05-jdbc-simple/.gitignore @@ -16,7 +16,6 @@ HELP.md *.iws *.iml *.ipr -spring-shell.log ### NetBeans ### /nbproject/private/ @@ -28,3 +27,5 @@ spring-shell.log ### VS Code ### .vscode/ + +spring-shell.log \ No newline at end of file diff --git a/templates/hw05-jdbc-simple-template/pom.xml b/templates/hw05-jdbc-simple/pom.xml similarity index 99% rename from templates/hw05-jdbc-simple-template/pom.xml rename to templates/hw05-jdbc-simple/pom.xml index 86f97d4b4..9c467b1a2 100644 --- a/templates/hw05-jdbc-simple-template/pom.xml +++ b/templates/hw05-jdbc-simple/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.1.5 diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/Application.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/Application.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/Application.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/Application.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/AuthorCommands.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/AuthorCommands.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/AuthorCommands.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/AuthorCommands.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/BookCommands.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/BookCommands.java similarity index 91% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/BookCommands.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/BookCommands.java index 2a6124f03..fb65dba13 100644 --- a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/BookCommands.java +++ b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/BookCommands.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; +@SuppressWarnings({"SpellCheckingInspection", "unused"}) @RequiredArgsConstructor @ShellComponent public class BookCommands { @@ -30,12 +31,14 @@ public String findBookById(long id) { .orElse("Book with id %d not found".formatted(id)); } + // bins newBook 1 1 @ShellMethod(value = "Insert book", key = "bins") public String insertBook(String title, long authorId, long genreId) { var savedBook = bookService.insert(title, authorId, genreId); return bookConverter.bookToString(savedBook); } + // bupd 4 editedBook 3 2 @ShellMethod(value = "Update book", key = "bupd") public String updateBook(long id, String title, long authorId, long genreId) { var savedBook = bookService.update(id, title, authorId, genreId); diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/GenreCommands.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/GenreCommands.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/commands/GenreCommands.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/commands/GenreCommands.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/AuthorConverter.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/AuthorConverter.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/AuthorConverter.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/AuthorConverter.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/BookConverter.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/BookConverter.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/BookConverter.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/BookConverter.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/GenreConverter.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/GenreConverter.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/converters/GenreConverter.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/converters/GenreConverter.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/exceptions/EntityNotFoundException.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Author.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Author.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Author.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Author.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Book.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Book.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Book.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Book.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Genre.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Genre.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/models/Genre.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/models/Genre.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/AuthorRepository.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/AuthorRepository.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/AuthorRepository.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/AuthorRepository.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/BookRepository.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/BookRepository.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/BookRepository.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/BookRepository.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/GenreRepository.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/GenreRepository.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/GenreRepository.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/GenreRepository.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java similarity index 91% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java index b12c0c2c1..892acbcc2 100644 --- a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/AuthorRepositoryJdbc.java +++ b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcAuthorRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; @Repository -public class AuthorRepositoryJdbc implements AuthorRepository { +public class JdbcAuthorRepository implements AuthorRepository { @Override public List findAll() { diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java similarity index 87% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java index fb3c70c3d..6dc8760de 100644 --- a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/BookRepositoryJdbc.java +++ b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcBookRepository.java @@ -12,7 +12,7 @@ import java.util.Optional; @Repository -public class BookRepositoryJdbc implements BookRepository { +public class JdbcBookRepository implements BookRepository { @Override public Optional findById(long id) { @@ -49,6 +49,7 @@ private Book insert(Book book) { private Book update(Book book) { //... + // Выбросить EntityNotFoundException если не обновлено ни одной записи в БД return book; } diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java similarity index 91% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java index 075e7f828..dc4e28373 100644 --- a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/repositories/GenreRepositoryJdbc.java +++ b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/repositories/JdbcGenreRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; @Repository -public class GenreRepositoryJdbc implements GenreRepository { +public class JdbcGenreRepository implements GenreRepository { @Override public List findAll() { diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/AuthorService.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/AuthorService.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/AuthorService.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/AuthorService.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/AuthorServiceImpl.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/BookService.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/BookService.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/BookService.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/BookService.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/BookServiceImpl.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/BookServiceImpl.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/BookServiceImpl.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/BookServiceImpl.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/GenreService.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/GenreService.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/GenreService.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/GenreService.java diff --git a/templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/GenreServiceImpl.java b/templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/GenreServiceImpl.java similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/java/ru/otus/hw/services/GenreServiceImpl.java rename to templates/hw05-jdbc-simple/src/main/java/ru/otus/hw/services/GenreServiceImpl.java diff --git a/templates/hw05-jdbc-simple-template/src/main/resources/application.yml b/templates/hw05-jdbc-simple/src/main/resources/application.yml similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/resources/application.yml rename to templates/hw05-jdbc-simple/src/main/resources/application.yml diff --git a/templates/hw05-jdbc-simple-template/src/main/resources/data.sql b/templates/hw05-jdbc-simple/src/main/resources/data.sql similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/resources/data.sql rename to templates/hw05-jdbc-simple/src/main/resources/data.sql diff --git a/templates/hw05-jdbc-simple-template/src/main/resources/schema.sql b/templates/hw05-jdbc-simple/src/main/resources/schema.sql similarity index 100% rename from templates/hw05-jdbc-simple-template/src/main/resources/schema.sql rename to templates/hw05-jdbc-simple/src/main/resources/schema.sql diff --git a/templates/hw05-jdbc-simple-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java b/templates/hw05-jdbc-simple/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java similarity index 96% rename from templates/hw05-jdbc-simple-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java rename to templates/hw05-jdbc-simple/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java index 10e1b6401..4583cec57 100644 --- a/templates/hw05-jdbc-simple-template/src/test/java/ru/otus/hw/repositories/BookRepositoryJdbcTest.java +++ b/templates/hw05-jdbc-simple/src/test/java/ru/otus/hw/repositories/JdbcBookRepositoryTest.java @@ -19,11 +19,11 @@ @DisplayName("Репозиторий на основе Jdbc для работы с книгами ") @JdbcTest -@Import({BookRepositoryJdbc.class, GenreRepositoryJdbc.class}) -class BookRepositoryJdbcTest { +@Import({JdbcBookRepository.class, JdbcGenreRepository.class}) +class JdbcBookRepositoryTest { @Autowired - private BookRepositoryJdbc repositoryJdbc; + private JdbcBookRepository repositoryJdbc; private List dbAuthors; diff --git a/templates/hw05-jdbc-simple-template/src/test/resources/application.yml b/templates/hw05-jdbc-simple/src/test/resources/application.yml similarity index 100% rename from templates/hw05-jdbc-simple-template/src/test/resources/application.yml rename to templates/hw05-jdbc-simple/src/test/resources/application.yml diff --git a/templates/hw05-jdbc-simple-template/src/test/resources/data.sql b/templates/hw05-jdbc-simple/src/test/resources/data.sql similarity index 100% rename from templates/hw05-jdbc-simple-template/src/test/resources/data.sql rename to templates/hw05-jdbc-simple/src/test/resources/data.sql