diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b1f1f0f08534a7d96b12a824f698d5c4114c1716 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# 📚 Bookworm Library + +Jednoduchá Java aplikace pro správu knihovny – REST API, frontend a event-driven architektura pomocà Spring Boot a JMS (ActiveMQ Artemis). + +--- + +## 🚀 Funkce + +- ✅ Přidánà knihy (REST + GUI) +- ✅ Půjčenà a vrácenà knihy +- ✅ Zobrazenà seznamu knih (Thymeleaf) +- ✅ Event-driven reakce na vytvořenà knihy +- ✅ In-memory databáze (H2) +- ✅ Embedded JMS (ActiveMQ Artemis) +- ✅ Swagger dokumentace + +--- + +## 🔧 Technologie + +- Java 21 +- Spring Boot 3.2+ +- Spring Web, JPA, Thymeleaf, JMS +- H2 database +- Mockito, JUnit 5 + +--- + +## ▶️ Jak aplikaci spustit + +1. **Klonuj nebo rozbal projekt** +2. Ujisti se, že máš Javu 21+ +3. V root složce spusť: + +```bash +./mvnw spring-boot:run \ No newline at end of file diff --git a/pom.xml b/pom.xml index 44fc8a0284c66f8a14ecfb665bb02664b808b164..f17bb3f047a5f359be9c30f22b2616e5503a72a5 100644 --- a/pom.xml +++ b/pom.xml @@ -64,16 +64,7 @@ <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-activemq</artifactId> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-broker</artifactId> - <version>5.17.6</version> <!-- aktuálnà verze k dubnu 2025 --> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/src/main/java/com/example/library/BookEventListener.java b/src/main/java/com/example/library/BookEventListener.java new file mode 100644 index 0000000000000000000000000000000000000000..5855e509780bb0b1269f977dbfe7048ba999cc1d --- /dev/null +++ b/src/main/java/com/example/library/BookEventListener.java @@ -0,0 +1,5 @@ +package com.example.library; + +public interface BookEventListener { + void onBookCreated(Book book); +} diff --git a/src/main/java/com/example/library/BookEventRegistry.java b/src/main/java/com/example/library/BookEventRegistry.java new file mode 100644 index 0000000000000000000000000000000000000000..e61fce56d5c5ec6f1233b0703a2c23cea5f317d3 --- /dev/null +++ b/src/main/java/com/example/library/BookEventRegistry.java @@ -0,0 +1,5 @@ +package com.example.library; + +public interface BookEventRegistry { + void registerListener(BookEventListener listener); +} diff --git a/src/main/java/com/example/library/BookEventService.java b/src/main/java/com/example/library/BookEventService.java new file mode 100644 index 0000000000000000000000000000000000000000..6a769591f7e530cfc134f3198a45b3b369d9954b --- /dev/null +++ b/src/main/java/com/example/library/BookEventService.java @@ -0,0 +1,22 @@ +package com.example.library; + +import jakarta.annotation.PostConstruct; +import org.springframework.stereotype.Service; + +@Service +public class BookEventService { + + private final BookEventRegistry registry; + + public BookEventService(BookEventRegistry registry) { + this.registry = registry; + } + + @PostConstruct + public void register() { + registry.registerListener(book -> { + // např. logika ukládánà do DB + System.out.println("Book created: " + book.getTitle()); + }); + } +} diff --git a/src/main/java/com/example/library/BookSender.java b/src/main/java/com/example/library/BookSender.java deleted file mode 100644 index 867352d2d94c7db485b9515dd90df914f2d874cd..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/library/BookSender.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.library; - -import jakarta.jms.Queue; -import org.springframework.jms.core.JmsTemplate; -import org.springframework.stereotype.Service; - -@Service -public class BookSender { - - private final JmsTemplate jmsTemplate; - private final Queue bookQueue; - - public BookSender(JmsTemplate jmsTemplate, Queue bookQueue) { - this.jmsTemplate = jmsTemplate; - this.bookQueue = bookQueue; - } - - public void sendBook(Book book) { - jmsTemplate.convertAndSend(bookQueue, book); - } -} \ No newline at end of file diff --git a/src/main/java/com/example/library/BookeEventRegistryImpl.java b/src/main/java/com/example/library/BookeEventRegistryImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b9c1ff668d36200499f4539b9a56e19064733395 --- /dev/null +++ b/src/main/java/com/example/library/BookeEventRegistryImpl.java @@ -0,0 +1,13 @@ +package com.example.library; + +import org.springframework.stereotype.Service; + +@Service +public class BookeEventRegistryImpl implements BookEventRegistry { + + + @Override + public void registerListener(BookEventListener listener) { + + } +} diff --git a/src/main/java/com/example/library/config/JmsConfig.java b/src/main/java/com/example/library/config/JmsConfig.java deleted file mode 100644 index dd7afd0f4f8b71bd9e91c1389d8a155cdf38a367..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/library/config/JmsConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.library.config; - -import jakarta.jms.Queue; -import org.apache.activemq.command.ActiveMQQueue; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class JmsConfig { - - @Bean - public Queue bookQueue() { - return new ActiveMQQueue("bookQueue"); - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6588bd0a41dd41042c99149a925b95884f5f0b40..bd4ac6430c1088191b91ddcaafeee47bc8b5e506 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,4 +5,5 @@ spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.hibernate.ddl-auto=update -spring.h2.console.enabled=true \ No newline at end of file +spring.h2.console.enabled=true + diff --git a/src/test/java/com/example/library/LibraryServiceTest.java b/src/test/java/com/example/library/LibraryServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391