diff --git a/.gradle/8.14.3/checksums/checksums.lock b/.gradle/8.14.3/checksums/checksums.lock index d7b9710..5152503 100644 Binary files a/.gradle/8.14.3/checksums/checksums.lock and b/.gradle/8.14.3/checksums/checksums.lock differ diff --git a/.gradle/8.14.3/checksums/md5-checksums.bin b/.gradle/8.14.3/checksums/md5-checksums.bin index 9d7f056..390eddd 100644 Binary files a/.gradle/8.14.3/checksums/md5-checksums.bin and b/.gradle/8.14.3/checksums/md5-checksums.bin differ diff --git a/.gradle/8.14.3/checksums/sha1-checksums.bin b/.gradle/8.14.3/checksums/sha1-checksums.bin index 4936d16..a7820f2 100644 Binary files a/.gradle/8.14.3/checksums/sha1-checksums.bin and b/.gradle/8.14.3/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.14.3/executionHistory/executionHistory.bin b/.gradle/8.14.3/executionHistory/executionHistory.bin index 1c64e50..2cd76df 100644 Binary files a/.gradle/8.14.3/executionHistory/executionHistory.bin and b/.gradle/8.14.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.14.3/executionHistory/executionHistory.lock b/.gradle/8.14.3/executionHistory/executionHistory.lock index ec9d262..c6a2c89 100644 Binary files a/.gradle/8.14.3/executionHistory/executionHistory.lock and b/.gradle/8.14.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.14.3/fileHashes/fileHashes.bin b/.gradle/8.14.3/fileHashes/fileHashes.bin index a18ec51..d0a1fae 100644 Binary files a/.gradle/8.14.3/fileHashes/fileHashes.bin and b/.gradle/8.14.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.14.3/fileHashes/fileHashes.lock b/.gradle/8.14.3/fileHashes/fileHashes.lock index d8638a1..477157d 100644 Binary files a/.gradle/8.14.3/fileHashes/fileHashes.lock and b/.gradle/8.14.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.14.3/fileHashes/resourceHashesCache.bin b/.gradle/8.14.3/fileHashes/resourceHashesCache.bin index e843447..2fb84f6 100644 Binary files a/.gradle/8.14.3/fileHashes/resourceHashesCache.bin and b/.gradle/8.14.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 0ec34df..ee05a16 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index ac73e7b..2761d81 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 7f8b09c..b601286 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build.gradle b/build.gradle index 3b4026b..52d945c 100644 --- a/build.gradle +++ b/build.gradle @@ -20,9 +20,12 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' + runtimeOnly 'com.h2database:h2' + testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/build/classes/java/main/com/example/controller/CustomerController.class b/build/classes/java/main/com/example/controller/CustomerController.class index 8019b0b..65bd2cb 100644 Binary files a/build/classes/java/main/com/example/controller/CustomerController.class and b/build/classes/java/main/com/example/controller/CustomerController.class differ diff --git a/build/classes/java/main/com/example/controller/DeliveryController.class b/build/classes/java/main/com/example/controller/DeliveryController.class index ec49aaf..b9dde26 100644 Binary files a/build/classes/java/main/com/example/controller/DeliveryController.class and b/build/classes/java/main/com/example/controller/DeliveryController.class differ diff --git a/build/classes/java/main/com/example/controller/OrderController.class b/build/classes/java/main/com/example/controller/OrderController.class index 8f0da08..10be618 100644 Binary files a/build/classes/java/main/com/example/controller/OrderController.class and b/build/classes/java/main/com/example/controller/OrderController.class differ diff --git a/build/classes/java/main/com/example/dto/CustomerRs.class b/build/classes/java/main/com/example/dto/CustomerRs.class index 42487e7..18a2ce5 100644 Binary files a/build/classes/java/main/com/example/dto/CustomerRs.class and b/build/classes/java/main/com/example/dto/CustomerRs.class differ diff --git a/build/classes/java/main/com/example/dto/DeliveryRq.class b/build/classes/java/main/com/example/dto/DeliveryRq.class index 38e8e39..2aeb1b7 100644 Binary files a/build/classes/java/main/com/example/dto/DeliveryRq.class and b/build/classes/java/main/com/example/dto/DeliveryRq.class differ diff --git a/build/classes/java/main/com/example/dto/DeliveryRs.class b/build/classes/java/main/com/example/dto/DeliveryRs.class index 021afea..db5b84b 100644 Binary files a/build/classes/java/main/com/example/dto/DeliveryRs.class and b/build/classes/java/main/com/example/dto/DeliveryRs.class differ diff --git a/build/classes/java/main/com/example/dto/OrderRq.class b/build/classes/java/main/com/example/dto/OrderRq.class index 8e88198..ec48e85 100644 Binary files a/build/classes/java/main/com/example/dto/OrderRq.class and b/build/classes/java/main/com/example/dto/OrderRq.class differ diff --git a/build/classes/java/main/com/example/dto/OrderRs.class b/build/classes/java/main/com/example/dto/OrderRs.class index 1ea2e0a..0995273 100644 Binary files a/build/classes/java/main/com/example/dto/OrderRs.class and b/build/classes/java/main/com/example/dto/OrderRs.class differ diff --git a/build/classes/java/main/com/example/entity/BaseEntity.class b/build/classes/java/main/com/example/entity/BaseEntity.class index 34ebc62..0176a28 100644 Binary files a/build/classes/java/main/com/example/entity/BaseEntity.class and b/build/classes/java/main/com/example/entity/BaseEntity.class differ diff --git a/build/classes/java/main/com/example/entity/Customer.class b/build/classes/java/main/com/example/entity/Customer.class index e08d4e0..14c08b3 100644 Binary files a/build/classes/java/main/com/example/entity/Customer.class and b/build/classes/java/main/com/example/entity/Customer.class differ diff --git a/build/classes/java/main/com/example/entity/Delivery.class b/build/classes/java/main/com/example/entity/Delivery.class index cdac882..b89c1d8 100644 Binary files a/build/classes/java/main/com/example/entity/Delivery.class and b/build/classes/java/main/com/example/entity/Delivery.class differ diff --git a/build/classes/java/main/com/example/entity/Order.class b/build/classes/java/main/com/example/entity/Order.class index ffa0837..3820e22 100644 Binary files a/build/classes/java/main/com/example/entity/Order.class and b/build/classes/java/main/com/example/entity/Order.class differ diff --git a/build/classes/java/main/com/example/mapper/CustomerMapper.class b/build/classes/java/main/com/example/mapper/CustomerMapper.class index 151b012..ce54c57 100644 Binary files a/build/classes/java/main/com/example/mapper/CustomerMapper.class and b/build/classes/java/main/com/example/mapper/CustomerMapper.class differ diff --git a/build/classes/java/main/com/example/mapper/DeliveryMapper.class b/build/classes/java/main/com/example/mapper/DeliveryMapper.class index 191faff..0a19dde 100644 Binary files a/build/classes/java/main/com/example/mapper/DeliveryMapper.class and b/build/classes/java/main/com/example/mapper/DeliveryMapper.class differ diff --git a/build/classes/java/main/com/example/mapper/OrderMapper.class b/build/classes/java/main/com/example/mapper/OrderMapper.class index 46689c4..fa47a3c 100644 Binary files a/build/classes/java/main/com/example/mapper/OrderMapper.class and b/build/classes/java/main/com/example/mapper/OrderMapper.class differ diff --git a/build/classes/java/main/com/example/repository/CommonRepository.class b/build/classes/java/main/com/example/repository/CommonRepository.class deleted file mode 100644 index 4868416..0000000 Binary files a/build/classes/java/main/com/example/repository/CommonRepository.class and /dev/null differ diff --git a/build/classes/java/main/com/example/repository/CustomerRepository$CustomerOrderStats.class b/build/classes/java/main/com/example/repository/CustomerRepository$CustomerOrderStats.class new file mode 100644 index 0000000..12144ce Binary files /dev/null and b/build/classes/java/main/com/example/repository/CustomerRepository$CustomerOrderStats.class differ diff --git a/build/classes/java/main/com/example/repository/CustomerRepository.class b/build/classes/java/main/com/example/repository/CustomerRepository.class index 1a63c93..301943e 100644 Binary files a/build/classes/java/main/com/example/repository/CustomerRepository.class and b/build/classes/java/main/com/example/repository/CustomerRepository.class differ diff --git a/build/classes/java/main/com/example/repository/DeliveryRepository$DeliveryStatusStats.class b/build/classes/java/main/com/example/repository/DeliveryRepository$DeliveryStatusStats.class new file mode 100644 index 0000000..e12d039 Binary files /dev/null and b/build/classes/java/main/com/example/repository/DeliveryRepository$DeliveryStatusStats.class differ diff --git a/build/classes/java/main/com/example/repository/DeliveryRepository.class b/build/classes/java/main/com/example/repository/DeliveryRepository.class index c7538c7..3eb6da0 100644 Binary files a/build/classes/java/main/com/example/repository/DeliveryRepository.class and b/build/classes/java/main/com/example/repository/DeliveryRepository.class differ diff --git a/build/classes/java/main/com/example/repository/MapRepository.class b/build/classes/java/main/com/example/repository/MapRepository.class deleted file mode 100644 index 6979505..0000000 Binary files a/build/classes/java/main/com/example/repository/MapRepository.class and /dev/null differ diff --git a/build/classes/java/main/com/example/repository/OrderRepository$OrderMonthlyStats.class b/build/classes/java/main/com/example/repository/OrderRepository$OrderMonthlyStats.class new file mode 100644 index 0000000..feafd6c Binary files /dev/null and b/build/classes/java/main/com/example/repository/OrderRepository$OrderMonthlyStats.class differ diff --git a/build/classes/java/main/com/example/repository/OrderRepository$OrderStatusStats.class b/build/classes/java/main/com/example/repository/OrderRepository$OrderStatusStats.class new file mode 100644 index 0000000..ffeede4 Binary files /dev/null and b/build/classes/java/main/com/example/repository/OrderRepository$OrderStatusStats.class differ diff --git a/build/classes/java/main/com/example/repository/OrderRepository.class b/build/classes/java/main/com/example/repository/OrderRepository.class index cf163b7..fc40ce4 100644 Binary files a/build/classes/java/main/com/example/repository/OrderRepository.class and b/build/classes/java/main/com/example/repository/OrderRepository.class differ diff --git a/build/classes/java/main/com/example/service/CustomerService$CustomerOrderStats.class b/build/classes/java/main/com/example/service/CustomerService$CustomerOrderStats.class new file mode 100644 index 0000000..61f7bb2 Binary files /dev/null and b/build/classes/java/main/com/example/service/CustomerService$CustomerOrderStats.class differ diff --git a/build/classes/java/main/com/example/service/CustomerService.class b/build/classes/java/main/com/example/service/CustomerService.class index 53e3a8d..b511b61 100644 Binary files a/build/classes/java/main/com/example/service/CustomerService.class and b/build/classes/java/main/com/example/service/CustomerService.class differ diff --git a/build/classes/java/main/com/example/service/DeliveryService$DeliveryStatusStats.class b/build/classes/java/main/com/example/service/DeliveryService$DeliveryStatusStats.class new file mode 100644 index 0000000..ad46699 Binary files /dev/null and b/build/classes/java/main/com/example/service/DeliveryService$DeliveryStatusStats.class differ diff --git a/build/classes/java/main/com/example/service/DeliveryService.class b/build/classes/java/main/com/example/service/DeliveryService.class index 77bfa51..8472d9c 100644 Binary files a/build/classes/java/main/com/example/service/DeliveryService.class and b/build/classes/java/main/com/example/service/DeliveryService.class differ diff --git a/build/classes/java/main/com/example/service/OrderService$OrderMonthlyStats.class b/build/classes/java/main/com/example/service/OrderService$OrderMonthlyStats.class new file mode 100644 index 0000000..3be5f06 Binary files /dev/null and b/build/classes/java/main/com/example/service/OrderService$OrderMonthlyStats.class differ diff --git a/build/classes/java/main/com/example/service/OrderService$OrderStatusStats.class b/build/classes/java/main/com/example/service/OrderService$OrderStatusStats.class new file mode 100644 index 0000000..251e075 Binary files /dev/null and b/build/classes/java/main/com/example/service/OrderService$OrderStatusStats.class differ diff --git a/build/classes/java/main/com/example/service/OrderService.class b/build/classes/java/main/com/example/service/OrderService.class index 0209535..b1658d3 100644 Binary files a/build/classes/java/main/com/example/service/OrderService.class and b/build/classes/java/main/com/example/service/OrderService.class differ diff --git a/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class b/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class deleted file mode 100644 index 9bb3b8a..0000000 Binary files a/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class and /dev/null differ diff --git a/build/classes/java/test/com/example/service/CustomerServiceTest.class b/build/classes/java/test/com/example/service/CustomerServiceTest.class new file mode 100644 index 0000000..e80c1c5 Binary files /dev/null and b/build/classes/java/test/com/example/service/CustomerServiceTest.class differ diff --git a/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class b/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class deleted file mode 100644 index c568627..0000000 Binary files a/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class and /dev/null differ diff --git a/build/classes/java/test/com/example/service/DeliveryServiceTest.class b/build/classes/java/test/com/example/service/DeliveryServiceTest.class new file mode 100644 index 0000000..10a7449 Binary files /dev/null and b/build/classes/java/test/com/example/service/DeliveryServiceTest.class differ diff --git a/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class b/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class deleted file mode 100644 index 568ce29..0000000 Binary files a/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class and /dev/null differ diff --git a/build/classes/java/test/com/example/service/OrderServiceTest.class b/build/classes/java/test/com/example/service/OrderServiceTest.class new file mode 100644 index 0000000..3c7b767 Binary files /dev/null and b/build/classes/java/test/com/example/service/OrderServiceTest.class differ diff --git a/build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html b/build/reports/tests/test/classes/com.example.service.CustomerServiceTest.html similarity index 52% rename from build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html rename to build/reports/tests/test/classes/com.example.service.CustomerServiceTest.html index 519b3ff..bc7b0d0 100644 --- a/build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html +++ b/build/reports/tests/test/classes/com.example.service.CustomerServiceTest.html @@ -3,17 +3,17 @@ -Test results - CustomerServiceIntegrationTest +Test results - CustomerServiceTest
-

CustomerServiceIntegrationTest

+

CustomerServiceTest

+com.example.service > CustomerServiceTest
@@ -23,7 +23,7 @@ @@ -41,7 +41,7 @@ @@ -64,9 +64,6 @@ Tests
  • -Standard output -
  • -
  • Standard error
  • @@ -81,49 +78,18 @@ - - + + - - - - - - - - - - - - + +
    -
    4
    +
    2

    tests

    -
    0.340s
    +
    0.518s

    duration

    createTest()0.001screate_WhenValidData_ShouldCreateCustomer()0.515s passed
    deleteTest()0.001spassed
    getTest_WhenCustomerNotExists_ShouldThrowException()0.336spassed
    updateTest()0.002sfindById_WhenCustomerExists_ShouldReturnCustomer()0.003s passed
    -

    Standard output

    - -
    10:23:39.285 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.service.CustomerServiceIntegrationTest]: CustomerServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    -10:23:39.330 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.CustomerServiceIntegrationTest
    -
    -  .   ____          _            __ _ _
    - /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    -( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    - \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    -  '  |____| .__|_| |_|_| |_\__, | / / / /
    - =========|_|==============|___/=/_/_/_/
    -
    - :: Spring Boot ::                (v3.5.5)
    -
    -2025-10-11T10:23:39.481+04:00  INFO 25016 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : Starting CustomerServiceIntegrationTest using Java 21.0.3 with PID 25016 (started by floom in /Users/floom/PIbd-21_Kudrinsky_O.S._IP-6)
    -2025-10-11T10:23:39.481+04:00  INFO 25016 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : No active profile set, falling back to 1 default profile: "default"
    -2025-10-11T10:23:40.104+04:00  INFO 25016 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : Started CustomerServiceIntegrationTest in 0.719 seconds (process running for 1.208)
    -
    -
    -
    -

    Standard error

    Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3
    @@ -142,7 +108,7 @@ WARNING: Dynamic loading of agents will be disallowed by default in a future rel
     
     
     
    Generated by -Gradle 8.14.3 at 11 окт. 2025 г., 10:23:40

    +Gradle 8.14.3 at 25 окт. 2025 г., 00:35:22

    diff --git a/build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html b/build/reports/tests/test/classes/com.example.service.DeliveryServiceTest.html similarity index 60% rename from build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html rename to build/reports/tests/test/classes/com.example.service.DeliveryServiceTest.html index 72660e6..381683f 100644 --- a/build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html +++ b/build/reports/tests/test/classes/com.example.service.DeliveryServiceTest.html @@ -3,17 +3,17 @@ -Test results - OrderServiceIntegrationTest +Test results - DeliveryServiceTest
    -

    OrderServiceIntegrationTest

    +

    DeliveryServiceTest

    +com.example.service > DeliveryServiceTest
    @@ -41,7 +41,7 @@ @@ -63,9 +63,6 @@
  • Tests
  • -
  • -Standard output -
  • Tests

    @@ -78,45 +75,37 @@
    - + - + - + - + - - + + - +
    -
    0.007s
    +
    0.045s

    duration

    createTest()create_WhenValidData_ShouldCreateDelivery() 0.001s passed
    deleteTest()delete_WhenDeliveryExists_ShouldDeleteDelivery() 0.001s passed
    findByCustomerIdTest()delete_WhenDeliveryNotExists_ShouldReturnFalse() 0.001s passed
    findByStatusTest()findAll_ShouldReturnAllDeliveries() 0.001s passed
    getTest_WhenOrderNotExists_ShouldThrowException()0.002sfindById_WhenDeliveryExists_ShouldReturnDelivery()0.040s passed
    updateTest()update_WhenDeliveryExists_ShouldUpdateDelivery() 0.001s passed
    -
    -

    Standard output

    - -
    2025-10-11T10:23:40.464+04:00  INFO 25016 --- [demo] [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.OrderServiceIntegrationTest]: OrderServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    -2025-10-11T10:23:40.464+04:00  INFO 25016 --- [demo] [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.OrderServiceIntegrationTest
    -
    -
    -
    Generated by -Gradle 8.14.3 at 11 окт. 2025 г., 10:23:40

    +Gradle 8.14.3 at 25 окт. 2025 г., 00:35:22

    diff --git a/build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html b/build/reports/tests/test/classes/com.example.service.OrderServiceTest.html similarity index 60% rename from build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html rename to build/reports/tests/test/classes/com.example.service.OrderServiceTest.html index 12037d3..9cbbe62 100644 --- a/build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html +++ b/build/reports/tests/test/classes/com.example.service.OrderServiceTest.html @@ -3,17 +3,17 @@ -Test results - DeliveryServiceIntegrationTest +Test results - OrderServiceTest
    -

    DeliveryServiceIntegrationTest

    +

    OrderServiceTest

    +com.example.service > OrderServiceTest
    @@ -23,7 +23,7 @@ @@ -41,7 +41,7 @@ @@ -63,9 +63,6 @@
  • Tests
  • -
  • -Standard output -
  • Tests

    @@ -78,40 +75,42 @@
    - + + + + + + + + + + + - + + + + + + - + - - - - - - +
    -
    5
    +
    7

    tests

    -
    0.007s
    +
    0.048s

    duration

    createTest()create_WhenCustomerNotFound_ShouldThrowException()0.003spassed
    create_WhenValidData_ShouldCreateOrder()0.038spassed
    delete_WhenOrderExists_ShouldDeleteOrder() 0.001s passed
    deleteTest()delete_WhenOrderNotExists_ShouldReturnFalse()0.001spassed
    findAll_ShouldReturnAllOrders() 0.002s passed
    findByTrackingNumberTest()findById_WhenOrderExists_ShouldReturnOrder() 0.001s passed
    getTest_WhenDeliveryNotExists_ShouldThrowException()0.001spassed
    updateTest()update_WhenOrderExists_ShouldUpdateOrder() 0.002s passed
    -
    -

    Standard output

    - -
    2025-10-11T10:23:40.453+04:00  INFO 25016 --- [demo] [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.DeliveryServiceIntegrationTest]: DeliveryServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    -2025-10-11T10:23:40.454+04:00  INFO 25016 --- [demo] [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.DeliveryServiceIntegrationTest
    -
    -
    -
    Generated by -Gradle 8.14.3 at 11 окт. 2025 г., 10:23:40

    +Gradle 8.14.3 at 25 окт. 2025 г., 00:35:22

    diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index 1bd3547..74f8dde 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -38,7 +38,7 @@
    -
    0.354s
    +
    0.611s

    duration

    @@ -85,7 +85,7 @@ 15 0 0 -0.354s +0.611s 100% @@ -107,32 +107,32 @@ -com.example.service.CustomerServiceIntegrationTest +com.example.service.CustomerServiceTest -4 +2 0 0 -0.340s +0.518s 100% -com.example.service.DeliveryServiceIntegrationTest - -5 -0 -0 -0.007s -100% - - - -com.example.service.OrderServiceIntegrationTest +com.example.service.DeliveryServiceTest 6 0 0 -0.007s +0.045s +100% + + + +com.example.service.OrderServiceTest + +7 +0 +0 +0.048s 100% @@ -146,7 +146,7 @@ Generated by -Gradle 8.14.3 at 11 окт. 2025 г., 10:23:40

    +Gradle 8.14.3 at 25 окт. 2025 г., 00:35:22

    diff --git a/build/reports/tests/test/packages/com.example.service.html b/build/reports/tests/test/packages/com.example.service.html index 97fd5a4..e333937 100644 --- a/build/reports/tests/test/packages/com.example.service.html +++ b/build/reports/tests/test/packages/com.example.service.html @@ -40,7 +40,7 @@
    -
    0.354s
    +
    0.611s

    duration

    @@ -78,32 +78,32 @@ -CustomerServiceIntegrationTest +CustomerServiceTest -4 +2 0 0 -0.340s +0.518s 100% -DeliveryServiceIntegrationTest - -5 -0 -0 -0.007s -100% - - - -OrderServiceIntegrationTest +DeliveryServiceTest 6 0 0 -0.007s +0.045s +100% + + + +OrderServiceTest + +7 +0 +0 +0.048s 100% @@ -116,7 +116,7 @@ Generated by -Gradle 8.14.3 at 11 окт. 2025 г., 10:23:40

    +Gradle 8.14.3 at 25 окт. 2025 г., 00:35:22

    diff --git a/build/resources/main/application.properties b/build/resources/main/application.properties index 2109a44..7c5c9e9 100644 --- a/build/resources/main/application.properties +++ b/build/resources/main/application.properties @@ -1 +1,22 @@ -spring.application.name=demo +# H2 Database Configuration +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +# JPA Configuration +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +# H2 Console (для просмотра базы в браузере) +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +# Включить инициализацию данных +spring.sql.init.mode=always +spring.jpa.defer-datasource-initialization=true + +# Server Configuration +server.port=8080 \ No newline at end of file diff --git a/build/resources/main/data.sql b/build/resources/main/data.sql new file mode 100644 index 0000000..01839c6 --- /dev/null +++ b/build/resources/main/data.sql @@ -0,0 +1,14 @@ +-- Тестовые клиенты +INSERT INTO customers (id, name, email, created_at, updated_at) +VALUES +(1, 'Иван Иванов', 'ivan@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(2, 'Петр Петров', 'petr@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(3, 'Мария Сидорова', 'maria@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(4, 'Алексей Козлов', 'alex@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(5, 'Ольга Новикова', 'olga@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + +-- Тестовые доставки (опционально) +INSERT INTO deliveries (id, tracking_number, destination, status, customer_name, created_at, updated_at) +VALUES +(1, 'IVN777777', 'гоголя 34', 'В пути', 'Иван Иванов', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(2, 'IVN012021', 'Москва', 'Принято', 'Петр Петров', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); \ No newline at end of file diff --git a/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml deleted file mode 100644 index 8c9f284..0000000 --- a/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/build/test-results/test/TEST-com.example.service.CustomerServiceTest.xml b/build/test-results/test/TEST-com.example.service.CustomerServiceTest.xml new file mode 100644 index 0000000..86cd130 --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.CustomerServiceTest.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml deleted file mode 100644 index e8a9a56..0000000 --- a/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/build/test-results/test/TEST-com.example.service.DeliveryServiceTest.xml b/build/test-results/test/TEST-com.example.service.DeliveryServiceTest.xml new file mode 100644 index 0000000..0f1c2ce --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.DeliveryServiceTest.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml deleted file mode 100644 index 0bcc9a5..0000000 --- a/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - diff --git a/build/test-results/test/TEST-com.example.service.OrderServiceTest.xml b/build/test-results/test/TEST-com.example.service.OrderServiceTest.xml new file mode 100644 index 0000000..234d47f --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.OrderServiceTest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/build/test-results/test/binary/output.bin b/build/test-results/test/binary/output.bin index 435a439..16e6c95 100644 Binary files a/build/test-results/test/binary/output.bin and b/build/test-results/test/binary/output.bin differ diff --git a/build/test-results/test/binary/output.bin.idx b/build/test-results/test/binary/output.bin.idx index 23a15e5..a70a485 100644 Binary files a/build/test-results/test/binary/output.bin.idx and b/build/test-results/test/binary/output.bin.idx differ diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin index 6af6403..e50fd31 100644 Binary files a/build/test-results/test/binary/results.bin and b/build/test-results/test/binary/results.bin differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId24 b/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId24 new file mode 100644 index 0000000..0176a28 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId24 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId8 b/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId8 deleted file mode 100644 index cfe2675..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/BaseEntity.class.uniqueId8 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId15 b/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId15 deleted file mode 100644 index e08d4e0..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId15 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId22 b/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId22 new file mode 100644 index 0000000..14c08b3 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/Customer.class.uniqueId22 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId0 deleted file mode 100644 index 8019b0b..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId0 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId11 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId11 new file mode 100644 index 0000000..90b243a Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId11 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId7 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId15 similarity index 52% rename from build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId7 rename to build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId15 index 151b012..ce54c57 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId7 and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerMapper.class.uniqueId15 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository$CustomerOrderStats.class.uniqueId28 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository$CustomerOrderStats.class.uniqueId28 new file mode 100644 index 0000000..12144ce Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository$CustomerOrderStats.class.uniqueId28 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId26 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId26 new file mode 100644 index 0000000..301943e Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId26 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId6 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId6 deleted file mode 100644 index 1a63c93..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRepository.class.uniqueId6 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRq.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRq.class.uniqueId1 new file mode 100644 index 0000000..988aed9 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRq.class.uniqueId1 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRs.class.uniqueId25 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRs.class.uniqueId25 new file mode 100644 index 0000000..18a2ce5 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerRs.class.uniqueId25 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService$CustomerOrderStats.class.uniqueId19 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService$CustomerOrderStats.class.uniqueId19 new file mode 100644 index 0000000..61f7bb2 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService$CustomerOrderStats.class.uniqueId19 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId0 new file mode 100644 index 0000000..b511b61 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId0 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId2 deleted file mode 100644 index 53e3a8d..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerService.class.uniqueId2 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId20 b/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId20 new file mode 100644 index 0000000..b89c1d8 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId20 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId9 b/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId9 deleted file mode 100644 index cdac882..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/Delivery.class.uniqueId9 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId12 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId12 deleted file mode 100644 index ec49aaf..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId12 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId4 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId4 new file mode 100644 index 0000000..1a046b4 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryController.class.uniqueId4 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryMapper.class.uniqueId3 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryMapper.class.uniqueId3 index 191faff..0a19dde 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryMapper.class.uniqueId3 and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryMapper.class.uniqueId3 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository$DeliveryStatusStats.class.uniqueId21 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository$DeliveryStatusStats.class.uniqueId21 new file mode 100644 index 0000000..e12d039 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository$DeliveryStatusStats.class.uniqueId21 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId10 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId10 deleted file mode 100644 index c7538c7..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId10 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId16 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId16 new file mode 100644 index 0000000..3eb6da0 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRepository.class.uniqueId16 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRq.class.uniqueId14 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRq.class.uniqueId14 new file mode 100644 index 0000000..2aeb1b7 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRq.class.uniqueId14 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRs.class.uniqueId10 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRs.class.uniqueId10 new file mode 100644 index 0000000..db5b84b Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryRs.class.uniqueId10 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService$DeliveryStatusStats.class.uniqueId27 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService$DeliveryStatusStats.class.uniqueId27 new file mode 100644 index 0000000..ad46699 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService$DeliveryStatusStats.class.uniqueId27 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId13 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId13 deleted file mode 100644 index 77bfa51..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId13 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId23 b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId23 new file mode 100644 index 0000000..8472d9c Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeliveryService.class.uniqueId23 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/MapRepository.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/MapRepository.class.uniqueId1 deleted file mode 100644 index cccba4b..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/MapRepository.class.uniqueId1 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId5 b/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId5 deleted file mode 100644 index ffa0837..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId5 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId8 b/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId8 new file mode 100644 index 0000000..3820e22 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/Order.class.uniqueId8 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId17 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId17 new file mode 100644 index 0000000..2021dea Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId17 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId4 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId4 deleted file mode 100644 index 8f0da08..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId4 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId11 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId11 deleted file mode 100644 index 46689c4..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId11 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId2 new file mode 100644 index 0000000..fa47a3c Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderMapper.class.uniqueId2 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderMonthlyStats.class.uniqueId18 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderMonthlyStats.class.uniqueId18 new file mode 100644 index 0000000..feafd6c Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderMonthlyStats.class.uniqueId18 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderStatusStats.class.uniqueId7 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderStatusStats.class.uniqueId7 new file mode 100644 index 0000000..ffeede4 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository$OrderStatusStats.class.uniqueId7 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId12 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId12 new file mode 100644 index 0000000..fc40ce4 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId12 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId16 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId16 deleted file mode 100644 index cf163b7..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRepository.class.uniqueId16 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRq.class.uniqueId6 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRq.class.uniqueId6 new file mode 100644 index 0000000..ec48e85 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRq.class.uniqueId6 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderRs.class.uniqueId13 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRs.class.uniqueId13 new file mode 100644 index 0000000..0995273 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderRs.class.uniqueId13 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderMonthlyStats.class.uniqueId5 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderMonthlyStats.class.uniqueId5 new file mode 100644 index 0000000..3be5f06 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderMonthlyStats.class.uniqueId5 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderStatusStats.class.uniqueId29 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderStatusStats.class.uniqueId29 new file mode 100644 index 0000000..251e075 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService$OrderStatusStats.class.uniqueId29 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId14 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId14 deleted file mode 100644 index 0209535..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId14 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId9 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId9 new file mode 100644 index 0000000..b1658d3 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/OrderService.class.uniqueId9 differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 6bf8901..882cfa2 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/build/tmp/compileTestJava/compileTransaction/stash-dir/CustomerServiceTest.class.uniqueId1 b/build/tmp/compileTestJava/compileTransaction/stash-dir/CustomerServiceTest.class.uniqueId1 new file mode 100644 index 0000000..e80c1c5 Binary files /dev/null and b/build/tmp/compileTestJava/compileTransaction/stash-dir/CustomerServiceTest.class.uniqueId1 differ diff --git a/build/tmp/compileTestJava/compileTransaction/stash-dir/DeliveryServiceTest.class.uniqueId2 b/build/tmp/compileTestJava/compileTransaction/stash-dir/DeliveryServiceTest.class.uniqueId2 new file mode 100644 index 0000000..10a7449 Binary files /dev/null and b/build/tmp/compileTestJava/compileTransaction/stash-dir/DeliveryServiceTest.class.uniqueId2 differ diff --git a/build/tmp/compileTestJava/compileTransaction/stash-dir/OrderServiceTest.class.uniqueId0 b/build/tmp/compileTestJava/compileTransaction/stash-dir/OrderServiceTest.class.uniqueId0 new file mode 100644 index 0000000..3c7b767 Binary files /dev/null and b/build/tmp/compileTestJava/compileTransaction/stash-dir/OrderServiceTest.class.uniqueId0 differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index bece89c..4016315 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/front/package-lock.json b/front/package-lock.json index 9a2bd13..97271a6 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -21,7 +21,7 @@ "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.19", "globals": "^16.0.0", - "vite": "^6.3.5" + "vite": "^6.4.1" } }, "node_modules/@ampproject/remapping": { @@ -2727,9 +2727,9 @@ } }, "node_modules/vite": { - "version": "6.3.6", - "resolved": "https://registry.npmjs.org/vite/-/vite-6.3.6.tgz", - "integrity": "sha512-0msEVHJEScQbhkbVTb/4iHZdJ6SXp/AvxL2sjwYQFfBqleHtnCqv1J3sa9zbWz/6kW1m9Tfzn92vW+kZ1WV6QA==", + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz", + "integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==", "dev": true, "license": "MIT", "dependencies": { diff --git a/front/package.json b/front/package.json index a809877..52eb587 100644 --- a/front/package.json +++ b/front/package.json @@ -24,6 +24,6 @@ "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.19", "globals": "^16.0.0", - "vite": "^6.3.5" + "vite": "^6.4.1" } } diff --git a/front/src/App.jsx b/front/src/App.jsx index b940c0e..e85dd29 100644 --- a/front/src/App.jsx +++ b/front/src/App.jsx @@ -6,7 +6,7 @@ import OrderList from './components/OrderList'; import './App.css'; function App() { - const [currentView, setCurrentView] = useState('orders'); // 'orders' или 'deliveries' + const [currentView, setCurrentView] = useState('orders'); return (
    diff --git a/front/src/components/DeliveryForm.jsx b/front/src/components/DeliveryForm.jsx index fccfc53..58d677a 100644 --- a/front/src/components/DeliveryForm.jsx +++ b/front/src/components/DeliveryForm.jsx @@ -1,16 +1,21 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect } from 'react' const DeliveryForm = ({ delivery, onSubmit, onCancel }) => { const [formData, setFormData] = useState({ trackingNumber: '', destination: '', status: 'Принято', - customer: '' + customerName: '' }) - useEffect(() => { + useEffect(() => { if (delivery) { - setFormData(delivery) + setFormData({ + trackingNumber: delivery.trackingNumber || '', + destination: delivery.destination || '', + status: delivery.status || 'Принято', + customerName: delivery.customerName || '' + }) } }, [delivery]) @@ -27,7 +32,7 @@ const DeliveryForm = ({ delivery, onSubmit, onCancel }) => { trackingNumber: '', destination: '', status: 'Принято', - customer: '' + customerName: '' }) } } @@ -78,8 +83,8 @@ const DeliveryForm = ({ delivery, onSubmit, onCancel }) => { Клиент: diff --git a/front/src/components/DeliveryItem.jsx b/front/src/components/DeliveryItem.jsx index 831a960..3111086 100644 --- a/front/src/components/DeliveryItem.jsx +++ b/front/src/components/DeliveryItem.jsx @@ -5,13 +5,15 @@ const DeliveryItem = ({ delivery, onEdit, onDelete }) => {

    Направление: {delivery.destination}

    -

    + {} +

    Статус: {delivery.status}

    -

    Клиент: {delivery.customer}

    + {} +

    Клиент: {delivery.customerName || 'Не указан'}

    @@ -22,4 +24,4 @@ const DeliveryItem = ({ delivery, onEdit, onDelete }) => { ); }; -export default DeliveryItem; \ No newline at end of file +export default DeliveryItem; \ No newline at end of file diff --git a/front/src/components/DeliveryList.jsx b/front/src/components/DeliveryList.jsx index c94a8cf..75c9d77 100644 --- a/front/src/components/DeliveryList.jsx +++ b/front/src/components/DeliveryList.jsx @@ -21,6 +21,8 @@ const DeliveryList = () => { } }; + + if (loading) return
    Загрузка данных...
    ; if (error) return
    Ошибка: {error}
    ; @@ -52,6 +54,7 @@ const DeliveryList = () => { )}
    + ); }; diff --git a/front/src/components/OrderFilter.jsx b/front/src/components/OrderFilter.jsx index 9db4894..3e54da6 100644 --- a/front/src/components/OrderFilter.jsx +++ b/front/src/components/OrderFilter.jsx @@ -39,7 +39,7 @@ function OrderFilter({ onFilterChange }) {

    Фильтры и сортировка заказов

    - {/* Фильтр по статусу */} + {}
    - {/* Кнопка сброса */} + {}
    - {/* Показать активные фильтры */} + {} {(filters.status || filters.sortBy !== 'id') && (
    Активно: diff --git a/front/src/components/OrderList.jsx b/front/src/components/OrderList.jsx index d565cf4..1cd4ea0 100644 --- a/front/src/components/OrderList.jsx +++ b/front/src/components/OrderList.jsx @@ -21,23 +21,23 @@ function OrderList() { try { const [ordersRes, customersRes, deliveriesRes] = await Promise.all([ fetch('http://localhost:8080/api/orders'), - fetch('http://localhost:8080/api/customers'), + fetch('http://localhost:8080/api/customers'), fetch('http://localhost:8080/api/deliveries') ]); - + const ordersData = await ordersRes.json(); - const customersData = await customersRes.json(); + const customersData = await customersRes.json(); const deliveriesData = await deliveriesRes.json(); - + setOrders(ordersData); setFilteredOrders(ordersData); - setCustomers(customersData); + setCustomers(customersData); setDeliveries(deliveriesData); } catch (error) { console.error('Ошибка загрузки данных:', error); setOrders([]); setFilteredOrders([]); - setCustomers([]); + setCustomers([]); setDeliveries([]); } finally { setLoading(false); @@ -62,7 +62,7 @@ function OrderList() { const handleCreateOrder = async (orderData) => { try { - // Теперь отправляем OrderRq DTO с customerId и deliveryId + const orderRq = { customerId: orderData.customerId, deliveryId: orderData.deliveryId, @@ -154,7 +154,7 @@ function OrderList() { return (
    -

    📦 Управление заказами

    +

    Управление заказами

    diff --git a/front/src/hooks/useDeliveries.js b/front/src/hooks/useDeliveries.js index 401b9d7..0c9979a 100644 --- a/front/src/hooks/useDeliveries.js +++ b/front/src/hooks/useDeliveries.js @@ -26,11 +26,13 @@ export const useDeliveries = () => { const addDelivery = async (delivery) => { try { + console.log('Sending delivery data:', delivery); const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(delivery) }); + console.log('Response status:', response.status); const newDelivery = await response.json(); setDeliveries(prev => [...prev, newDelivery]); return newDelivery; diff --git a/src/main/java/com/example/controller/CustomerController.java b/src/main/java/com/example/controller/CustomerController.java index 6f7da41..d8f7705 100644 --- a/src/main/java/com/example/controller/CustomerController.java +++ b/src/main/java/com/example/controller/CustomerController.java @@ -10,7 +10,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; -import java.util.Optional; @CrossOrigin(origins = "http://localhost:5173") @RestController @@ -32,9 +31,9 @@ public class CustomerController { @GetMapping("/{id}") @Operation(summary = "Получить клиента по ID") - public ResponseEntity getOne(@PathVariable String id) { - Optional customer = customerService.findById(id); - return customer.map(ResponseEntity::ok) + public ResponseEntity getOne(@PathVariable Long id) { + return customerService.findById(id) + .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @@ -46,16 +45,22 @@ public class CustomerController { @PutMapping("/{id}") @Operation(summary = "Обновить данные клиента") - public ResponseEntity update(@PathVariable String id, @Valid @RequestBody CustomerRq customerRq) { - Optional updated = customerService.update(id, customerRq); - return updated.map(ResponseEntity::ok) + public ResponseEntity update(@PathVariable Long id, @Valid @RequestBody CustomerRq customerRq) { + return customerService.update(id, customerRq) + .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @DeleteMapping("/{id}") @Operation(summary = "Удалить клиента") - public ResponseEntity delete(@PathVariable String id) { + public ResponseEntity delete(@PathVariable Long id) { boolean deleted = customerService.delete(id); return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } + + @GetMapping("/stats/orders") + @Operation(summary = "Получить статистику заказов по клиентам") + public List getCustomerOrderStats() { + return customerService.getCustomerOrderStats(); + } } \ No newline at end of file diff --git a/src/main/java/com/example/controller/DeliveryController.java b/src/main/java/com/example/controller/DeliveryController.java index 89cb37c..04aaa5c 100644 --- a/src/main/java/com/example/controller/DeliveryController.java +++ b/src/main/java/com/example/controller/DeliveryController.java @@ -32,7 +32,7 @@ public class DeliveryController { @GetMapping("/{id}") @Operation(summary = "Получить доставку по ID") - public ResponseEntity getOne(@PathVariable String id) { + public ResponseEntity getOne(@PathVariable Long id) { Optional delivery = deliveryService.findById(id); return delivery.map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); @@ -46,7 +46,7 @@ public class DeliveryController { @PutMapping("/{id}") @Operation(summary = "Обновить данные доставки") - public ResponseEntity update(@PathVariable String id, @Valid @RequestBody DeliveryRq deliveryRq) { + public ResponseEntity update(@PathVariable Long id, @Valid @RequestBody DeliveryRq deliveryRq) { Optional updated = deliveryService.update(id, deliveryRq); return updated.map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); @@ -54,8 +54,21 @@ public class DeliveryController { @DeleteMapping("/{id}") @Operation(summary = "Удалить доставку") - public ResponseEntity delete(@PathVariable String id) { + public ResponseEntity delete(@PathVariable Long id) { boolean deleted = deliveryService.delete(id); return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } + + @GetMapping("/stats/status") + @Operation(summary = "Получить статистику доставок по статусам") + public List getDeliveryStatusStats() { + return deliveryService.getDeliveryStatusStats(); +} + + @GetMapping("/search/city/{city}") + @Operation(summary = "Найти доставки по городу") + public List getDeliveriesByCity(@PathVariable String city) { + + return deliveryService.findByCity(city); + } } \ No newline at end of file diff --git a/src/main/java/com/example/controller/OrderController.java b/src/main/java/com/example/controller/OrderController.java index 71b75d4..3774399 100644 --- a/src/main/java/com/example/controller/OrderController.java +++ b/src/main/java/com/example/controller/OrderController.java @@ -32,7 +32,7 @@ public class OrderController { @GetMapping("/{id}") @Operation(summary = "Получить заказ по ID") - public ResponseEntity getOne(@PathVariable String id) { + public ResponseEntity getOne(@PathVariable Long id) { Optional order = orderService.findById(id); return order.map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); @@ -40,7 +40,7 @@ public class OrderController { @GetMapping("/customer/{customerId}") @Operation(summary = "Получить заказы по ID клиента") - public List getByCustomer(@PathVariable String customerId) { + public List getByCustomer(@PathVariable Long customerId) { return orderService.findByCustomerId(customerId); } @@ -63,7 +63,7 @@ public class OrderController { @PutMapping("/{id}") @Operation(summary = "Обновить заказ") - public ResponseEntity update(@PathVariable String id, @Valid @RequestBody OrderRq orderRq) { + public ResponseEntity update(@PathVariable Long id, @Valid @RequestBody OrderRq orderRq) { try { Optional updated = orderService.update(id, orderRq); return updated.map(ResponseEntity::ok) @@ -75,8 +75,20 @@ public class OrderController { @DeleteMapping("/{id}") @Operation(summary = "Удалить заказ") - public ResponseEntity delete(@PathVariable String id) { + public ResponseEntity delete(@PathVariable Long id) { boolean deleted = orderService.delete(id); return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } + + @GetMapping("/stats/monthly") + @Operation(summary = "Получить месячную статистику заказов") + public List getOrderMonthlyStats() { + return orderService.getOrderMonthlyStats(); +} + + @GetMapping("/stats/status") + @Operation(summary = "Получить статистику заказов по статусам") + public List getOrderStatusStats() { + return orderService.getOrderStatusStats(); +} } \ No newline at end of file diff --git a/src/main/java/com/example/dto/CustomerRq.java b/src/main/java/com/example/dto/CustomerRq.java index d6cc155..a60696e 100644 --- a/src/main/java/com/example/dto/CustomerRq.java +++ b/src/main/java/com/example/dto/CustomerRq.java @@ -14,7 +14,7 @@ public class CustomerRq { public CustomerRq() {} - public CustomerRq(String name, String email) { + public CustomerRq(String name, String email) { this.name = name; this.email = email; } diff --git a/src/main/java/com/example/dto/CustomerRs.java b/src/main/java/com/example/dto/CustomerRs.java index abd5211..ea80fe2 100644 --- a/src/main/java/com/example/dto/CustomerRs.java +++ b/src/main/java/com/example/dto/CustomerRs.java @@ -3,15 +3,15 @@ package com.example.dto; import java.time.LocalDateTime; public class CustomerRs { - private String id; + private Long id; private String name; private String email; private LocalDateTime createdAt; private LocalDateTime updatedAt; - public String getId() { return id; } - public void setId(String id) { this.id = id; } + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } diff --git a/src/main/java/com/example/dto/DeliveryRq.java b/src/main/java/com/example/dto/DeliveryRq.java index 93d5d53..1aecf92 100644 --- a/src/main/java/com/example/dto/DeliveryRq.java +++ b/src/main/java/com/example/dto/DeliveryRq.java @@ -12,8 +12,20 @@ public class DeliveryRq { @NotBlank(message = "Статус обязателен") private String status; - private String customer; + @NotBlank(message = "Имя клиента обязательно") + private String customerName; + + public DeliveryRq() {} + + public DeliveryRq(String trackingNumber, String destination, String status, String customerName) { + this.trackingNumber = trackingNumber; + this.destination = destination; + this.status = status; + this.customerName = customerName; + } + + public String getTrackingNumber() { return trackingNumber; } public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } @@ -23,15 +35,6 @@ public class DeliveryRq { public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } - public String getCustomer() { return customer; } - public void setCustomer(String customer) { this.customer = customer; } - - public DeliveryRq() {} - - public DeliveryRq(String trackingNumber, String destination, String status, String customer) { - this.trackingNumber = trackingNumber; - this.destination = destination; - this.status = status; - this.customer = customer; - } + public String getCustomerName() { return customerName; } + public void setCustomerName(String customerName) { this.customerName = customerName; } } \ No newline at end of file diff --git a/src/main/java/com/example/dto/DeliveryRs.java b/src/main/java/com/example/dto/DeliveryRs.java index 5081953..b4e055a 100644 --- a/src/main/java/com/example/dto/DeliveryRs.java +++ b/src/main/java/com/example/dto/DeliveryRs.java @@ -3,17 +3,17 @@ package com.example.dto; import java.time.LocalDateTime; public class DeliveryRs { - private String id; + private Long id; private String trackingNumber; private String destination; private String status; - private String customer; + private String customerName; private LocalDateTime createdAt; private LocalDateTime updatedAt; - public String getId() { return id; } - public void setId(String id) { this.id = id; } + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } public String getTrackingNumber() { return trackingNumber; } public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } @@ -24,8 +24,8 @@ public class DeliveryRs { public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } - public String getCustomer() { return customer; } - public void setCustomer(String customer) { this.customer = customer; } + public String getCustomerName() { return customerName; } + public void setCustomerName(String customerName) { this.customerName = customerName; } public LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } diff --git a/src/main/java/com/example/dto/OrderRq.java b/src/main/java/com/example/dto/OrderRq.java index 1c046be..c00b0a4 100644 --- a/src/main/java/com/example/dto/OrderRq.java +++ b/src/main/java/com/example/dto/OrderRq.java @@ -1,32 +1,33 @@ package com.example.dto; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; public class OrderRq { - @NotBlank(message = "ID клиента обязателен") - private String customerId; + @NotNull(message = "ID клиента обязателен") + private Long customerId; - @NotBlank(message = "ID доставки обязателен") - private String deliveryId; + @NotNull(message = "ID доставки обязателен") + private Long deliveryId; - @NotBlank(message = "Статус обязателен") + @NotNull(message = "Статус обязателен") private String status; - public String getCustomerId() { return customerId; } - public void setCustomerId(String customerId) { this.customerId = customerId; } - public String getDeliveryId() { return deliveryId; } - public void setDeliveryId(String deliveryId) { this.deliveryId = deliveryId; } - - public String getStatus() { return status; } - public void setStatus(String status) { this.status = status; } - public OrderRq() {} - public OrderRq(String customerId, String deliveryId, String status) { + public OrderRq(Long customerId, Long deliveryId, String status) { this.customerId = customerId; this.deliveryId = deliveryId; this.status = status; } + + + public Long getCustomerId() { return customerId; } + public void setCustomerId(Long customerId) { this.customerId = customerId; } + + public Long getDeliveryId() { return deliveryId; } + public void setDeliveryId(Long deliveryId) { this.deliveryId = deliveryId; } + + public String getStatus() { return status; } + public void setStatus(String status) { this.status = status; } } \ No newline at end of file diff --git a/src/main/java/com/example/dto/OrderRs.java b/src/main/java/com/example/dto/OrderRs.java index 41149c2..08f4b47 100644 --- a/src/main/java/com/example/dto/OrderRs.java +++ b/src/main/java/com/example/dto/OrderRs.java @@ -3,7 +3,7 @@ package com.example.dto; import java.time.LocalDateTime; public class OrderRs { - private String id; + private Long id; private CustomerRs customer; private DeliveryRs delivery; private String status; @@ -11,8 +11,8 @@ public class OrderRs { private LocalDateTime updatedAt; - public String getId() { return id; } - public void setId(String id) { this.id = id; } + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } public CustomerRs getCustomer() { return customer; } public void setCustomer(CustomerRs customer) { this.customer = customer; } diff --git a/src/main/java/com/example/entity/BaseEntity.java b/src/main/java/com/example/entity/BaseEntity.java index 0c57fb4..5184a72 100644 --- a/src/main/java/com/example/entity/BaseEntity.java +++ b/src/main/java/com/example/entity/BaseEntity.java @@ -1,24 +1,40 @@ package com.example.entity; +import jakarta.persistence.*; + import java.time.LocalDateTime; +@MappedSuperclass public abstract class BaseEntity { - protected String id; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + protected Long id; + + @Column(name = "created_at", nullable = false, updatable = false) protected LocalDateTime createdAt; + + @Column(name = "updated_at", nullable = false) protected LocalDateTime updatedAt; - public BaseEntity() { - this.createdAt = LocalDateTime.now(); - this.updatedAt = LocalDateTime.now(); + @PrePersist + protected void onCreate() { + createdAt = LocalDateTime.now(); + updatedAt = LocalDateTime.now(); } - public String getId() { + @PreUpdate + protected void onUpdate() { + updatedAt = LocalDateTime.now(); + } + + + public Long getId() { return id; } - public void setId(String id) { + public void setId(Long id) { this.id = id; - this.updatedAt = LocalDateTime.now(); } public LocalDateTime getCreatedAt() { @@ -36,5 +52,4 @@ public abstract class BaseEntity { public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } - } \ No newline at end of file diff --git a/src/main/java/com/example/entity/Customer.java b/src/main/java/com/example/entity/Customer.java index 648e346..d79dfc3 100644 --- a/src/main/java/com/example/entity/Customer.java +++ b/src/main/java/com/example/entity/Customer.java @@ -1,13 +1,24 @@ package com.example.entity; +import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; +@Entity +@Table(name = "customers") public class Customer extends BaseEntity { + + @Column(name = "name", nullable = false) private String name; + + @Column(name = "email", nullable = false, unique = true) private String email; + + + @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List orders = new ArrayList<>(); + public Customer() {} public Customer(String name, String email) { @@ -15,6 +26,7 @@ public class Customer extends BaseEntity { this.email = email; } + public String getName() { return name; } public void setName(String name) { this.name = name; } @@ -23,5 +35,15 @@ public class Customer extends BaseEntity { public List getOrders() { return orders; } public void setOrders(List orders) { this.orders = orders; } - public void addOrder(Order order) { this.orders.add(order); } + + + public void addOrder(Order order) { + orders.add(order); + order.setCustomer(this); + } + + public void removeOrder(Order order) { + orders.remove(order); + order.setCustomer(null); + } } \ No newline at end of file diff --git a/src/main/java/com/example/entity/Delivery.java b/src/main/java/com/example/entity/Delivery.java index 7ff23dc..d7cfd72 100644 --- a/src/main/java/com/example/entity/Delivery.java +++ b/src/main/java/com/example/entity/Delivery.java @@ -1,20 +1,40 @@ package com.example.entity; -public class Delivery extends BaseEntity { - private String trackingNumber; - private String destination; - private String status; - private String customer; +import jakarta.persistence.*; +import java.util.ArrayList; +import java.util.List; +@Entity +@Table(name = "deliveries") +public class Delivery extends BaseEntity { + + @Column(name = "tracking_number", nullable = false, unique = true) + private String trackingNumber; + + @Column(name = "destination", nullable = false) + private String destination; + + @Column(name = "status", nullable = false) + private String status; + + @Column(name = "customer_name") + private String customerName; + + + @OneToMany(mappedBy = "delivery", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List orders = new ArrayList<>(); + + public Delivery() {} - public Delivery(String trackingNumber, String destination, String status, String customer) { + public Delivery(String trackingNumber, String destination, String status, String customerName) { this.trackingNumber = trackingNumber; this.destination = destination; this.status = status; - this.customer = customer; + this.customerName = customerName; } + public String getTrackingNumber() { return trackingNumber; } public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } @@ -24,6 +44,20 @@ public class Delivery extends BaseEntity { public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } - public String getCustomer() { return customer; } - public void setCustomer(String customer) { this.customer = customer; } + public String getCustomerName() { return customerName; } + public void setCustomerName(String customerName) { this.customerName = customerName; } + + public List getOrders() { return orders; } + public void setOrders(List orders) { this.orders = orders; } + + + public void addOrder(Order order) { + orders.add(order); + order.setDelivery(this); + } + + public void removeOrder(Order order) { + orders.remove(order); + order.setDelivery(null); + } } \ No newline at end of file diff --git a/src/main/java/com/example/entity/Order.java b/src/main/java/com/example/entity/Order.java index b221274..346b234 100644 --- a/src/main/java/com/example/entity/Order.java +++ b/src/main/java/com/example/entity/Order.java @@ -1,8 +1,22 @@ package com.example.entity; +import jakarta.persistence.*; + +@Entity +@Table(name = "orders") public class Order extends BaseEntity { - private Customer customer; - private Delivery delivery; + + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "customer_id", nullable = false) + private Customer customer; + + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "delivery_id", nullable = false) + private Delivery delivery; + + @Column(name = "status", nullable = false) private String status; @@ -14,12 +28,61 @@ public class Order extends BaseEntity { this.status = status; } - public Customer getCustomer() { return customer; } - public void setCustomer(Customer customer) { this.customer = customer; } - public Delivery getDelivery() { return delivery; } - public void setDelivery(Delivery delivery) { this.delivery = delivery; } + public Customer getCustomer() { + return customer; + } - public String getStatus() { return status; } - public void setStatus(String status) { this.status = status; } + public void setCustomer(Customer customer) { + this.customer = customer; + + if (customer != null && !customer.getOrders().contains(this)) { + customer.getOrders().add(this); + } + } + + public Delivery getDelivery() { + return delivery; + } + + public void setDelivery(Delivery delivery) { + this.delivery = delivery; + + if (delivery != null && !delivery.getOrders().contains(this)) { + delivery.getOrders().add(this); + } + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + + @Override + public String toString() { + return "Order{" + + "id=" + getId() + + ", customer=" + (customer != null ? customer.getName() : "null") + + ", delivery=" + (delivery != null ? delivery.getTrackingNumber() : "null") + + ", status='" + status + '\'' + + ", createdAt=" + getCreatedAt() + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Order)) return false; + Order order = (Order) o; + return getId() != null && getId().equals(order.getId()); + } + + @Override + public int hashCode() { + return getClass().hashCode(); + } } \ No newline at end of file diff --git a/src/main/java/com/example/mapper/DeliveryMapper.java b/src/main/java/com/example/mapper/DeliveryMapper.java index 3454a1c..e1ccc23 100644 --- a/src/main/java/com/example/mapper/DeliveryMapper.java +++ b/src/main/java/com/example/mapper/DeliveryMapper.java @@ -13,7 +13,7 @@ public class DeliveryMapper { delivery.setTrackingNumber(deliveryRq.getTrackingNumber()); delivery.setDestination(deliveryRq.getDestination()); delivery.setStatus(deliveryRq.getStatus()); - delivery.setCustomer(deliveryRq.getCustomer()); + delivery.setCustomerName(deliveryRq.getCustomerName()); return delivery; } @@ -23,7 +23,7 @@ public class DeliveryMapper { deliveryRs.setTrackingNumber(delivery.getTrackingNumber()); deliveryRs.setDestination(delivery.getDestination()); deliveryRs.setStatus(delivery.getStatus()); - deliveryRs.setCustomer(delivery.getCustomer()); + deliveryRs.setCustomerName(delivery.getCustomerName()); deliveryRs.setCreatedAt(delivery.getCreatedAt()); deliveryRs.setUpdatedAt(delivery.getUpdatedAt()); return deliveryRs; diff --git a/src/main/java/com/example/mapper/OrderMapper.java b/src/main/java/com/example/mapper/OrderMapper.java index 4a2bbc4..5751ba1 100644 --- a/src/main/java/com/example/mapper/OrderMapper.java +++ b/src/main/java/com/example/mapper/OrderMapper.java @@ -3,6 +3,8 @@ package com.example.mapper; import com.example.entity.Order; import com.example.dto.OrderRq; import com.example.dto.OrderRs; +import com.example.dto.CustomerRs; +import com.example.dto.DeliveryRs; import org.springframework.stereotype.Component; @Component @@ -10,7 +12,6 @@ public class OrderMapper { public Order toEntity(OrderRq orderRq) { Order order = new Order(); - order.setStatus(orderRq.getStatus()); return order; } @@ -21,6 +22,30 @@ public class OrderMapper { orderRs.setStatus(order.getStatus()); orderRs.setCreatedAt(order.getCreatedAt()); orderRs.setUpdatedAt(order.getUpdatedAt()); + + + if (order.getCustomer() != null) { + CustomerRs customerRs = new CustomerRs(); + customerRs.setId(order.getCustomer().getId()); + customerRs.setName(order.getCustomer().getName()); + customerRs.setEmail(order.getCustomer().getEmail()); + customerRs.setCreatedAt(order.getCustomer().getCreatedAt()); + customerRs.setUpdatedAt(order.getCustomer().getUpdatedAt()); + orderRs.setCustomer(customerRs); + } + + if (order.getDelivery() != null) { + DeliveryRs deliveryRs = new DeliveryRs(); + deliveryRs.setId(order.getDelivery().getId()); + deliveryRs.setTrackingNumber(order.getDelivery().getTrackingNumber()); + deliveryRs.setDestination(order.getDelivery().getDestination()); + deliveryRs.setStatus(order.getDelivery().getStatus()); + deliveryRs.setCustomerName(order.getDelivery().getCustomerName()); + deliveryRs.setCreatedAt(order.getDelivery().getCreatedAt()); + deliveryRs.setUpdatedAt(order.getDelivery().getUpdatedAt()); + orderRs.setDelivery(deliveryRs); + } + return orderRs; } } \ No newline at end of file diff --git a/src/main/java/com/example/repository/CommonRepository.java b/src/main/java/com/example/repository/CommonRepository.java deleted file mode 100644 index cb059b9..0000000 --- a/src/main/java/com/example/repository/CommonRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example.repository; - -import java.util.List; -import java.util.Optional; - -public interface CommonRepository { - List findAll(); - Optional findById(String id); - T save(T entity); - void deleteById(String id); - boolean existsById(String id); -} \ No newline at end of file diff --git a/src/main/java/com/example/repository/CustomerRepository.java b/src/main/java/com/example/repository/CustomerRepository.java index 88569d6..cd4ac3b 100644 --- a/src/main/java/com/example/repository/CustomerRepository.java +++ b/src/main/java/com/example/repository/CustomerRepository.java @@ -1,15 +1,34 @@ package com.example.repository; import com.example.entity.Customer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository -public class CustomerRepository extends MapRepository { - public Optional findByEmail(String email) { - return storage.values().stream() - .filter(customer -> customer.getEmail().equals(email)) - .findFirst(); +public interface CustomerRepository extends JpaRepository { + + Optional findByEmail(String email); + + List findByNameContainingIgnoreCase(String name); + + + @Query("SELECT c.name as customerName, COUNT(o.id) as orderCount " + + "FROM Customer c LEFT JOIN c.orders o " + + "GROUP BY c.id, c.name " + + "ORDER BY orderCount DESC") + List findCustomerOrderStats(); + + interface CustomerOrderStats { + String getCustomerName(); + Long getOrderCount(); } + + + @Query("SELECT c FROM Customer c WHERE SIZE(c.orders) >= :minOrders") + List findCustomersWithMinOrders(@Param("minOrders") int minOrders); } \ No newline at end of file diff --git a/src/main/java/com/example/repository/DeliveryRepository.java b/src/main/java/com/example/repository/DeliveryRepository.java index 4c8727c..f480f81 100644 --- a/src/main/java/com/example/repository/DeliveryRepository.java +++ b/src/main/java/com/example/repository/DeliveryRepository.java @@ -1,15 +1,32 @@ package com.example.repository; import com.example.entity.Delivery; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository -public class DeliveryRepository extends MapRepository { - public Optional findByTrackingNumber(String trackingNumber) { - return storage.values().stream() - .filter(delivery -> delivery.getTrackingNumber().equals(trackingNumber)) - .findFirst(); +public interface DeliveryRepository extends JpaRepository { + + Optional findByTrackingNumber(String trackingNumber); + + List findByStatus(String status); + + + @Query("SELECT d.status as deliveryStatus, COUNT(d.id) as count " + + "FROM Delivery d GROUP BY d.status ORDER BY count DESC") + List findDeliveryStatusStats(); + + interface DeliveryStatusStats { + String getDeliveryStatus(); + Long getCount(); } + + + @Query("SELECT d FROM Delivery d WHERE d.destination LIKE %:city%") + List findDeliveriesByCity(@Param("city") String city); } \ No newline at end of file diff --git a/src/main/java/com/example/repository/MapRepository.java b/src/main/java/com/example/repository/MapRepository.java deleted file mode 100644 index e72b22d..0000000 --- a/src/main/java/com/example/repository/MapRepository.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.example.repository; - -import com.example.entity.BaseEntity; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - -public abstract class MapRepository implements CommonRepository { - protected final ConcurrentHashMap storage = new ConcurrentHashMap<>(); - protected final AtomicLong idCounter = new AtomicLong(1); - - @Override - public List findAll() { - return new ArrayList<>(storage.values()); - } - - @Override - public Optional findById(String id) { - return Optional.ofNullable(storage.get(id)); - } - - @Override - public T save(T entity) { - if (entity.getId() == null) { - - entity.setId(String.valueOf(idCounter.getAndIncrement())); - entity.setCreatedAt(java.time.LocalDateTime.now()); - } - - entity.setUpdatedAt(java.time.LocalDateTime.now()); - storage.put(entity.getId(), entity); - return entity; - } - - @Override - public void deleteById(String id) { - storage.remove(id); - } - - @Override - public boolean existsById(String id) { - return storage.containsKey(id); - } -} \ No newline at end of file diff --git a/src/main/java/com/example/repository/OrderRepository.java b/src/main/java/com/example/repository/OrderRepository.java index 8d7be90..31e63b3 100644 --- a/src/main/java/com/example/repository/OrderRepository.java +++ b/src/main/java/com/example/repository/OrderRepository.java @@ -1,29 +1,49 @@ package com.example.repository; import com.example.entity.Order; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; -import java.util.Optional; @Repository -public class OrderRepository extends MapRepository { +public interface OrderRepository extends JpaRepository { - public List findByCustomerId(String customerId) { - return storage.values().stream() - .filter(order -> order.getCustomer().getId().equals(customerId)) - .toList(); + List findByCustomerId(Long customerId); + + List findByDeliveryId(Long deliveryId); + + List findByStatus(String status); + + + @Query("SELECT MONTH(o.createdAt) as month, " + + "COUNT(o.id) as orderCount " + + "FROM Order o " + + "GROUP BY MONTH(o.createdAt) " + + "ORDER BY month") + List findOrderMonthlyStats(); + + interface OrderMonthlyStats { + Integer getMonth(); + Long getOrderCount(); } - public List findByDeliveryId(String deliveryId) { - return storage.values().stream() - .filter(order -> order.getDelivery().getId().equals(deliveryId)) - .toList(); + + @Query("SELECT o.status as status, " + + "COUNT(o.id) as total " + + "FROM Order o " + + "GROUP BY o.status") + List findOrderStatusStats(); + + interface OrderStatusStats { + String getStatus(); + Long getTotal(); } - public List findByStatus(String status) { - return storage.values().stream() - .filter(order -> order.getStatus().equals(status)) - .toList(); - } + + @Query("SELECT o FROM Order o WHERE o.customer.id = :customerId AND o.status = :status") + List findCustomerOrdersByStatus(@Param("customerId") Long customerId, + @Param("status") String status); } \ No newline at end of file diff --git a/src/main/java/com/example/service/CustomerService.java b/src/main/java/com/example/service/CustomerService.java index 7a57710..ded7e0e 100644 --- a/src/main/java/com/example/service/CustomerService.java +++ b/src/main/java/com/example/service/CustomerService.java @@ -1,16 +1,18 @@ package com.example.service; -import com.example.entity.Customer; import com.example.dto.CustomerRq; import com.example.dto.CustomerRs; +import com.example.entity.Customer; import com.example.mapper.CustomerMapper; import com.example.repository.CustomerRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; @Service +@Transactional public class CustomerService { private final CustomerRepository customerRepository; @@ -19,40 +21,49 @@ public class CustomerService { public CustomerService(CustomerRepository customerRepository, CustomerMapper customerMapper) { this.customerRepository = customerRepository; this.customerMapper = customerMapper; - initializeTestData(); - } - - private void initializeTestData() { - if (customerRepository.findAll().isEmpty()) { - Customer customer1 = new Customer("Иванов Иван", "ivanov@example.com"); - Customer customer2 = new Customer("Петров Петр", "petrov@example.com"); - Customer customer3 = new Customer("Олег Андреевич", "oleg@example.com"); - customerRepository.save(customer1); - customerRepository.save(customer2); - customerRepository.save(customer3); - } } + @Transactional(readOnly = true) public List findAll() { return customerRepository.findAll().stream() .map(customerMapper::toResponse) .toList(); } - public Optional findById(String id) { + @Transactional(readOnly = true) + public Optional findById(Long id) { return customerRepository.findById(id) .map(customerMapper::toResponse); } + @Transactional(readOnly = true) + public Optional findByEmail(String email) { + return customerRepository.findByEmail(email); + } + + @Transactional(readOnly = true) + public List findByNameContaining(String name) { + return customerRepository.findByNameContainingIgnoreCase(name); + } + public CustomerRs create(CustomerRq customerRq) { + if (customerRepository.findByEmail(customerRq.getEmail()).isPresent()) { + throw new IllegalArgumentException("Customer with email " + customerRq.getEmail() + " already exists"); + } + Customer customer = customerMapper.toEntity(customerRq); Customer saved = customerRepository.save(customer); return customerMapper.toResponse(saved); } - public Optional update(String id, CustomerRq customerRq) { + public Optional update(Long id, CustomerRq customerRq) { return customerRepository.findById(id) .map(customer -> { + if (!customer.getEmail().equals(customerRq.getEmail()) && + customerRepository.findByEmail(customerRq.getEmail()).isPresent()) { + throw new IllegalArgumentException("Customer with email " + customerRq.getEmail() + " already exists"); + } + customer.setName(customerRq.getName()); customer.setEmail(customerRq.getEmail()); Customer updated = customerRepository.save(customer); @@ -60,11 +71,32 @@ public class CustomerService { }); } - public boolean delete(String id) { + public boolean delete(Long id) { if (customerRepository.existsById(id)) { customerRepository.deleteById(id); return true; } return false; } + + @Transactional(readOnly = true) + public List getCustomerOrderStats() { + List repoStats = customerRepository.findCustomerOrderStats(); + + return repoStats.stream() + .map(stat -> new CustomerOrderStats(stat.getCustomerName(), stat.getOrderCount())) + .toList(); + } + + public record CustomerOrderStats(String customerName, Long orderCount) {} + + @Transactional(readOnly = true) + public List getCustomersWithMinOrders(int minOrders) { + return customerRepository.findCustomersWithMinOrders(minOrders); + } + + @Transactional(readOnly = true) + public long countCustomers() { + return customerRepository.count(); + } } \ No newline at end of file diff --git a/src/main/java/com/example/service/DeliveryService.java b/src/main/java/com/example/service/DeliveryService.java index db8115d..88a5901 100644 --- a/src/main/java/com/example/service/DeliveryService.java +++ b/src/main/java/com/example/service/DeliveryService.java @@ -1,16 +1,18 @@ package com.example.service; -import com.example.entity.Delivery; import com.example.dto.DeliveryRq; import com.example.dto.DeliveryRs; +import com.example.entity.Delivery; import com.example.mapper.DeliveryMapper; import com.example.repository.DeliveryRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; @Service +@Transactional public class DeliveryService { private final DeliveryRepository deliveryRepository; @@ -19,25 +21,17 @@ public class DeliveryService { public DeliveryService(DeliveryRepository deliveryRepository, DeliveryMapper deliveryMapper) { this.deliveryRepository = deliveryRepository; this.deliveryMapper = deliveryMapper; - initializeTestData(); - } - - private void initializeTestData() { - if (deliveryRepository.findAll().isEmpty()) { - Delivery delivery1 = new Delivery("IVN012021", "гоголя10", "Доставлено", "Парт петрович wwww"); - Delivery delivery2 = new Delivery("IVN123456", "Москва", "В пути", "1Иванов Иван"); - deliveryRepository.save(delivery1); - deliveryRepository.save(delivery2); - } } + @Transactional(readOnly = true) public List findAll() { return deliveryRepository.findAll().stream() .map(deliveryMapper::toResponse) .toList(); } - public Optional findById(String id) { + @Transactional(readOnly = true) + public Optional findById(Long id) { return deliveryRepository.findById(id) .map(deliveryMapper::toResponse); } @@ -48,23 +42,58 @@ public class DeliveryService { return deliveryMapper.toResponse(saved); } - public Optional update(String id, DeliveryRq deliveryRq) { + public Optional update(Long id, DeliveryRq deliveryRq) { return deliveryRepository.findById(id) .map(delivery -> { delivery.setTrackingNumber(deliveryRq.getTrackingNumber()); delivery.setDestination(deliveryRq.getDestination()); delivery.setStatus(deliveryRq.getStatus()); - delivery.setCustomer(deliveryRq.getCustomer()); + delivery.setCustomerName(deliveryRq.getCustomerName()); Delivery updated = deliveryRepository.save(delivery); return deliveryMapper.toResponse(updated); }); } - public boolean delete(String id) { + public boolean delete(Long id) { if (deliveryRepository.existsById(id)) { deliveryRepository.deleteById(id); return true; } return false; } + + @Transactional(readOnly = true) + public List getDeliveryStatusStats() { + List repoStats = deliveryRepository.findDeliveryStatusStats(); + + return repoStats.stream() + .map(stat -> new DeliveryStatusStats(stat.getDeliveryStatus(), stat.getCount())) + .toList(); + } + + public record DeliveryStatusStats(String deliveryStatus, Long count) {} + + @Transactional(readOnly = true) + public List findByCity(String city) { + return deliveryRepository.findDeliveriesByCity(city).stream() + .map(deliveryMapper::toResponse) + .toList(); + } + + @Transactional(readOnly = true) + public Optional findByTrackingNumber(String trackingNumber) { + return deliveryRepository.findByTrackingNumber(trackingNumber); + } + + @Transactional(readOnly = true) + public List findByStatus(String status) { + return deliveryRepository.findByStatus(status).stream() + .map(deliveryMapper::toResponse) + .toList(); + } + + @Transactional(readOnly = true) + public long countDeliveries() { + return deliveryRepository.count(); + } } \ No newline at end of file diff --git a/src/main/java/com/example/service/OrderService.java b/src/main/java/com/example/service/OrderService.java index 317b161..78061a7 100644 --- a/src/main/java/com/example/service/OrderService.java +++ b/src/main/java/com/example/service/OrderService.java @@ -1,20 +1,22 @@ package com.example.service; -import com.example.entity.Order; -import com.example.entity.Customer; -import com.example.entity.Delivery; import com.example.dto.OrderRq; import com.example.dto.OrderRs; +import com.example.entity.Customer; +import com.example.entity.Delivery; +import com.example.entity.Order; import com.example.mapper.OrderMapper; -import com.example.repository.OrderRepository; import com.example.repository.CustomerRepository; import com.example.repository.DeliveryRepository; +import com.example.repository.OrderRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; @Service +@Transactional public class OrderService { private final OrderRepository orderRepository; @@ -30,40 +32,36 @@ public class OrderService { this.customerRepository = customerRepository; this.deliveryRepository = deliveryRepository; this.orderMapper = orderMapper; - initializeTestData(); - } - - private void initializeTestData() { - if (orderRepository.findAll().isEmpty()) { - List customers = customerRepository.findAll(); - List deliveries = deliveryRepository.findAll(); - - if (!customers.isEmpty() && !deliveries.isEmpty()) { - Order order1 = new Order(customers.get(0), deliveries.get(0), "Доставлено"); - Order order2 = new Order(customers.get(1), deliveries.get(1), "В пути"); - orderRepository.save(order1); - orderRepository.save(order2); - } - } } + @Transactional(readOnly = true) public List findAll() { return orderRepository.findAll().stream() .map(orderMapper::toResponse) .toList(); } - public Optional findById(String id) { + @Transactional(readOnly = true) + public Optional findById(Long id) { return orderRepository.findById(id) .map(orderMapper::toResponse); } - public List findByCustomerId(String customerId) { + @Transactional(readOnly = true) + public List findByCustomerId(Long customerId) { return orderRepository.findByCustomerId(customerId).stream() .map(orderMapper::toResponse) .toList(); } + @Transactional(readOnly = true) + public List findByDeliveryId(Long deliveryId) { + return orderRepository.findByDeliveryId(deliveryId).stream() + .map(orderMapper::toResponse) + .toList(); + } + + @Transactional(readOnly = true) public List findByStatus(String status) { return orderRepository.findByStatus(status).stream() .map(orderMapper::toResponse) @@ -71,26 +69,80 @@ public class OrderService { } public OrderRs create(OrderRq orderRq) { + Customer customer = customerRepository.findById(orderRq.getCustomerId()) + .orElseThrow(() -> new IllegalArgumentException("Customer not found with id: " + orderRq.getCustomerId())); + + Delivery delivery = deliveryRepository.findById(orderRq.getDeliveryId()) + .orElseThrow(() -> new IllegalArgumentException("Delivery not found with id: " + orderRq.getDeliveryId())); + Order order = orderMapper.toEntity(orderRq); + order.setCustomer(customer); + order.setDelivery(delivery); + Order saved = orderRepository.save(order); return orderMapper.toResponse(saved); } - public Optional update(String id, OrderRq orderRq) { + public Optional update(Long id, OrderRq orderRq) { return orderRepository.findById(id) .map(order -> { - Order updatedOrder = orderMapper.toEntity(orderRq); - updatedOrder.setId(id); - Order saved = orderRepository.save(updatedOrder); - return orderMapper.toResponse(saved); + Customer customer = customerRepository.findById(orderRq.getCustomerId()) + .orElseThrow(() -> new IllegalArgumentException("Customer not found with id: " + orderRq.getCustomerId())); + + Delivery delivery = deliveryRepository.findById(orderRq.getDeliveryId()) + .orElseThrow(() -> new IllegalArgumentException("Delivery not found with id: " + orderRq.getDeliveryId())); + + order.setCustomer(customer); + order.setDelivery(delivery); + order.setStatus(orderRq.getStatus()); + + Order updated = orderRepository.save(order); + return orderMapper.toResponse(updated); }); } - public boolean delete(String id) { + public boolean delete(Long id) { if (orderRepository.existsById(id)) { orderRepository.deleteById(id); return true; } return false; } + + @Transactional(readOnly = true) + public List getOrderMonthlyStats() { + List repoStats = orderRepository.findOrderMonthlyStats(); + + return repoStats.stream() + .map(stat -> new OrderMonthlyStats(stat.getMonth(), stat.getOrderCount())) + .toList(); + } + + public record OrderMonthlyStats(Integer month, Long orderCount) {} + + @Transactional(readOnly = true) + public List getOrderStatusStats() { + List repoStats = orderRepository.findOrderStatusStats(); + + return repoStats.stream() + .map(stat -> new OrderStatusStats(stat.getStatus(), stat.getTotal())) + .toList(); + } + + public record OrderStatusStats(String status, Long total) {} + + @Transactional(readOnly = true) + public List getCustomerOrdersByStatus(Long customerId, String status) { + return orderRepository.findCustomerOrdersByStatus(customerId, status); + } + + @Transactional(readOnly = true) + public long countOrders() { + return orderRepository.count(); + } + + @Transactional(readOnly = true) + public long countOrdersByStatus(String status) { + return orderRepository.findByStatus(status).size(); + } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2109a44..7c5c9e9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,22 @@ -spring.application.name=demo +# H2 Database Configuration +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +# JPA Configuration +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +# H2 Console (для просмотра базы в браузере) +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +# Включить инициализацию данных +spring.sql.init.mode=always +spring.jpa.defer-datasource-initialization=true + +# Server Configuration +server.port=8080 \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 0000000..01839c6 --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,14 @@ +-- Тестовые клиенты +INSERT INTO customers (id, name, email, created_at, updated_at) +VALUES +(1, 'Иван Иванов', 'ivan@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(2, 'Петр Петров', 'petr@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(3, 'Мария Сидорова', 'maria@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(4, 'Алексей Козлов', 'alex@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(5, 'Ольга Новикова', 'olga@mail.ru', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + +-- Тестовые доставки (опционально) +INSERT INTO deliveries (id, tracking_number, destination, status, customer_name, created_at, updated_at) +VALUES +(1, 'IVN777777', 'гоголя 34', 'В пути', 'Иван Иванов', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), +(2, 'IVN012021', 'Москва', 'Принято', 'Петр Петров', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); \ No newline at end of file diff --git a/src/test/java/com/example/service/CustomerServiceIntegrationTest.java b/src/test/java/com/example/service/CustomerServiceIntegrationTest.java deleted file mode 100644 index bdbc20f..0000000 --- a/src/test/java/com/example/service/CustomerServiceIntegrationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.example.service; - -import com.example.dto.CustomerRq; -import com.example.dto.CustomerRs; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class CustomerServiceIntegrationTest { - - @Autowired - private CustomerService customerService; - - @Test - void getTest_WhenCustomerNotExists_ShouldThrowException() { - - assertThrows(RuntimeException.class, () -> - customerService.findById("non-existent-id").orElseThrow(() -> new RuntimeException("Not found"))); - } - - @Test - void createTest() { - - int initialCount = customerService.findAll().size(); - - - CustomerRq customerRq1 = new CustomerRq(); - customerRq1.setName("ПИбд-31"); - customerRq1.setEmail("pi31@example.com"); - CustomerRs customer1 = customerService.create(customerRq1); - - CustomerRq customerRq2 = new CustomerRq(); - customerRq2.setName("ПИбд-32"); - customerRq2.setEmail("pi32@example.com"); - CustomerRs customer2 = customerService.create(customerRq2); - - CustomerRq customerRq3 = new CustomerRq(); - customerRq3.setName("ПИбд-33"); - customerRq3.setEmail("pi33@example.com"); - CustomerRs customer3 = customerService.create(customerRq3); - - - assertEquals(initialCount + 3, customerService.findAll().size()); - - - CustomerRs foundCustomer = customerService.findById(customer3.getId()) - .orElseThrow(() -> new RuntimeException("Customer not found")); - assertEquals(customer3.getId(), foundCustomer.getId()); - assertEquals(customer3.getName(), foundCustomer.getName()); - } - - @Test - void updateTest() { - - List customers = customerService.findAll(); - if (customers.isEmpty()) { - - CustomerRq newCustomer = new CustomerRq(); - newCustomer.setName("Тестовый клиент"); - newCustomer.setEmail("test@example.com"); - customerService.create(newCustomer); - customers = customerService.findAll(); - } - - CustomerRs existingCustomer = customers.get(0); - String customerId = existingCustomer.getId(); - - final String newName = "ОБНОВЛЕННОЕ ИМЯ"; - final String newEmail = "updated@example.com"; - - - CustomerRq updateRequest = new CustomerRq(); - updateRequest.setName(newName); - updateRequest.setEmail(newEmail); - - CustomerRs updatedCustomer = customerService.update(customerId, updateRequest) - .orElseThrow(() -> new RuntimeException("Customer not found")); - - - assertEquals(customers.size(), customerService.findAll().size()); - - - assertEquals(newName, updatedCustomer.getName()); - assertEquals(newEmail, updatedCustomer.getEmail()); - assertNotEquals(existingCustomer.getName(), updatedCustomer.getName()); - - - CustomerRs customerFromDb = customerService.findById(customerId) - .orElseThrow(() -> new RuntimeException("Customer not found")); - assertEquals(updatedCustomer.getId(), customerFromDb.getId()); - assertEquals(updatedCustomer.getName(), customerFromDb.getName()); - } - - @Test - void deleteTest() { - - CustomerRq newCustomer = new CustomerRq(); - newCustomer.setName("Клиент для удаления"); - newCustomer.setEmail("delete@example.com"); - CustomerRs customerToDelete = customerService.create(newCustomer); - - - int countBefore = customerService.findAll().size(); - - - customerService.delete(customerToDelete.getId()); - - - assertEquals(countBefore - 1, customerService.findAll().size()); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/service/CustomerServiceTest.java b/src/test/java/com/example/service/CustomerServiceTest.java new file mode 100644 index 0000000..f1ccf9c --- /dev/null +++ b/src/test/java/com/example/service/CustomerServiceTest.java @@ -0,0 +1,71 @@ +package com.example.service; + +import com.example.dto.CustomerRq; +import com.example.dto.CustomerRs; +import com.example.entity.Customer; +import com.example.mapper.CustomerMapper; +import com.example.repository.CustomerRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class CustomerServiceTest { + + @Mock + private CustomerRepository customerRepository; + + @Mock + private CustomerMapper customerMapper; + + @InjectMocks + private CustomerService customerService; + + @Test + void findById_WhenCustomerExists_ShouldReturnCustomer() { + + Long customerId = 1L; + Customer customer = new Customer("Test", "test@mail.ru"); + CustomerRs customerRs = new CustomerRs(); + customerRs.setId(customerId); + + when(customerRepository.findById(customerId)).thenReturn(Optional.of(customer)); + when(customerMapper.toResponse(customer)).thenReturn(customerRs); + + + Optional result = customerService.findById(customerId); + + + assertTrue(result.isPresent()); + assertEquals(customerId, result.get().getId()); + } + + @Test + void create_WhenValidData_ShouldCreateCustomer() { + + CustomerRq request = new CustomerRq("John", "john@mail.ru"); + Customer customer = new Customer("John", "john@mail.ru"); + Customer savedCustomer = new Customer("John", "john@mail.ru"); + CustomerRs response = new CustomerRs(); + + when(customerRepository.findByEmail("john@mail.ru")).thenReturn(Optional.empty()); + when(customerMapper.toEntity(request)).thenReturn(customer); + when(customerRepository.save(customer)).thenReturn(savedCustomer); + when(customerMapper.toResponse(savedCustomer)).thenReturn(response); + + + CustomerRs result = customerService.create(request); + + + assertNotNull(result); + verify(customerRepository).save(customer); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/service/DeliveryServiceIntegrationTest.java b/src/test/java/com/example/service/DeliveryServiceIntegrationTest.java deleted file mode 100644 index 96e86f2..0000000 --- a/src/test/java/com/example/service/DeliveryServiceIntegrationTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.example.service; - -import com.example.dto.DeliveryRq; -import com.example.dto.DeliveryRs; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class DeliveryServiceIntegrationTest { - - @Autowired - private DeliveryService deliveryService; - - @Test - void getTest_WhenDeliveryNotExists_ShouldThrowException() { - - assertThrows(RuntimeException.class, () -> - deliveryService.findById("non-existent-id").orElseThrow(() -> new RuntimeException("Not found"))); - } - - @Test - void createTest() { - - int initialCount = deliveryService.findAll().size(); - - - DeliveryRq deliveryRq1 = new DeliveryRq(); - deliveryRq1.setTrackingNumber("TRACK001"); - deliveryRq1.setDestination("Москва"); - deliveryRq1.setStatus("В пути"); - deliveryRq1.setCustomer("Иван Иванов"); - DeliveryRs delivery1 = deliveryService.create(deliveryRq1); - - DeliveryRq deliveryRq2 = new DeliveryRq(); - deliveryRq2.setTrackingNumber("TRACK002"); - deliveryRq2.setDestination("Санкт-Петербург"); - deliveryRq2.setStatus("Доставлено"); - deliveryRq2.setCustomer("Петр Петров"); - DeliveryRs delivery2 = deliveryService.create(deliveryRq2); - - DeliveryRq deliveryRq3 = new DeliveryRq(); - deliveryRq3.setTrackingNumber("TRACK003"); - deliveryRq3.setDestination("Казань"); - deliveryRq3.setStatus("Обработка"); - deliveryRq3.setCustomer("Сергей Сергеев"); - DeliveryRs delivery3 = deliveryService.create(deliveryRq3); - - - assertEquals(initialCount + 3, deliveryService.findAll().size()); - - - DeliveryRs foundDelivery = deliveryService.findById(delivery3.getId()) - .orElseThrow(() -> new RuntimeException("Delivery not found")); - assertEquals(delivery3.getId(), foundDelivery.getId()); - assertEquals(delivery3.getTrackingNumber(), foundDelivery.getTrackingNumber()); - } - - @Test - void updateTest() { - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("OLD123"); - deliveryRq.setDestination("Старый адрес"); - deliveryRq.setStatus("Создана"); - deliveryRq.setCustomer("Тестовый клиент"); - DeliveryRs delivery = deliveryService.create(deliveryRq); - - - int countBefore = deliveryService.findAll().size(); - - final String newTrackingNumber = "NEW123"; - final String newDestination = "Новый адрес"; - final String newStatus = "В пути"; - - - DeliveryRq updateRequest = new DeliveryRq(); - updateRequest.setTrackingNumber(newTrackingNumber); - updateRequest.setDestination(newDestination); - updateRequest.setStatus(newStatus); - updateRequest.setCustomer("Обновленный клиент"); - - DeliveryRs updatedDelivery = deliveryService.update(delivery.getId(), updateRequest) - .orElseThrow(() -> new RuntimeException("Delivery not found")); - - - assertEquals(countBefore, deliveryService.findAll().size()); - - - assertEquals(newTrackingNumber, updatedDelivery.getTrackingNumber()); - assertEquals(newDestination, updatedDelivery.getDestination()); - assertEquals(newStatus, updatedDelivery.getStatus()); - assertNotEquals(delivery.getTrackingNumber(), updatedDelivery.getTrackingNumber()); - - - DeliveryRs deliveryFromDb = deliveryService.findById(delivery.getId()) - .orElseThrow(() -> new RuntimeException("Delivery not found")); - assertEquals(updatedDelivery.getId(), deliveryFromDb.getId()); - assertEquals(updatedDelivery.getTrackingNumber(), deliveryFromDb.getTrackingNumber()); - } - - @Test - void deleteTest() { - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("DELETE123"); - deliveryRq.setDestination("Адрес для удаления"); - deliveryRq.setStatus("Создана"); - deliveryRq.setCustomer("Клиент для удаления"); - DeliveryRs deliveryToDelete = deliveryService.create(deliveryRq); - - - int countBefore = deliveryService.findAll().size(); - - - deliveryService.delete(deliveryToDelete.getId()); - - - assertEquals(countBefore - 1, deliveryService.findAll().size()); - } - - @Test - void findByTrackingNumberTest() { - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("UNIQUE123"); - deliveryRq.setDestination("Уникальный адрес"); - deliveryRq.setStatus("В пути"); - deliveryRq.setCustomer("Уникальный клиент"); - DeliveryRs created = deliveryService.create(deliveryRq); - - - DeliveryRs found = deliveryService.findById(created.getId()) - .orElseThrow(() -> new RuntimeException("Delivery not found")); - - assertEquals("UNIQUE123", found.getTrackingNumber()); - assertEquals("Уникальный адрес", found.getDestination()); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/service/DeliveryServiceTest.java b/src/test/java/com/example/service/DeliveryServiceTest.java new file mode 100644 index 0000000..7b0a496 --- /dev/null +++ b/src/test/java/com/example/service/DeliveryServiceTest.java @@ -0,0 +1,141 @@ +package com.example.service; + +import com.example.dto.DeliveryRq; +import com.example.dto.DeliveryRs; +import com.example.entity.Delivery; +import com.example.mapper.DeliveryMapper; +import com.example.repository.DeliveryRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class DeliveryServiceTest { + + @Mock + private DeliveryRepository deliveryRepository; + + @Mock + private DeliveryMapper deliveryMapper; + + @InjectMocks + private DeliveryService deliveryService; + + @Test + void findAll_ShouldReturnAllDeliveries() { + + Delivery delivery1 = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Delivery delivery2 = new Delivery("TRACK002", "СПб", "Доставлено", "Петр Петров"); + DeliveryRs deliveryRs1 = new DeliveryRs(); + DeliveryRs deliveryRs2 = new DeliveryRs(); + + when(deliveryRepository.findAll()).thenReturn(List.of(delivery1, delivery2)); + when(deliveryMapper.toResponse(delivery1)).thenReturn(deliveryRs1); + when(deliveryMapper.toResponse(delivery2)).thenReturn(deliveryRs2); + + + List result = deliveryService.findAll(); + + + assertEquals(2, result.size()); + verify(deliveryRepository).findAll(); + } + + @Test + void findById_WhenDeliveryExists_ShouldReturnDelivery() { + + Long deliveryId = 1L; + Delivery delivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + DeliveryRs deliveryRs = new DeliveryRs(); + + when(deliveryRepository.findById(deliveryId)).thenReturn(Optional.of(delivery)); + when(deliveryMapper.toResponse(delivery)).thenReturn(deliveryRs); + + + Optional result = deliveryService.findById(deliveryId); + + + assertTrue(result.isPresent()); + verify(deliveryRepository).findById(deliveryId); + } + + @Test + void create_WhenValidData_ShouldCreateDelivery() { + + DeliveryRq request = new DeliveryRq("TRACK001", "Москва", "В пути", "Иван Иванов"); + Delivery delivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Delivery savedDelivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + DeliveryRs response = new DeliveryRs(); + + when(deliveryMapper.toEntity(request)).thenReturn(delivery); + when(deliveryRepository.save(delivery)).thenReturn(savedDelivery); + when(deliveryMapper.toResponse(savedDelivery)).thenReturn(response); + + + DeliveryRs result = deliveryService.create(request); + + + assertNotNull(result); + verify(deliveryRepository).save(delivery); + } + + @Test + void update_WhenDeliveryExists_ShouldUpdateDelivery() { + + Long deliveryId = 1L; + DeliveryRq request = new DeliveryRq("TRACK002", "СПб", "Доставлено", "Петр Петров"); + Delivery existingDelivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Delivery updatedDelivery = new Delivery("TRACK002", "СПб", "Доставлено", "Петр Петров"); + DeliveryRs response = new DeliveryRs(); + + when(deliveryRepository.findById(deliveryId)).thenReturn(Optional.of(existingDelivery)); + when(deliveryRepository.save(existingDelivery)).thenReturn(updatedDelivery); + when(deliveryMapper.toResponse(updatedDelivery)).thenReturn(response); + + + Optional result = deliveryService.update(deliveryId, request); + + + assertTrue(result.isPresent()); + assertEquals("TRACK002", existingDelivery.getTrackingNumber()); + assertEquals("СПб", existingDelivery.getDestination()); + verify(deliveryRepository).save(existingDelivery); + } + + @Test + void delete_WhenDeliveryExists_ShouldDeleteDelivery() { + + Long deliveryId = 1L; + when(deliveryRepository.existsById(deliveryId)).thenReturn(true); + + + boolean result = deliveryService.delete(deliveryId); + + + assertTrue(result); + verify(deliveryRepository).deleteById(deliveryId); + } + + @Test + void delete_WhenDeliveryNotExists_ShouldReturnFalse() { + + Long deliveryId = 999L; + when(deliveryRepository.existsById(deliveryId)).thenReturn(false); + + + boolean result = deliveryService.delete(deliveryId); + + + assertFalse(result); + verify(deliveryRepository, never()).deleteById(deliveryId); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/service/OrderServiceIntegrationTest.java b/src/test/java/com/example/service/OrderServiceIntegrationTest.java deleted file mode 100644 index ea92efc..0000000 --- a/src/test/java/com/example/service/OrderServiceIntegrationTest.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.example.service; - -import com.example.dto.OrderRq; -import com.example.dto.OrderRs; -import com.example.dto.CustomerRq; -import com.example.dto.DeliveryRq; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class OrderServiceIntegrationTest { - - @Autowired - private OrderService orderService; - - @Autowired - private CustomerService customerService; - - @Autowired - private DeliveryService deliveryService; - - @Test - void getTest_WhenOrderNotExists_ShouldThrowException() { - - assertThrows(RuntimeException.class, () -> - orderService.findById("non-existent-id").orElseThrow(() -> new RuntimeException("Not found"))); - } - - @Test - void createTest() { - - CustomerRq customerRq = new CustomerRq(); - customerRq.setName("Тестовый Клиент для Заказа"); - customerRq.setEmail("order@example.com"); - String customerId = customerService.create(customerRq).getId(); - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("ORDER_TRACK"); - deliveryRq.setDestination("Адрес для заказа"); - deliveryRq.setStatus("Готов к отправке"); - deliveryRq.setCustomer("Тестовый клиент"); - String deliveryId = deliveryService.create(deliveryRq).getId(); - - - int initialCount = orderService.findAll().size(); - - - OrderRq orderRq1 = new OrderRq(); - orderRq1.setCustomerId(customerId); - orderRq1.setDeliveryId(deliveryId); - orderRq1.setStatus("В пути"); - OrderRs order1 = orderService.create(orderRq1); - - OrderRq orderRq2 = new OrderRq(); - orderRq2.setCustomerId(customerId); - orderRq2.setDeliveryId(deliveryId); - orderRq2.setStatus("Обработка"); - OrderRs order2 = orderService.create(orderRq2); - - OrderRq orderRq3 = new OrderRq(); - orderRq3.setCustomerId(customerId); - orderRq3.setDeliveryId(deliveryId); - orderRq3.setStatus("Доставлено"); - OrderRs order3 = orderService.create(orderRq3); - - - assertEquals(initialCount + 3, orderService.findAll().size()); - - - OrderRs foundOrder = orderService.findById(order3.getId()) - .orElseThrow(() -> new RuntimeException("Order not found")); - assertEquals(order3.getId(), foundOrder.getId()); - assertEquals(order3.getStatus(), foundOrder.getStatus()); - - - assertNotNull(foundOrder.getCustomer()); - assertNotNull(foundOrder.getDelivery()); - assertEquals(customerId, foundOrder.getCustomer().getId()); - assertEquals(deliveryId, foundOrder.getDelivery().getId()); - } - - @Test - void updateTest() { - - CustomerRq customerRq = new CustomerRq(); - customerRq.setName("Клиент для обновления"); - customerRq.setEmail("update@example.com"); - String customerId = customerService.create(customerRq).getId(); - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("UPDATE_TRACK"); - deliveryRq.setDestination("Адрес для обновления"); - deliveryRq.setStatus("Готов"); - deliveryRq.setCustomer("Клиент"); - String deliveryId = deliveryService.create(deliveryRq).getId(); - - - OrderRq orderRq = new OrderRq(); - orderRq.setCustomerId(customerId); - orderRq.setDeliveryId(deliveryId); - orderRq.setStatus("В пути"); - OrderRs order = orderService.create(orderRq); - - - int countBefore = orderService.findAll().size(); - - final String newStatus = "Доставлено"; - - - OrderRq updateRequest = new OrderRq(); - updateRequest.setCustomerId(customerId); - updateRequest.setDeliveryId(deliveryId); - updateRequest.setStatus(newStatus); - - OrderRs updatedOrder = orderService.update(order.getId(), updateRequest) - .orElseThrow(() -> new RuntimeException("Order not found")); - - - assertEquals(countBefore, orderService.findAll().size()); - - - assertEquals(newStatus, updatedOrder.getStatus()); - assertNotEquals(order.getStatus(), updatedOrder.getStatus()); - - - OrderRs orderFromDb = orderService.findById(order.getId()) - .orElseThrow(() -> new RuntimeException("Order not found")); - assertEquals(updatedOrder.getId(), orderFromDb.getId()); - assertEquals(updatedOrder.getStatus(), orderFromDb.getStatus()); - } - - @Test - void deleteTest() { - - CustomerRq customerRq = new CustomerRq(); - customerRq.setName("Клиент для удаления"); - customerRq.setEmail("delete@example.com"); - String customerId = customerService.create(customerRq).getId(); - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("DELETE_TRACK"); - deliveryRq.setDestination("Адрес для удаления"); - deliveryRq.setStatus("Готов"); - deliveryRq.setCustomer("Клиент"); - String deliveryId = deliveryService.create(deliveryRq).getId(); - - - OrderRq orderRq = new OrderRq(); - orderRq.setCustomerId(customerId); - orderRq.setDeliveryId(deliveryId); - orderRq.setStatus("В пути"); - OrderRs orderToDelete = orderService.create(orderRq); - - - int countBefore = orderService.findAll().size(); - - - orderService.delete(orderToDelete.getId()); - - - assertEquals(countBefore - 1, orderService.findAll().size()); - } - - @Test - void findByCustomerIdTest() { - - CustomerRq customerRq = new CustomerRq(); - customerRq.setName("Клиент для поиска"); - customerRq.setEmail("search@example.com"); - String customerId = customerService.create(customerRq).getId(); - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("SEARCH_TRACK"); - deliveryRq.setDestination("Адрес для поиска"); - deliveryRq.setStatus("Готов"); - deliveryRq.setCustomer("Клиент"); - String deliveryId = deliveryService.create(deliveryRq).getId(); - - - OrderRq orderRq = new OrderRq(); - orderRq.setCustomerId(customerId); - orderRq.setDeliveryId(deliveryId); - orderRq.setStatus("В пути"); - orderService.create(orderRq); - - - List customerOrders = orderService.findByCustomerId(customerId); - - assertFalse(customerOrders.isEmpty()); - assertEquals(customerId, customerOrders.get(0).getCustomer().getId()); - } - - @Test - void findByStatusTest() { - - CustomerRq customerRq = new CustomerRq(); - customerRq.setName("Клиент для статуса"); - customerRq.setEmail("status@example.com"); - String customerId = customerService.create(customerRq).getId(); - - DeliveryRq deliveryRq = new DeliveryRq(); - deliveryRq.setTrackingNumber("STATUS_TRACK"); - deliveryRq.setDestination("Адрес для статуса"); - deliveryRq.setStatus("Готов"); - deliveryRq.setCustomer("Клиент"); - String deliveryId = deliveryService.create(deliveryRq).getId(); - - - OrderRq orderRq = new OrderRq(); - orderRq.setCustomerId(customerId); - orderRq.setDeliveryId(deliveryId); - orderRq.setStatus("Обработка"); - orderService.create(orderRq); - - - List processingOrders = orderService.findByStatus("Обработка"); - - assertFalse(processingOrders.isEmpty()); - assertEquals("Обработка", processingOrders.get(0).getStatus()); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/service/OrderServiceTest.java b/src/test/java/com/example/service/OrderServiceTest.java new file mode 100644 index 0000000..5eae082 --- /dev/null +++ b/src/test/java/com/example/service/OrderServiceTest.java @@ -0,0 +1,185 @@ +package com.example.service; + +import com.example.dto.OrderRq; +import com.example.dto.OrderRs; +import com.example.entity.Customer; +import com.example.entity.Delivery; +import com.example.entity.Order; +import com.example.mapper.OrderMapper; +import com.example.repository.CustomerRepository; +import com.example.repository.DeliveryRepository; +import com.example.repository.OrderRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class OrderServiceTest { + + @Mock + private OrderRepository orderRepository; + + @Mock + private CustomerRepository customerRepository; + + @Mock + private DeliveryRepository deliveryRepository; + + @Mock + private OrderMapper orderMapper; + + @InjectMocks + private OrderService orderService; + + @Test + void findAll_ShouldReturnAllOrders() { + + Customer customer = new Customer("Иван", "ivan@mail.ru"); + Delivery delivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Order order1 = new Order(customer, delivery, "В пути"); + Order order2 = new Order(customer, delivery, "Доставлено"); + OrderRs orderRs1 = new OrderRs(); + OrderRs orderRs2 = new OrderRs(); + + when(orderRepository.findAll()).thenReturn(List.of(order1, order2)); + when(orderMapper.toResponse(order1)).thenReturn(orderRs1); + when(orderMapper.toResponse(order2)).thenReturn(orderRs2); + + + List result = orderService.findAll(); + + + assertEquals(2, result.size()); + verify(orderRepository).findAll(); + } + + @Test + void findById_WhenOrderExists_ShouldReturnOrder() { + + Long orderId = 1L; + Customer customer = new Customer("Иван", "ivan@mail.ru"); + Delivery delivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Order order = new Order(customer, delivery, "В пути"); + OrderRs orderRs = new OrderRs(); + + when(orderRepository.findById(orderId)).thenReturn(Optional.of(order)); + when(orderMapper.toResponse(order)).thenReturn(orderRs); + + + Optional result = orderService.findById(orderId); + + + assertTrue(result.isPresent()); + verify(orderRepository).findById(orderId); + } + + @Test + void create_WhenValidData_ShouldCreateOrder() { + + OrderRq request = new OrderRq(1L, 1L, "В пути"); + + Customer customer = new Customer("Иван", "ivan@mail.ru"); + Delivery delivery = new Delivery("TRACK001", "Москва", "В пути", "Иван Иванов"); + Order order = new Order(customer, delivery, "В пути"); + Order savedOrder = new Order(customer, delivery, "В пути"); + OrderRs response = new OrderRs(); + + + when(customerRepository.findById(1L)).thenReturn(Optional.of(customer)); + when(deliveryRepository.findById(1L)).thenReturn(Optional.of(delivery)); + when(orderMapper.toEntity(request)).thenReturn(order); + when(orderRepository.save(order)).thenReturn(savedOrder); + when(orderMapper.toResponse(savedOrder)).thenReturn(response); + + + OrderRs result = orderService.create(request); + + + assertNotNull(result); + verify(orderRepository).save(order); + verify(customerRepository).findById(1L); + verify(deliveryRepository).findById(1L); + } + + @Test +void create_WhenCustomerNotFound_ShouldThrowException() { + + OrderRq request = new OrderRq(999L, 1L, "В пути"); + + + when(customerRepository.findById(999L)).thenReturn(Optional.empty()); + + + + assertThrows(IllegalArgumentException.class, () -> { + orderService.create(request); + }); + + + verify(deliveryRepository, never()).findById(any()); +} + + @Test + void update_WhenOrderExists_ShouldUpdateOrder() { + + Long orderId = 1L; + OrderRq request = new OrderRq(2L, 2L, "Доставлено"); + + Customer customer = new Customer("Петр", "petr@mail.ru"); + Delivery delivery = new Delivery("TRACK002", "СПб", "Доставлено", "Петр Петров"); + Order existingOrder = new Order(customer, delivery, "В пути"); + Order updatedOrder = new Order(customer, delivery, "Доставлено"); + OrderRs response = new OrderRs(); + + when(orderRepository.findById(orderId)).thenReturn(Optional.of(existingOrder)); + when(customerRepository.findById(2L)).thenReturn(Optional.of(customer)); + when(deliveryRepository.findById(2L)).thenReturn(Optional.of(delivery)); + when(orderRepository.save(existingOrder)).thenReturn(updatedOrder); + when(orderMapper.toResponse(updatedOrder)).thenReturn(response); + + + Optional result = orderService.update(orderId, request); + + + assertTrue(result.isPresent()); + assertEquals("Доставлено", existingOrder.getStatus()); + verify(orderRepository).save(existingOrder); + } + + @Test + void delete_WhenOrderExists_ShouldDeleteOrder() { + + Long orderId = 1L; + when(orderRepository.existsById(orderId)).thenReturn(true); + + + boolean result = orderService.delete(orderId); + + + assertTrue(result); + verify(orderRepository).deleteById(orderId); + } + + @Test + void delete_WhenOrderNotExists_ShouldReturnFalse() { + + Long orderId = 999L; + when(orderRepository.existsById(orderId)).thenReturn(false); + + + boolean result = orderService.delete(orderId); + + + assertFalse(result); + verify(orderRepository, never()).deleteById(orderId); + } +} \ No newline at end of file