diff --git a/.gradle/8.14.3/checksums/checksums.lock b/.gradle/8.14.3/checksums/checksums.lock index b1d62eb..d7b9710 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 new file mode 100644 index 0000000..9d7f056 Binary files /dev/null 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 new file mode 100644 index 0000000..4936d16 Binary files /dev/null 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 5fdb1de..5d81444 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 7f462c4..359cad1 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 d324a3c..866d200 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 8dfd69c..1fdb214 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 0fafffa..bfbd835 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 2a0a878..b6b815c 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 027da61..ac73e7b 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 4df3e31..7f8b09c 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.gradle/workspace-id.txt b/.gradle/workspace-id.txt new file mode 100644 index 0000000..cb82541 Binary files /dev/null and b/.gradle/workspace-id.txt differ diff --git a/.gradle/workspace-id.txt.lock b/.gradle/workspace-id.txt.lock new file mode 100644 index 0000000..714bdc2 Binary files /dev/null and b/.gradle/workspace-id.txt.lock differ diff --git a/build.gradle b/build.gradle index d7383cc..3b4026b 100644 --- a/build.gradle +++ b/build.gradle @@ -20,13 +20,13 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' + testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' } - - tasks.named('test') { useJUnitPlatform() -} +} \ No newline at end of file diff --git a/build/classes/java/main/com/example/controller/DemoApplication.class b/build/classes/java/main/com/example/DemoApplication.class similarity index 60% rename from build/classes/java/main/com/example/controller/DemoApplication.class rename to build/classes/java/main/com/example/DemoApplication.class index 02cf2be..5c05a36 100644 Binary files a/build/classes/java/main/com/example/controller/DemoApplication.class and b/build/classes/java/main/com/example/DemoApplication.class differ diff --git a/build/classes/java/main/com/example/controller/CustomerController.class b/build/classes/java/main/com/example/controller/CustomerController.class index e86a8ce..8019b0b 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 d3f2bd3..ec49aaf 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 645f155..8f0da08 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/CustomerRq.class b/build/classes/java/main/com/example/dto/CustomerRq.class new file mode 100644 index 0000000..988aed9 Binary files /dev/null and b/build/classes/java/main/com/example/dto/CustomerRq.class differ diff --git a/build/classes/java/main/com/example/dto/CustomerRs.class b/build/classes/java/main/com/example/dto/CustomerRs.class new file mode 100644 index 0000000..8a0040d Binary files /dev/null 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 new file mode 100644 index 0000000..38e8e39 Binary files /dev/null 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 new file mode 100644 index 0000000..c3341c3 Binary files /dev/null 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 new file mode 100644 index 0000000..8e88198 Binary files /dev/null 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 new file mode 100644 index 0000000..e71849d Binary files /dev/null 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 new file mode 100644 index 0000000..aea43ca Binary files /dev/null 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 new file mode 100644 index 0000000..e08d4e0 Binary files /dev/null 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 new file mode 100644 index 0000000..cdac882 Binary files /dev/null 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 new file mode 100644 index 0000000..ffa0837 Binary files /dev/null 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 new file mode 100644 index 0000000..b2f3cb1 Binary files /dev/null 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 new file mode 100644 index 0000000..9246e38 Binary files /dev/null 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 new file mode 100644 index 0000000..26edee9 Binary files /dev/null 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 new file mode 100644 index 0000000..4868416 Binary files /dev/null and b/build/classes/java/main/com/example/repository/CommonRepository.class differ diff --git a/build/classes/java/main/com/example/repository/CustomerRepository.class b/build/classes/java/main/com/example/repository/CustomerRepository.class new file mode 100644 index 0000000..1a63c93 Binary files /dev/null and b/build/classes/java/main/com/example/repository/CustomerRepository.class differ diff --git a/build/classes/java/main/com/example/repository/DeliveryRepository.class b/build/classes/java/main/com/example/repository/DeliveryRepository.class new file mode 100644 index 0000000..c7538c7 Binary files /dev/null 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 new file mode 100644 index 0000000..ac65d49 Binary files /dev/null and b/build/classes/java/main/com/example/repository/MapRepository.class differ diff --git a/build/classes/java/main/com/example/repository/OrderRepository.class b/build/classes/java/main/com/example/repository/OrderRepository.class new file mode 100644 index 0000000..cf163b7 Binary files /dev/null and b/build/classes/java/main/com/example/repository/OrderRepository.class differ diff --git a/build/classes/java/main/com/example/service/CustomerService.class b/build/classes/java/main/com/example/service/CustomerService.class new file mode 100644 index 0000000..53e3a8d Binary files /dev/null and b/build/classes/java/main/com/example/service/CustomerService.class differ diff --git a/build/classes/java/main/com/example/service/DeliveryService.class b/build/classes/java/main/com/example/service/DeliveryService.class new file mode 100644 index 0000000..77bfa51 Binary files /dev/null and b/build/classes/java/main/com/example/service/DeliveryService.class differ diff --git a/build/classes/java/main/com/example/service/OrderService.class b/build/classes/java/main/com/example/service/OrderService.class new file mode 100644 index 0000000..aef31b6 Binary files /dev/null and b/build/classes/java/main/com/example/service/OrderService.class differ diff --git a/build/classes/java/test/com/example/controller/CustomerControllerTest.class b/build/classes/java/test/com/example/controller/CustomerControllerTest.class new file mode 100644 index 0000000..e0dbc60 Binary files /dev/null and b/build/classes/java/test/com/example/controller/CustomerControllerTest.class differ diff --git a/build/classes/java/test/com/example/controller/DeliveryControllerTest.class b/build/classes/java/test/com/example/controller/DeliveryControllerTest.class new file mode 100644 index 0000000..3aafb61 Binary files /dev/null and b/build/classes/java/test/com/example/controller/DeliveryControllerTest.class differ diff --git a/build/classes/java/test/com/example/controller/OrderControllerTest.class b/build/classes/java/test/com/example/controller/OrderControllerTest.class new file mode 100644 index 0000000..5fb952f Binary files /dev/null and b/build/classes/java/test/com/example/controller/OrderControllerTest.class differ diff --git a/build/classes/java/test/com/example/demo/DemoApplicationTests.class b/build/classes/java/test/com/example/demo/DemoApplicationTests.class deleted file mode 100644 index 58aca21..0000000 Binary files a/build/classes/java/test/com/example/demo/DemoApplicationTests.class and /dev/null differ diff --git a/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class b/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class new file mode 100644 index 0000000..9bb3b8a Binary files /dev/null and b/build/classes/java/test/com/example/service/CustomerServiceIntegrationTest.class differ diff --git a/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class b/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class new file mode 100644 index 0000000..c568627 Binary files /dev/null and b/build/classes/java/test/com/example/service/DeliveryServiceIntegrationTest.class differ diff --git a/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class b/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class new file mode 100644 index 0000000..568ce29 Binary files /dev/null and b/build/classes/java/test/com/example/service/OrderServiceIntegrationTest.class differ diff --git a/build/libs/demo-0.0.1-SNAPSHOT-plain.jar b/build/libs/demo-0.0.1-SNAPSHOT-plain.jar deleted file mode 100644 index 0ff275a..0000000 Binary files a/build/libs/demo-0.0.1-SNAPSHOT-plain.jar and /dev/null differ diff --git a/build/libs/demo-0.0.1-SNAPSHOT.jar b/build/libs/demo-0.0.1-SNAPSHOT.jar deleted file mode 100644 index fdc73c0..0000000 Binary files a/build/libs/demo-0.0.1-SNAPSHOT.jar and /dev/null differ diff --git a/build/reports/problems/problems-report.html b/build/reports/problems/problems-report.html deleted file mode 100644 index b309b40..0000000 --- a/build/reports/problems/problems-report.html +++ /dev/null @@ -1,663 +0,0 @@ - - - - - - - - - - - - - Gradle Configuration Cache - - - -
- -
- Loading... -
- - - - - - diff --git a/build/reports/tests/test/classes/com.example.demo.DemoApplicationTests.html b/build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html similarity index 62% rename from build/reports/tests/test/classes/com.example.demo.DemoApplicationTests.html rename to build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html index 81ca5eb..3767e14 100644 --- a/build/reports/tests/test/classes/com.example.demo.DemoApplicationTests.html +++ b/build/reports/tests/test/classes/com.example.service.CustomerServiceIntegrationTest.html @@ -3,17 +3,17 @@ -Test results - DemoApplicationTests +Test results - CustomerServiceIntegrationTest
-

DemoApplicationTests

+

CustomerServiceIntegrationTest

+com.example.service > CustomerServiceIntegrationTest
@@ -23,7 +23,7 @@ @@ -41,7 +41,7 @@ @@ -81,8 +81,23 @@ - - + + + + + + + + + + + + + + + + +
-
1
+
4

tests

-
0.383s
+
0.349s

duration

contextLoads()0.383screateTest()0.002spassed
deleteTest()0.001spassed
getTest_WhenCustomerNotExists_ShouldThrowException()0.344spassed
updateTest()0.002s passed
@@ -90,8 +105,8 @@

Standard output

-
09:05:47.895 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.DemoApplicationTests]: DemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
-09:05:47.937 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.DemoApplication for test class com.example.demo.DemoApplicationTests
+
19:23:02.926 [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.
+19:23:02.970 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.CustomerServiceIntegrationTest
 
   .   ____          _            __ _ _
  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
@@ -102,10 +117,9 @@
 
  :: Spring Boot ::                (v3.5.5)
 
-2025-09-13T09:05:48.075+04:00  INFO 56029 --- [demo] [    Test worker] com.example.demo.DemoApplicationTests    : Starting DemoApplicationTests using Java 21.0.3 with PID 56029 (started by floom in /Users/floom/demo)
-2025-09-13T09:05:48.075+04:00  INFO 56029 --- [demo] [    Test worker] com.example.demo.DemoApplicationTests    : No active profile set, falling back to 1 default profile: "default"
-2025-09-13T09:05:48.407+04:00  INFO 56029 --- [demo] [    Test worker] o.s.v.b.OptionalValidatorFactoryBean     : Failed to set up a Bean Validation provider: jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
-2025-09-13T09:05:48.517+04:00  INFO 56029 --- [demo] [    Test worker] com.example.demo.DemoApplicationTests    : Started DemoApplicationTests in 0.531 seconds (process running for 0.945)
+2025-10-10T19:23:03.112+04:00  INFO 20384 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : Starting CustomerServiceIntegrationTest using Java 21.0.3 with PID 20384 (started by floom in /Users/floom/PIbd-21_Kudrinsky_O.S._IP-6)
+2025-10-10T19:23:03.113+04:00  INFO 20384 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : No active profile set, falling back to 1 default profile: "default"
+2025-10-10T19:23:03.648+04:00  INFO 20384 --- [demo] [    Test worker] c.e.s.CustomerServiceIntegrationTest     : Started CustomerServiceIntegrationTest in 0.628 seconds (process running for 1.067)
 
@@ -128,7 +142,7 @@ WARNING: Dynamic loading of agents will be disallowed by default in a future rel
Generated by -Gradle 8.14.3 at 13 сент. 2025 г., 09:05:48

+Gradle 8.14.3 at 10 окт. 2025 г., 19:23:04

diff --git a/build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html b/build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html new file mode 100644 index 0000000..77ba660 --- /dev/null +++ b/build/reports/tests/test/classes/com.example.service.DeliveryServiceIntegrationTest.html @@ -0,0 +1,127 @@ + + + + + +Test results - DeliveryServiceIntegrationTest + + + + + +
+

DeliveryServiceIntegrationTest

+ +
+ + + + + +
+
+ + + + + + + +
+
+
5
+

tests

+
+
+
+
0
+

failures

+
+
+
+
0
+

ignored

+
+
+
+
0.008s
+

duration

+
+
+
+
+
+
100%
+

successful

+
+
+
+
+ +
+

Tests

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TestDurationResult
createTest()0.002spassed
deleteTest()0.001spassed
findByTrackingNumberTest()0.001spassed
getTest_WhenDeliveryNotExists_ShouldThrowException()0.002spassed
updateTest()0.002spassed
+
+
+

Standard output

+ +
2025-10-10T19:23:04.005+04:00  INFO 20384 --- [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-10T19:23:04.006+04:00  INFO 20384 --- [demo] [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.DeliveryServiceIntegrationTest
+
+
+
+
+ +
+ + diff --git a/build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html b/build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html new file mode 100644 index 0000000..aba079c --- /dev/null +++ b/build/reports/tests/test/classes/com.example.service.OrderServiceIntegrationTest.html @@ -0,0 +1,132 @@ + + + + + +Test results - OrderServiceIntegrationTest + + + + + +
+

OrderServiceIntegrationTest

+ +
+ + + + + +
+
+ + + + + + + +
+
+
6
+

tests

+
+
+
+
0
+

failures

+
+
+
+
0
+

ignored

+
+
+
+
0.007s
+

duration

+
+
+
+
+
+
100%
+

successful

+
+
+
+
+ +
+

Tests

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TestDurationResult
createTest()0.001spassed
deleteTest()0.001spassed
findByCustomerIdTest()0.002spassed
findByStatusTest()0.001spassed
getTest_WhenOrderNotExists_ShouldThrowException()0.001spassed
updateTest()0.001spassed
+
+
+

Standard output

+ +
2025-10-10T19:23:04.016+04:00  INFO 20384 --- [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-10T19:23:04.016+04:00  INFO 20384 --- [demo] [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.OrderServiceIntegrationTest
+
+
+
+
+ +
+ + diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index 2178f9c..c2e771b 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -20,7 +20,7 @@
-
1
+
15

tests

@@ -38,7 +38,7 @@
-
0.383s
+
0.364s

duration

@@ -80,12 +80,12 @@ -com.example.demo +com.example.service -1 +15 0 0 -0.383s +0.364s 100% @@ -107,12 +107,32 @@ -com.example.demo.DemoApplicationTests +com.example.service.CustomerServiceIntegrationTest -1 +4 0 0 -0.383s +0.349s +100% + + + +com.example.service.DeliveryServiceIntegrationTest + +5 +0 +0 +0.008s +100% + + + +com.example.service.OrderServiceIntegrationTest + +6 +0 +0 +0.007s 100% @@ -126,7 +146,7 @@ Generated by -Gradle 8.14.3 at 13 сент. 2025 г., 09:05:48

+Gradle 8.14.3 at 10 окт. 2025 г., 19:23:04

diff --git a/build/reports/tests/test/packages/com.example.demo.html b/build/reports/tests/test/packages/com.example.service.html similarity index 64% rename from build/reports/tests/test/packages/com.example.demo.html rename to build/reports/tests/test/packages/com.example.service.html index 6cfe3c5..49fb35a 100644 --- a/build/reports/tests/test/packages/com.example.demo.html +++ b/build/reports/tests/test/packages/com.example.service.html @@ -3,16 +3,16 @@ -Test results - Package com.example.demo +Test results - Package com.example.service
-

Package com.example.demo

+

Package com.example.service

+all > com.example.service
@@ -22,7 +22,7 @@ @@ -40,7 +40,7 @@ @@ -78,12 +78,32 @@ - + - + + + + + + + + + + + + + + + + +
-
1
+
15

tests

-
0.383s
+
0.364s

duration

-DemoApplicationTests +CustomerServiceIntegrationTest 14 0 00.383s0.349s100%
+DeliveryServiceIntegrationTest +5000.008s100%
+OrderServiceIntegrationTest +6000.007s 100%
@@ -96,7 +116,7 @@
Generated by -Gradle 8.14.3 at 13 сент. 2025 г., 09:05:48

+Gradle 8.14.3 at 10 окт. 2025 г., 19:23:04

diff --git a/build/resolvedMainClassName b/build/resolvedMainClassName deleted file mode 100644 index f122f8b..0000000 --- a/build/resolvedMainClassName +++ /dev/null @@ -1 +0,0 @@ -com.example.controller.DemoApplication \ No newline at end of file diff --git a/build/test-results/test/TEST-com.example.demo.DemoApplicationTests.xml b/build/test-results/test/TEST-com.example.demo.DemoApplicationTests.xml deleted file mode 100644 index b8a3d5a..0000000 --- a/build/test-results/test/TEST-com.example.demo.DemoApplicationTests.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - diff --git a/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml new file mode 100644 index 0000000..40e0844 --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.CustomerServiceIntegrationTest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml new file mode 100644 index 0000000..120a352 --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.DeliveryServiceIntegrationTest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml b/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml new file mode 100644 index 0000000..060afac --- /dev/null +++ b/build/test-results/test/TEST-com.example.service.OrderServiceIntegrationTest.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/build/test-results/test/binary/output.bin b/build/test-results/test/binary/output.bin index 6eae358..955b9d3 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 d7eed90..23a15e5 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 97459fe..622b5bc 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/bootJar/MANIFEST.MF b/build/tmp/bootJar/MANIFEST.MF deleted file mode 100644 index 4c6bc85..0000000 --- a/build/tmp/bootJar/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: org.springframework.boot.loader.launch.JarLauncher -Start-Class: com.example.demo.DemoApplication -Spring-Boot-Version: 3.5.5 -Spring-Boot-Classes: BOOT-INF/classes/ -Spring-Boot-Lib: BOOT-INF/lib/ -Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx -Spring-Boot-Layers-Index: BOOT-INF/layers.idx -Build-Jdk-Spec: 21 -Implementation-Title: demo -Implementation-Version: 0.0.1-SNAPSHOT - diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId3 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId3 deleted file mode 100644 index e86a8ce..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerController.class.uniqueId3 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerDTO.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/CustomerDTO.class.uniqueId1 deleted file mode 100644 index 5ee7e68..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CustomerDTO.class.uniqueId1 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId0 deleted file mode 100644 index 6fdd224..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderController.class.uniqueId0 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/OrderDTO.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/OrderDTO.class.uniqueId2 deleted file mode 100644 index 3e9e90d..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/OrderDTO.class.uniqueId2 and /dev/null differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 8f5b9fb..802dca2 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/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index a1e8448..2919066 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/build/tmp/jar/MANIFEST.MF b/build/tmp/jar/MANIFEST.MF deleted file mode 100644 index 58630c0..0000000 --- a/build/tmp/jar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/front/src/components/OrderList.jsx b/front/src/components/OrderList.jsx index e7527a7..d565cf4 100644 --- a/front/src/components/OrderList.jsx +++ b/front/src/components/OrderList.jsx @@ -25,10 +25,6 @@ function OrderList() { fetch('http://localhost:8080/api/deliveries') ]); - if (!ordersRes.ok) throw new Error('Ошибка загрузки заказов'); - if (!customersRes.ok) throw new Error('Ошибка загрузки клиентов'); - if (!deliveriesRes.ok) throw new Error('Ошибка загрузки доставок'); - const ordersData = await ordersRes.json(); const customersData = await customersRes.json(); const deliveriesData = await deliveriesRes.json(); @@ -66,17 +62,10 @@ function OrderList() { const handleCreateOrder = async (orderData) => { try { - const customer = customers.find(c => c.id === orderData.customerId); - const delivery = deliveries.find(d => d.id === orderData.deliveryId); - - if (!customer || !delivery) { - alert('Ошибка: клиент или доставка не найдены'); - return; - } - - const newOrder = { - customer: customer, - delivery: delivery, + // Теперь отправляем OrderRq DTO с customerId и deliveryId + const orderRq = { + customerId: orderData.customerId, + deliveryId: orderData.deliveryId, status: orderData.status }; @@ -86,17 +75,15 @@ function OrderList() { 'Content-Type': 'application/json', 'Accept': 'application/json' }, - body: JSON.stringify(newOrder) + body: JSON.stringify(orderRq) }); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + const errorText = await response.text(); + throw new Error(errorText || `HTTP error! status: ${response.status}`); } - const createdOrder = await response.json(); - console.log('Создан заказ:', createdOrder); - - await loadData(); + await loadData(); setEditingOrder(null); } catch (error) { console.error('Ошибка создания заказа:', error); @@ -104,6 +91,36 @@ function OrderList() { } }; + const handleUpdateOrder = async (orderData) => { + try { + const orderRq = { + customerId: orderData.customerId, + deliveryId: orderData.deliveryId, + status: orderData.status + }; + + const response = await fetch(`http://localhost:8080/api/orders/${editingOrder.id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + body: JSON.stringify(orderRq) + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(errorText || `HTTP error! status: ${response.status}`); + } + + await loadData(); + setEditingOrder(null); + } catch (error) { + console.error('Ошибка обновления заказа:', error); + alert('Ошибка при обновлении заказа: ' + error.message); + } + }; + const handleDeleteOrder = async (orderId) => { if (window.confirm('Удалить этот заказ?')) { try { @@ -115,7 +132,7 @@ function OrderList() { throw new Error(`HTTP error! status: ${response.status}`); } - await loadData(); + await loadData(); } catch (error) { console.error('Ошибка удаления заказа:', error); alert('Ошибка при удалении заказа: ' + error.message); @@ -123,20 +140,28 @@ function OrderList() { } }; + const handleFormSubmit = (orderData) => { + if (editingOrder) { + handleUpdateOrder(orderData); + } else { + handleCreateOrder(orderData); + } + }; + if (loading) { return
Загрузка...
; } return (
-

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

+

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

diff --git a/src/main/java/com/example/controller/DemoApplication.java b/src/main/java/com/example/DemoApplication.java similarity index 56% rename from src/main/java/com/example/controller/DemoApplication.java rename to src/main/java/com/example/DemoApplication.java index 3ded762..cbc0699 100644 --- a/src/main/java/com/example/controller/DemoApplication.java +++ b/src/main/java/com/example/DemoApplication.java @@ -1,4 +1,4 @@ -package com.example.controller; +package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,8 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } - -} + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/controller/CustomerController.java b/src/main/java/com/example/controller/CustomerController.java index f62304a..6f7da41 100644 --- a/src/main/java/com/example/controller/CustomerController.java +++ b/src/main/java/com/example/controller/CustomerController.java @@ -1,11 +1,14 @@ package com.example.controller; -import com.example.dto.CustomerDTO; +import com.example.dto.CustomerRq; +import com.example.dto.CustomerRs; +import com.example.service.CustomerService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -14,49 +17,45 @@ import java.util.Optional; @RequestMapping("/api/customers") @Tag(name = "Customer API", description = "Операции с клиентами") public class CustomerController { - - private final List customers = new ArrayList<>(); - - public CustomerController() { - customers.add(new CustomerDTO("c1", "Иванов Иван", "ivanov@example.com")); - customers.add(new CustomerDTO("c2", "Петров Петр", "petrov@example.com")); + + private final CustomerService customerService; + + public CustomerController(CustomerService customerService) { + this.customerService = customerService; } - + @GetMapping @Operation(summary = "Получить всех клиентов") - public List getAll() { - return customers; + public List getAll() { + return customerService.findAll(); } - + @GetMapping("/{id}") @Operation(summary = "Получить клиента по ID") - public CustomerDTO getOne(@PathVariable String id) { - return customers.stream().filter(c -> c.getId().equals(id)).findFirst().orElse(null); + public ResponseEntity getOne(@PathVariable String id) { + Optional customer = customerService.findById(id); + return customer.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - + @PostMapping @Operation(summary = "Создать нового клиента") - public CustomerDTO create(@RequestBody CustomerDTO customer) { - customers.add(customer); - return customer; + public CustomerRs create(@Valid @RequestBody CustomerRq customerRq) { + return customerService.create(customerRq); } - + @PutMapping("/{id}") @Operation(summary = "Обновить данные клиента") - public CustomerDTO update(@PathVariable String id, @RequestBody CustomerDTO updated) { - Optional existing = customers.stream().filter(c -> c.getId().equals(id)).findFirst(); - if (existing.isPresent()) { - CustomerDTO c = existing.get(); - c.setName(updated.getName()); - c.setEmail(updated.getEmail()); - return c; - } - return null; + public ResponseEntity update(@PathVariable String id, @Valid @RequestBody CustomerRq customerRq) { + Optional updated = customerService.update(id, customerRq); + return updated.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - + @DeleteMapping("/{id}") @Operation(summary = "Удалить клиента") - public void delete(@PathVariable String id) { - customers.removeIf(c -> c.getId().equals(id)); + public ResponseEntity delete(@PathVariable String id) { + boolean deleted = customerService.delete(id); + return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } } \ 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 3a895f3..89cb37c 100644 --- a/src/main/java/com/example/controller/DeliveryController.java +++ b/src/main/java/com/example/controller/DeliveryController.java @@ -1,68 +1,61 @@ package com.example.controller; -import com.example.dto.DeliveryDTO; +import com.example.dto.DeliveryRq; +import com.example.dto.DeliveryRs; +import com.example.service.DeliveryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; -import java.util.UUID; +import java.util.Optional; @CrossOrigin(origins = "http://localhost:5173") @RestController @RequestMapping("/api/deliveries") @Tag(name = "Delivery API", description = "Операции с доставками") public class DeliveryController { - - private final List deliveries = new ArrayList<>(); - - public DeliveryController() { - deliveries.add(new DeliveryDTO("578a","IVN012021","гоголя10","Доставлено","Парт петрович wwww")); - deliveries.add(new DeliveryDTO("0e0f","IVN123456","Москва","В пути","1Иванов Иван")); + + private final DeliveryService deliveryService; + + public DeliveryController(DeliveryService deliveryService) { + this.deliveryService = deliveryService; } - + @GetMapping @Operation(summary = "Получить все доставки") - public List getAll() { - return deliveries; + public List getAll() { + return deliveryService.findAll(); } - + @GetMapping("/{id}") @Operation(summary = "Получить доставку по ID") - public DeliveryDTO getOne(@PathVariable String id) { - return deliveries.stream() - .filter(d -> d.getId().equals(id)) - .findFirst() - .orElseThrow(() -> new RuntimeException("Delivery not found")); + public ResponseEntity getOne(@PathVariable String id) { + Optional delivery = deliveryService.findById(id); + return delivery.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - + @PostMapping @Operation(summary = "Создать новую доставку") - public DeliveryDTO create(@RequestBody DeliveryDTO delivery) { - if (delivery.getId() == null || delivery.getId().isEmpty()) { - delivery.setId(UUID.randomUUID().toString()); - } - deliveries.add(delivery); - return delivery; + public DeliveryRs create(@Valid @RequestBody DeliveryRq deliveryRq) { + return deliveryService.create(deliveryRq); } - + @PutMapping("/{id}") @Operation(summary = "Обновить данные доставки") - public DeliveryDTO update(@PathVariable String id, @RequestBody DeliveryDTO updated) { - for (int i = 0; i < deliveries.size(); i++) { - if (deliveries.get(i).getId().equals(id)) { - updated.setId(id); - deliveries.set(i, updated); - return updated; - } - } - throw new RuntimeException("Delivery not found"); + public ResponseEntity update(@PathVariable String id, @Valid @RequestBody DeliveryRq deliveryRq) { + Optional updated = deliveryService.update(id, deliveryRq); + return updated.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - + @DeleteMapping("/{id}") @Operation(summary = "Удалить доставку") - public void delete(@PathVariable String id) { - deliveries.removeIf(d -> d.getId().equals(id)); + public ResponseEntity delete(@PathVariable String id) { + boolean deleted = deliveryService.delete(id); + return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } } \ 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 13b8cfc..71b75d4 100644 --- a/src/main/java/com/example/controller/OrderController.java +++ b/src/main/java/com/example/controller/OrderController.java @@ -1,105 +1,82 @@ package com.example.controller; -import com.example.dto.OrderDTO; -import com.example.dto.CustomerDTO; -import com.example.dto.DeliveryDTO; +import com.example.dto.OrderRq; +import com.example.dto.OrderRs; +import com.example.service.OrderService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.Optional; -@RestController @CrossOrigin(origins = "http://localhost:5173") +@RestController @RequestMapping("/api/orders") @Tag(name = "Order API", description = "Операции с заказами") public class OrderController { - - private final List orders = new ArrayList<>(); - private final CustomerController customerController; - private final DeliveryController deliveryController; - - public OrderController(CustomerController customerController, DeliveryController deliveryController) { - this.customerController = customerController; - this.deliveryController = deliveryController; - initializeTestData(); + + private final OrderService orderService; + + public OrderController(OrderService orderService) { + this.orderService = orderService; } - - private void initializeTestData() { - CustomerDTO customer1 = new CustomerDTO("c1", "Иванов Иван", "ivanov@example.com"); - CustomerDTO customer2 = new CustomerDTO("c2", "Петров Петр", "petrov@example.com"); - - DeliveryDTO delivery1 = new DeliveryDTO("578a", "IVN012021", "гоголя10", "Доставлено", "Парт петрович wwww"); - DeliveryDTO delivery2 = new DeliveryDTO("0e0f", "IVN123456", "Москва", "В пути", "1Иванов Иван"); - - orders.add(new OrderDTO("o1", customer1, delivery1, "Доставлено")); - orders.add(new OrderDTO("o2", customer2, delivery2, "В пути")); - } - + @GetMapping @Operation(summary = "Получить все заказы") - public List getAll() { - return orders; + public List getAll() { + return orderService.findAll(); } - + @GetMapping("/{id}") @Operation(summary = "Получить заказ по ID") - public OrderDTO getOne(@PathVariable String id) { - return orders.stream() - .filter(o -> o.getId().equals(id)) - .findFirst() - .orElse(null); + public ResponseEntity getOne(@PathVariable String id) { + Optional order = orderService.findById(id); + return order.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - + + @GetMapping("/customer/{customerId}") + @Operation(summary = "Получить заказы по ID клиента") + public List getByCustomer(@PathVariable String customerId) { + return orderService.findByCustomerId(customerId); + } + @GetMapping("/status/{status}") @Operation(summary = "Получить заказы по статусу") - public List getOrdersByStatus(@PathVariable String status) { - return orders.stream() - .filter(o -> o.getStatus().equalsIgnoreCase(status)) - .toList(); + public List getByStatus(@PathVariable String status) { + return orderService.findByStatus(status); } - - @GetMapping("/sorted/by-status") - @Operation(summary = "Получить заказы отсортированные по статусу") - public List getOrdersSortedByStatus() { - return orders.stream() - .sorted(Comparator.comparing(OrderDTO::getStatus)) - .toList(); - } - + @PostMapping @Operation(summary = "Создать новый заказ") - public OrderDTO create(@RequestBody OrderDTO order) { - if (order.getId() == null || order.getId().isEmpty()) { - order.setId("order_" + System.currentTimeMillis()); + public ResponseEntity create(@Valid @RequestBody OrderRq orderRq) { + try { + OrderRs created = orderService.create(orderRq); + return ResponseEntity.ok(created); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().body(e.getMessage()); } - orders.add(order); - return order; } - + @PutMapping("/{id}") @Operation(summary = "Обновить заказ") - public OrderDTO update(@PathVariable String id, @RequestBody OrderDTO updatedOrder) { - Optional existing = orders.stream() - .filter(o -> o.getId().equals(id)) - .findFirst(); - - if (existing.isPresent()) { - OrderDTO order = existing.get(); - order.setCustomer(updatedOrder.getCustomer()); - order.setDelivery(updatedOrder.getDelivery()); - order.setStatus(updatedOrder.getStatus()); - return order; + public ResponseEntity update(@PathVariable String id, @Valid @RequestBody OrderRq orderRq) { + try { + Optional updated = orderService.update(id, orderRq); + return updated.map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().body(e.getMessage()); } - return null; } - + @DeleteMapping("/{id}") @Operation(summary = "Удалить заказ") - public void delete(@PathVariable String id) { - orders.removeIf(o -> o.getId().equals(id)); + public ResponseEntity delete(@PathVariable String id) { + boolean deleted = orderService.delete(id); + return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } } \ 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 new file mode 100644 index 0000000..65588ed --- /dev/null +++ b/src/main/java/com/example/dto/CustomerRq.java @@ -0,0 +1,28 @@ +package com.example.dto; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; + +public class CustomerRq { + @NotBlank(message = "Имя обязательно") + private String name; + + @NotBlank(message = "Email обязателен") + @Email(message = "Некорректный формат email") + private String email; + + // Конструкторы + public CustomerRq() {} + + public CustomerRq(String name, String email) { + this.name = name; + this.email = email; + } + + // Геттеры и сеттеры + public String getName() { return name; } + public void setName(String name) { this.name = name; } + + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } +} \ No newline at end of file diff --git a/src/main/java/com/example/dto/CustomerRs.java b/src/main/java/com/example/dto/CustomerRs.java new file mode 100644 index 0000000..d93b755 --- /dev/null +++ b/src/main/java/com/example/dto/CustomerRs.java @@ -0,0 +1,16 @@ +package com.example.dto; + +public class CustomerRs { + private String id; + private String name; + private String email; + + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public String getName() { return name; } + public void setName(String name) { this.name = name; } + + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } +} \ No newline at end of file diff --git a/src/main/java/com/example/dto/DeliveryRq.java b/src/main/java/com/example/dto/DeliveryRq.java new file mode 100644 index 0000000..93d5d53 --- /dev/null +++ b/src/main/java/com/example/dto/DeliveryRq.java @@ -0,0 +1,37 @@ +package com.example.dto; + +import jakarta.validation.constraints.NotBlank; + +public class DeliveryRq { + @NotBlank(message = "Трек номер обязателен") + private String trackingNumber; + + @NotBlank(message = "Адрес назначения обязателен") + private String destination; + + @NotBlank(message = "Статус обязателен") + private String status; + + private String customer; + + public String getTrackingNumber() { return trackingNumber; } + public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } + + public String getDestination() { return destination; } + public void setDestination(String destination) { this.destination = destination; } + + 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; + } +} \ 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 new file mode 100644 index 0000000..f6ba4c7 --- /dev/null +++ b/src/main/java/com/example/dto/DeliveryRs.java @@ -0,0 +1,24 @@ +package com.example.dto; + +public class DeliveryRs { + private String id; + private String trackingNumber; + private String destination; + private String status; + private String customer; + + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public String getTrackingNumber() { return trackingNumber; } + public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } + + public String getDestination() { return destination; } + public void setDestination(String destination) { this.destination = destination; } + + 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; } +} \ No newline at end of file diff --git a/src/main/java/com/example/dto/OrderRq.java b/src/main/java/com/example/dto/OrderRq.java new file mode 100644 index 0000000..1c046be --- /dev/null +++ b/src/main/java/com/example/dto/OrderRq.java @@ -0,0 +1,32 @@ +package com.example.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public class OrderRq { + @NotBlank(message = "ID клиента обязателен") + private String customerId; + + @NotBlank(message = "ID доставки обязателен") + private String deliveryId; + + @NotBlank(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) { + this.customerId = customerId; + this.deliveryId = deliveryId; + 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 new file mode 100644 index 0000000..8d74bc7 --- /dev/null +++ b/src/main/java/com/example/dto/OrderRs.java @@ -0,0 +1,21 @@ +package com.example.dto; + +public class OrderRs { + private String id; + private CustomerRs customer; + private DeliveryRs delivery; + private String status; + + // Геттеры и сеттеры + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public CustomerRs getCustomer() { return customer; } + public void setCustomer(CustomerRs customer) { this.customer = customer; } + + public DeliveryRs getDelivery() { return delivery; } + public void setDelivery(DeliveryRs delivery) { this.delivery = delivery; } + + 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/entity/BaseEntity.java b/src/main/java/com/example/entity/BaseEntity.java new file mode 100644 index 0000000..d0a4b08 --- /dev/null +++ b/src/main/java/com/example/entity/BaseEntity.java @@ -0,0 +1,8 @@ +package com.example.entity; + +public abstract class BaseEntity { + protected String id; + + public String getId() { return id; } + public void setId(String id) { this.id = id; } +} diff --git a/src/main/java/com/example/entity/Customer.java b/src/main/java/com/example/entity/Customer.java new file mode 100644 index 0000000..648e346 --- /dev/null +++ b/src/main/java/com/example/entity/Customer.java @@ -0,0 +1,27 @@ +package com.example.entity; + +import java.util.ArrayList; +import java.util.List; + +public class Customer extends BaseEntity { + private String name; + private String email; + private List orders = new ArrayList<>(); + + public Customer() {} + + public Customer(String name, String email) { + this.name = name; + this.email = email; + } + + public String getName() { return name; } + public void setName(String name) { this.name = name; } + + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } + + public List getOrders() { return orders; } + public void setOrders(List orders) { this.orders = orders; } + public void addOrder(Order order) { this.orders.add(order); } +} \ 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 new file mode 100644 index 0000000..7ff23dc --- /dev/null +++ b/src/main/java/com/example/entity/Delivery.java @@ -0,0 +1,29 @@ +package com.example.entity; + +public class Delivery extends BaseEntity { + private String trackingNumber; + private String destination; + private String status; + private String customer; + + public Delivery() {} + + public Delivery(String trackingNumber, String destination, String status, String customer) { + this.trackingNumber = trackingNumber; + this.destination = destination; + this.status = status; + this.customer = customer; + } + + public String getTrackingNumber() { return trackingNumber; } + public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } + + public String getDestination() { return destination; } + public void setDestination(String destination) { this.destination = destination; } + + 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; } +} \ 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 new file mode 100644 index 0000000..f5374e2 --- /dev/null +++ b/src/main/java/com/example/entity/Order.java @@ -0,0 +1,25 @@ +package com.example.entity; + +public class Order extends BaseEntity { + private Customer customer; + private Delivery delivery; + private String status; + + // Конструкторы + public Order() {} + + public Order(Customer customer, Delivery delivery, String status) { + this.customer = customer; + this.delivery = delivery; + 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 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/mapper/CustomerMapper.java b/src/main/java/com/example/mapper/CustomerMapper.java new file mode 100644 index 0000000..c2116db --- /dev/null +++ b/src/main/java/com/example/mapper/CustomerMapper.java @@ -0,0 +1,25 @@ +package com.example.mapper; + +import com.example.entity.Customer; +import com.example.dto.CustomerRq; +import com.example.dto.CustomerRs; +import org.springframework.stereotype.Component; + +@Component +public class CustomerMapper { + + public Customer toEntity(CustomerRq customerRq) { + Customer customer = new Customer(); + customer.setName(customerRq.getName()); + customer.setEmail(customerRq.getEmail()); + return customer; + } + + public CustomerRs toResponse(Customer customer) { + CustomerRs customerRs = new CustomerRs(); + customerRs.setId(customer.getId()); + customerRs.setName(customer.getName()); + customerRs.setEmail(customer.getEmail()); + return customerRs; + } +} \ 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 new file mode 100644 index 0000000..6711698 --- /dev/null +++ b/src/main/java/com/example/mapper/DeliveryMapper.java @@ -0,0 +1,29 @@ +package com.example.mapper; + +import com.example.entity.Delivery; +import com.example.dto.DeliveryRq; +import com.example.dto.DeliveryRs; +import org.springframework.stereotype.Component; + +@Component +public class DeliveryMapper { + + public Delivery toEntity(DeliveryRq deliveryRq) { + Delivery delivery = new Delivery(); + delivery.setTrackingNumber(deliveryRq.getTrackingNumber()); + delivery.setDestination(deliveryRq.getDestination()); + delivery.setStatus(deliveryRq.getStatus()); + delivery.setCustomer(deliveryRq.getCustomer()); + return delivery; + } + + public DeliveryRs toResponse(Delivery delivery) { + DeliveryRs deliveryRs = new DeliveryRs(); + deliveryRs.setId(delivery.getId()); + deliveryRs.setTrackingNumber(delivery.getTrackingNumber()); + deliveryRs.setDestination(delivery.getDestination()); + deliveryRs.setStatus(delivery.getStatus()); + deliveryRs.setCustomer(delivery.getCustomer()); + return deliveryRs; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/mapper/OrderMapper.java b/src/main/java/com/example/mapper/OrderMapper.java new file mode 100644 index 0000000..da3f706 --- /dev/null +++ b/src/main/java/com/example/mapper/OrderMapper.java @@ -0,0 +1,61 @@ +package com.example.mapper; + +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.dto.CustomerRs; +import com.example.dto.DeliveryRs; +import com.example.repository.CustomerRepository; +import com.example.repository.DeliveryRepository; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +@Component +public class OrderMapper { + + private final CustomerRepository customerRepository; + private final DeliveryRepository deliveryRepository; + private final CustomerMapper customerMapper; + private final DeliveryMapper deliveryMapper; + + public OrderMapper(CustomerRepository customerRepository, + DeliveryRepository deliveryRepository, + CustomerMapper customerMapper, + DeliveryMapper deliveryMapper) { + this.customerRepository = customerRepository; + this.deliveryRepository = deliveryRepository; + this.customerMapper = customerMapper; + this.deliveryMapper = deliveryMapper; + } + + public Order toEntity(OrderRq orderRq) { + Optional customer = customerRepository.findById(orderRq.getCustomerId()); + Optional delivery = deliveryRepository.findById(orderRq.getDeliveryId()); + + if (customer.isEmpty() || delivery.isEmpty()) { + throw new IllegalArgumentException("Customer или Delivery не найдены"); + } + + Order order = new Order(); + order.setCustomer(customer.get()); + order.setDelivery(delivery.get()); + order.setStatus(orderRq.getStatus()); + return order; + } + + public OrderRs toResponse(Order order) { + OrderRs orderRs = new OrderRs(); + orderRs.setId(order.getId()); + + CustomerRs customerRs = customerMapper.toResponse(order.getCustomer()); + DeliveryRs deliveryRs = deliveryMapper.toResponse(order.getDelivery()); + + orderRs.setCustomer(customerRs); + orderRs.setDelivery(deliveryRs); + orderRs.setStatus(order.getStatus()); + 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 new file mode 100644 index 0000000..cb059b9 --- /dev/null +++ b/src/main/java/com/example/repository/CommonRepository.java @@ -0,0 +1,12 @@ +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 new file mode 100644 index 0000000..88569d6 --- /dev/null +++ b/src/main/java/com/example/repository/CustomerRepository.java @@ -0,0 +1,15 @@ +package com.example.repository; + +import com.example.entity.Customer; +import org.springframework.stereotype.Repository; + +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(); + } +} \ 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 new file mode 100644 index 0000000..4c8727c --- /dev/null +++ b/src/main/java/com/example/repository/DeliveryRepository.java @@ -0,0 +1,15 @@ +package com.example.repository; + +import com.example.entity.Delivery; +import org.springframework.stereotype.Repository; + +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(); + } +} \ 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 new file mode 100644 index 0000000..caa6d7f --- /dev/null +++ b/src/main/java/com/example/repository/MapRepository.java @@ -0,0 +1,43 @@ +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())); + } + 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 new file mode 100644 index 0000000..8d7be90 --- /dev/null +++ b/src/main/java/com/example/repository/OrderRepository.java @@ -0,0 +1,29 @@ +package com.example.repository; + +import com.example.entity.Order; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +@Repository +public class OrderRepository extends MapRepository { + + public List findByCustomerId(String customerId) { + return storage.values().stream() + .filter(order -> order.getCustomer().getId().equals(customerId)) + .toList(); + } + + public List findByDeliveryId(String deliveryId) { + return storage.values().stream() + .filter(order -> order.getDelivery().getId().equals(deliveryId)) + .toList(); + } + + public List findByStatus(String status) { + return storage.values().stream() + .filter(order -> order.getStatus().equals(status)) + .toList(); + } +} \ 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 new file mode 100644 index 0000000..7a57710 --- /dev/null +++ b/src/main/java/com/example/service/CustomerService.java @@ -0,0 +1,70 @@ +package com.example.service; + +import com.example.entity.Customer; +import com.example.dto.CustomerRq; +import com.example.dto.CustomerRs; +import com.example.mapper.CustomerMapper; +import com.example.repository.CustomerRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class CustomerService { + + private final CustomerRepository customerRepository; + private final CustomerMapper customerMapper; + + 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); + } + } + + public List findAll() { + return customerRepository.findAll().stream() + .map(customerMapper::toResponse) + .toList(); + } + + public Optional findById(String id) { + return customerRepository.findById(id) + .map(customerMapper::toResponse); + } + + public CustomerRs create(CustomerRq customerRq) { + Customer customer = customerMapper.toEntity(customerRq); + Customer saved = customerRepository.save(customer); + return customerMapper.toResponse(saved); + } + + public Optional update(String id, CustomerRq customerRq) { + return customerRepository.findById(id) + .map(customer -> { + customer.setName(customerRq.getName()); + customer.setEmail(customerRq.getEmail()); + Customer updated = customerRepository.save(customer); + return customerMapper.toResponse(updated); + }); + } + + public boolean delete(String id) { + if (customerRepository.existsById(id)) { + customerRepository.deleteById(id); + return true; + } + return false; + } +} \ 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 new file mode 100644 index 0000000..db8115d --- /dev/null +++ b/src/main/java/com/example/service/DeliveryService.java @@ -0,0 +1,70 @@ +package com.example.service; + +import com.example.entity.Delivery; +import com.example.dto.DeliveryRq; +import com.example.dto.DeliveryRs; +import com.example.mapper.DeliveryMapper; +import com.example.repository.DeliveryRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class DeliveryService { + + private final DeliveryRepository deliveryRepository; + private final DeliveryMapper deliveryMapper; + + 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); + } + } + + public List findAll() { + return deliveryRepository.findAll().stream() + .map(deliveryMapper::toResponse) + .toList(); + } + + public Optional findById(String id) { + return deliveryRepository.findById(id) + .map(deliveryMapper::toResponse); + } + + public DeliveryRs create(DeliveryRq deliveryRq) { + Delivery delivery = deliveryMapper.toEntity(deliveryRq); + Delivery saved = deliveryRepository.save(delivery); + return deliveryMapper.toResponse(saved); + } + + public Optional update(String 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 updated = deliveryRepository.save(delivery); + return deliveryMapper.toResponse(updated); + }); + } + + public boolean delete(String id) { + if (deliveryRepository.existsById(id)) { + deliveryRepository.deleteById(id); + return true; + } + return false; + } +} \ 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 new file mode 100644 index 0000000..59777a5 --- /dev/null +++ b/src/main/java/com/example/service/OrderService.java @@ -0,0 +1,97 @@ +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.mapper.OrderMapper; +import com.example.repository.OrderRepository; +import com.example.repository.CustomerRepository; +import com.example.repository.DeliveryRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class OrderService { + + private final OrderRepository orderRepository; + private final CustomerRepository customerRepository; + private final DeliveryRepository deliveryRepository; + private final OrderMapper orderMapper; + + public OrderService(OrderRepository orderRepository, + CustomerRepository customerRepository, + DeliveryRepository deliveryRepository, + OrderMapper orderMapper) { + this.orderRepository = orderRepository; + 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); + } + } + } + + public List findAll() { + return orderRepository.findAll().stream() + .map(orderMapper::toResponse) + .toList(); + } + + public Optional findById(String id) { + return orderRepository.findById(id) + .map(orderMapper::toResponse); + } + + public List findByCustomerId(String customerId) { + return orderRepository.findByCustomerId(customerId).stream() + .map(orderMapper::toResponse) + .toList(); + } + + public List findByStatus(String status) { + return orderRepository.findByStatus(status).stream() + .map(orderMapper::toResponse) + .toList(); + } + + public OrderRs create(OrderRq orderRq) { + Order order = orderMapper.toEntity(orderRq); + Order saved = orderRepository.save(order); + return orderMapper.toResponse(saved); + } + + public Optional update(String id, OrderRq orderRq) { + return orderRepository.findById(id) + .map(order -> { + Order updatedOrder = orderMapper.toEntity(orderRq); + updatedOrder.setId(id); // Сохраняем оригинальный ID + Order saved = orderRepository.save(updatedOrder); + return orderMapper.toResponse(saved); + }); + } + + public boolean delete(String id) { + if (orderRepository.existsById(id)) { + orderRepository.deleteById(id); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/test/java/com/example/controller/CustomerControllerTest.java b/src/test/java/com/example/controller/CustomerControllerTest.java new file mode 100644 index 0000000..33c0e88 --- /dev/null +++ b/src/test/java/com/example/controller/CustomerControllerTest.java @@ -0,0 +1,5 @@ +package com.example.controller; + +public class CustomerControllerTest { + +} diff --git a/src/test/java/com/example/controller/DeliveryControllerTest.java b/src/test/java/com/example/controller/DeliveryControllerTest.java new file mode 100644 index 0000000..c219dcf --- /dev/null +++ b/src/test/java/com/example/controller/DeliveryControllerTest.java @@ -0,0 +1,5 @@ +package com.example.controller; + +public class DeliveryControllerTest { + +} diff --git a/src/test/java/com/example/controller/OrderControllerTest.java b/src/test/java/com/example/controller/OrderControllerTest.java new file mode 100644 index 0000000..51cd23e --- /dev/null +++ b/src/test/java/com/example/controller/OrderControllerTest.java @@ -0,0 +1,5 @@ +package com.example.controller; + +public class OrderControllerTest { + +} diff --git a/src/test/java/com/example/demo/DemoApplicationTests.java b/src/test/java/com/example/demo/DemoApplicationTests.java deleted file mode 100644 index 2778a6a..0000000 --- a/src/test/java/com/example/demo/DemoApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.demo; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DemoApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/com/example/service/CustomerServiceIntegrationTest.java b/src/test/java/com/example/service/CustomerServiceIntegrationTest.java new file mode 100644 index 0000000..bdbc20f --- /dev/null +++ b/src/test/java/com/example/service/CustomerServiceIntegrationTest.java @@ -0,0 +1,116 @@ +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/DeliveryServiceIntegrationTest.java b/src/test/java/com/example/service/DeliveryServiceIntegrationTest.java new file mode 100644 index 0000000..96e86f2 --- /dev/null +++ b/src/test/java/com/example/service/DeliveryServiceIntegrationTest.java @@ -0,0 +1,143 @@ +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/OrderServiceIntegrationTest.java b/src/test/java/com/example/service/OrderServiceIntegrationTest.java new file mode 100644 index 0000000..ea92efc --- /dev/null +++ b/src/test/java/com/example/service/OrderServiceIntegrationTest.java @@ -0,0 +1,226 @@ +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