lab2 done

This commit is contained in:
2025-10-14 14:51:22 +04:00
parent 63fb0a92d7
commit 19c7ea79a9
71 changed files with 823 additions and 285 deletions

File diff suppressed because one or more lines are too long

View File

@@ -41,7 +41,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.349s</div>
<div class="counter">0.340s</div>
<p>duration</p>
</div>
</td>
@@ -82,7 +82,7 @@
</thead>
<tr>
<td class="success">createTest()</td>
<td class="success">0.002s</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -92,7 +92,7 @@
</tr>
<tr>
<td class="success">getTest_WhenCustomerNotExists_ShouldThrowException()</td>
<td class="success">0.344s</td>
<td class="success">0.336s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -105,8 +105,8 @@
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>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
<pre>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
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
@@ -117,9 +117,9 @@
:: Spring Boot :: (v3.5.5)
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: &quot;default&quot;
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)
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: &quot;default&quot;
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)
</pre>
</span>
</div>
@@ -142,7 +142,7 @@ WARNING: Dynamic loading of agents will be disallowed by default in a future rel
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 11 окт. 2025г., 10:23:40</p>
</div>
</div>
</body>

View File

@@ -41,7 +41,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.008s</div>
<div class="counter">0.007s</div>
<p>duration</p>
</div>
</td>
@@ -79,12 +79,12 @@
</thead>
<tr>
<td class="success">createTest()</td>
<td class="success">0.002s</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">deleteTest()</td>
<td class="success">0.001s</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -94,7 +94,7 @@
</tr>
<tr>
<td class="success">getTest_WhenDeliveryNotExists_ShouldThrowException()</td>
<td class="success">0.002s</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -107,8 +107,8 @@
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>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
<pre>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
</pre>
</span>
</div>
@@ -120,7 +120,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 11 окт. 2025г., 10:23:40</p>
</div>
</div>
</body>

View File

@@ -89,7 +89,7 @@
</tr>
<tr>
<td class="success">findByCustomerIdTest()</td>
<td class="success">0.002s</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -99,7 +99,7 @@
</tr>
<tr>
<td class="success">getTest_WhenOrderNotExists_ShouldThrowException()</td>
<td class="success">0.001s</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
@@ -112,8 +112,8 @@
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>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
<pre>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
</pre>
</span>
</div>
@@ -125,7 +125,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 11 окт. 2025г., 10:23:40</p>
</div>
</div>
</body>

View File

@@ -38,7 +38,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.364s</div>
<div class="counter">0.354s</div>
<p>duration</p>
</div>
</td>
@@ -85,7 +85,7 @@
<td>15</td>
<td>0</td>
<td>0</td>
<td>0.364s</td>
<td>0.354s</td>
<td class="success">100%</td>
</tr>
</tbody>
@@ -112,7 +112,7 @@
<td>4</td>
<td>0</td>
<td>0</td>
<td>0.349s</td>
<td>0.340s</td>
<td class="success">100%</td>
</tr>
<tr>
@@ -122,7 +122,7 @@
<td>5</td>
<td>0</td>
<td>0</td>
<td>0.008s</td>
<td>0.007s</td>
<td class="success">100%</td>
</tr>
<tr>
@@ -146,7 +146,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 11 окт. 2025г., 10:23:40</p>
</div>
</div>
</body>

View File

@@ -40,7 +40,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.364s</div>
<div class="counter">0.354s</div>
<p>duration</p>
</div>
</td>
@@ -83,7 +83,7 @@
<td>4</td>
<td>0</td>
<td>0</td>
<td>0.349s</td>
<td>0.340s</td>
<td class="success">100%</td>
</tr>
<tr>
@@ -93,7 +93,7 @@
<td>5</td>
<td>0</td>
<td>0</td>
<td>0.008s</td>
<td>0.007s</td>
<td class="success">100%</td>
</tr>
<tr>
@@ -116,7 +116,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 11 окт. 2025г., 10:23:40</p>
</div>
</div>
</body>

View File

@@ -0,0 +1 @@
com.example.DemoApplication

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.CustomerServiceIntegrationTest" tests="4" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:03.652Z" hostname="MacBook-Air-Oleg.local" time="0.35">
<testsuite name="com.example.service.CustomerServiceIntegrationTest" tests="4" skipped="0" failures="0" errors="0" timestamp="2025-10-11T06:23:40.109Z" hostname="MacBook-Air-Oleg.local" time="0.342">
<properties/>
<testcase name="getTest_WhenCustomerNotExists_ShouldThrowException()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.344"/>
<testcase name="getTest_WhenCustomerNotExists_ShouldThrowException()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.336"/>
<testcase name="updateTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.002"/>
<testcase name="createTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.002"/>
<testcase name="createTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.001"/>
<testcase name="deleteTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.001"/>
<system-out><![CDATA[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
<system-out><![CDATA[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
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
@@ -17,9 +17,9 @@
:: Spring Boot :: (v3.5.5)
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)
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)
]]></system-out>
<system-err><![CDATA[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
WARNING: A Java agent has been loaded dynamically (/Users/floom/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.17.7/fbf3d6d649ed37fc9e9c59480a05be0a26e3c2da/byte-buddy-agent-1.17.7.jar)

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.DeliveryServiceIntegrationTest" tests="5" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:04.006Z" hostname="MacBook-Air-Oleg.local" time="0.008">
<testsuite name="com.example.service.DeliveryServiceIntegrationTest" tests="5" skipped="0" failures="0" errors="0" timestamp="2025-10-11T06:23:40.454Z" hostname="MacBook-Air-Oleg.local" time="0.008">
<properties/>
<testcase name="updateTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<testcase name="findByTrackingNumberTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<testcase name="createTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<testcase name="deleteTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<testcase name="getTest_WhenDeliveryNotExists_ShouldThrowException()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<system-out><![CDATA[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
<testcase name="createTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<testcase name="deleteTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<testcase name="getTest_WhenDeliveryNotExists_ShouldThrowException()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<system-out><![CDATA[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
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>

View File

@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.OrderServiceIntegrationTest" tests="6" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:04.017Z" hostname="MacBook-Air-Oleg.local" time="0.009">
<testsuite name="com.example.service.OrderServiceIntegrationTest" tests="6" skipped="0" failures="0" errors="0" timestamp="2025-10-11T06:23:40.465Z" hostname="MacBook-Air-Oleg.local" time="0.009">
<properties/>
<testcase name="findByStatusTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="updateTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="getTest_WhenOrderNotExists_ShouldThrowException()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="getTest_WhenOrderNotExists_ShouldThrowException()" classname="com.example.service.OrderServiceIntegrationTest" time="0.002"/>
<testcase name="createTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="findByCustomerIdTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.002"/>
<testcase name="findByCustomerIdTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="deleteTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<system-out><![CDATA[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
<system-out><![CDATA[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
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>

View File

@@ -1,35 +1,28 @@
function OrderItem({ order, onEdit, onDelete }) {
return (
<div style={{
border: '1px solid #ccc',
padding: '15px',
margin: '10px 0',
borderRadius: '5px'
}}>
<h4>Заказ #{order.id}</h4>
<p><strong>Клиент:</strong> {order.customer?.name} ({order.customer?.email})</p>
<p><strong>Доставка:</strong> {order.delivery?.trackingNumber} - {order.delivery?.destination}</p>
<p><strong>Статус:</strong>
<span style={{
color: order.status === 'Доставлено' ? 'green' :
order.status === 'В пути' ? 'orange' : 'gray',
fontWeight: 'bold',
marginLeft: '10px'
}}>
{order.status}
</span>
</p>
<div style={{ marginTop: '10px' }}>
<button onClick={() => onEdit(order)} style={{ marginRight: '10px' }}>
Редактировать
</button>
<button onClick={() => onDelete(order.id)} style={{ background: '#ff4444', color: 'white' }}>
Удалить
</button>
</div>
</div>
);
return (
<div style={{
border: '1px solid #ccc',
padding: '15px',
margin: '10px 0',
borderRadius: '5px'
}}>
<h4>Заказ #{order.id}</h4>
<p><strong>Клиент:</strong> {order.customer?.name} ({order.customer?.email})</p>
<p><strong>Доставка:</strong> {order.delivery?.trackingNumber} - {order.delivery?.destination}</p>
<p><strong>Статус:</strong>
<span style={{
color: order.status === 'Доставлено' ? 'green' :
order.status === 'В пути' ? 'orange' : 'gray',
fontWeight: 'bold',
marginLeft: '10px'
}}>
{order.status}
</span>
</p>
</div>
);
}
export default OrderItem;

View File

@@ -1,55 +0,0 @@
package com.example.dto;
import java.util.ArrayList;
import java.util.List;
public class CustomerDTO {
private String id;
private String name;
private String email;
private List<OrderDTO> orders = new ArrayList<>();
public CustomerDTO() {}
public CustomerDTO(String id, String name, String email) {
this.id = id;
this.name = name;
this.email = 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;
}
public List<OrderDTO> getOrders() {
return orders;
}
public void setOrders(List<OrderDTO> orders) {
this.orders = orders;
}
public void addOrder(OrderDTO order) {
this.orders.add(order);
}
}

View File

@@ -11,7 +11,7 @@ public class CustomerRq {
@Email(message = "Некорректный формат email")
private String email;
// Конструкторы
public CustomerRq() {}
public CustomerRq(String name, String email) {
@@ -19,7 +19,7 @@ public class CustomerRq {
this.email = email;
}
// Геттеры и сеттеры
public String getName() { return name; }
public void setName(String name) { this.name = name; }

View File

@@ -1,10 +1,15 @@
package com.example.dto;
import java.time.LocalDateTime;
public class CustomerRs {
private String 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; }
@@ -13,4 +18,10 @@ public class CustomerRs {
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
}

View File

@@ -1,34 +0,0 @@
package com.example.dto;
public class DeliveryDTO {
private String id;
private String trackingNumber;
private String destination;
private String status;
private String customer;
public DeliveryDTO() {}
public DeliveryDTO(String id, String trackingNumber, String destination, String status, String customer) {
this.id = id;
this.trackingNumber = trackingNumber;
this.destination = destination;
this.status = status;
this.customer = 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; }
}

View File

@@ -1,12 +1,17 @@
package com.example.dto;
import java.time.LocalDateTime;
public class DeliveryRs {
private String id;
private String trackingNumber;
private String destination;
private String status;
private String customer;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
@@ -21,4 +26,10 @@ public class DeliveryRs {
public String getCustomer() { return customer; }
public void setCustomer(String customer) { this.customer = customer; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
}

View File

@@ -1,51 +0,0 @@
package com.example.dto;
public class OrderDTO {
private String id;
private CustomerDTO customer; // объект вместо customerId
private DeliveryDTO delivery; // объект вместо deliveryId
private String status;
// Конструкторы
public OrderDTO() {}
public OrderDTO(String id, CustomerDTO customer, DeliveryDTO delivery, String status) {
this.id = id;
this.customer = customer;
this.delivery = delivery;
this.status = status;
}
// Геттеры и сеттеры
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public CustomerDTO getCustomer() {
return customer;
}
public void setCustomer(CustomerDTO customer) {
this.customer = customer;
}
public DeliveryDTO getDelivery() {
return delivery;
}
public void setDelivery(DeliveryDTO delivery) {
this.delivery = delivery;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@@ -1,12 +1,16 @@
package com.example.dto;
import java.time.LocalDateTime;
public class OrderRs {
private String id;
private CustomerRs customer;
private DeliveryRs delivery;
private CustomerRs customer;
private DeliveryRs delivery;
private String status;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
// Геттеры и сеттеры
public String getId() { return id; }
public void setId(String id) { this.id = id; }
@@ -18,4 +22,10 @@ public class OrderRs {
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
}

View File

@@ -1,8 +1,40 @@
package com.example.entity;
import java.time.LocalDateTime;
public abstract class BaseEntity {
protected String id;
protected LocalDateTime createdAt;
protected LocalDateTime updatedAt;
public BaseEntity() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}
public String getId() {
return id;
}
public String getId() { return id; }
public void setId(String id) { this.id = id; }
}
public void setId(String id) {
this.id = id;
this.updatedAt = LocalDateTime.now();
}
public LocalDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
public LocalDateTime getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@@ -5,7 +5,7 @@ public class Order extends BaseEntity {
private Delivery delivery;
private String status;
// Конструкторы
public Order() {}
public Order(Customer customer, Delivery delivery, String status) {

View File

@@ -20,6 +20,8 @@ public class CustomerMapper {
customerRs.setId(customer.getId());
customerRs.setName(customer.getName());
customerRs.setEmail(customer.getEmail());
customerRs.setCreatedAt(customer.getCreatedAt());
customerRs.setUpdatedAt(customer.getUpdatedAt());
return customerRs;
}
}

View File

@@ -24,6 +24,8 @@ public class DeliveryMapper {
deliveryRs.setDestination(delivery.getDestination());
deliveryRs.setStatus(delivery.getStatus());
deliveryRs.setCustomer(delivery.getCustomer());
deliveryRs.setCreatedAt(delivery.getCreatedAt());
deliveryRs.setUpdatedAt(delivery.getUpdatedAt());
return deliveryRs;
}
}

View File

@@ -1,47 +1,16 @@
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> customer = customerRepository.findById(orderRq.getCustomerId());
Optional<Delivery> 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;
}
@@ -49,13 +18,9 @@ public class OrderMapper {
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());
orderRs.setCreatedAt(order.getCreatedAt());
orderRs.setUpdatedAt(order.getUpdatedAt());
return orderRs;
}
}

View File

@@ -25,8 +25,12 @@ public abstract class MapRepository<T extends BaseEntity> implements CommonRepos
@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;
}

View File

@@ -35,7 +35,6 @@ public class OrderService {
private void initializeTestData() {
if (orderRepository.findAll().isEmpty()) {
// Берем тестовых клиентов и доставки
List<Customer> customers = customerRepository.findAll();
List<Delivery> deliveries = deliveryRepository.findAll();
@@ -81,7 +80,7 @@ public class OrderService {
return orderRepository.findById(id)
.map(order -> {
Order updatedOrder = orderMapper.toEntity(orderRq);
updatedOrder.setId(id); // Сохраняем оригинальный ID
updatedOrder.setId(id);
Order saved = orderRepository.save(updatedOrder);
return orderMapper.toResponse(saved);
});

View File

@@ -1,5 +0,0 @@
package com.example.controller;
public class CustomerControllerTest {
}

View File

@@ -1,5 +0,0 @@
package com.example.controller;
public class DeliveryControllerTest {
}

View File

@@ -1,5 +0,0 @@
package com.example.controller;
public class OrderControllerTest {
}