4
4
import dev .nano .clients .order .OrderResponse ;
5
5
import dev .nano .clients .payment .PaymentRequest ;
6
6
import dev .nano .clients .payment .PaymentResponse ;
7
+ import io .swagger .v3 .oas .annotations .Operation ;
8
+ import io .swagger .v3 .oas .annotations .media .ArraySchema ;
9
+ import io .swagger .v3 .oas .annotations .media .Content ;
10
+ import io .swagger .v3 .oas .annotations .media .Schema ;
11
+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
12
+ import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
13
+ import io .swagger .v3 .oas .annotations .tags .Tag ;
7
14
import jakarta .validation .Valid ;
8
15
import lombok .AllArgsConstructor ;
9
16
import lombok .extern .slf4j .Slf4j ;
10
17
import org .springframework .http .HttpStatus ;
11
18
import org .springframework .http .ResponseEntity ;
12
19
import org .springframework .web .bind .annotation .*;
20
+ import swagger .BaseController ;
13
21
14
22
import java .util .List ;
15
23
18
26
19
27
@ RestController
20
28
@ RequestMapping (path = CUSTOMER_URI_REST_API )
29
+ @ Tag (name = BaseController .CUSTOMER_TAG , description = BaseController .CUSTOMER_DESCRIPTION )
21
30
@ AllArgsConstructor @ Slf4j
22
31
public class CustomerController {
23
32
24
33
private final CustomerService customerService ;
25
34
26
- @ GetMapping (path = "/{customerId}" )
35
+ @ Operation (
36
+ summary = "Get customer by ID" ,
37
+ description = "Retrieve a customer's details using their unique identifier"
38
+ )
39
+ @ ApiResponses (value = {
40
+ @ ApiResponse (
41
+ responseCode = "200" ,
42
+ description = "Customer found successfully" ,
43
+ content = @ Content (
44
+ mediaType = "application/json" ,
45
+ schema = @ Schema (implementation = CustomerDTO .class )
46
+ )
47
+ ),
48
+ @ ApiResponse (responseCode = "404" , description = "Customer not found" ),
49
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
50
+ })
51
+ @ GetMapping ("/{customerId}" )
27
52
public ResponseEntity <CustomerDTO > getCustomer (@ PathVariable ("customerId" ) Long customerId ) {
28
53
log .info ("Retrieving customer with ID: {}" , customerId );
29
54
return ResponseEntity .ok (customerService .getCustomer (customerId ));
30
55
}
31
56
57
+ @ Operation (
58
+ summary = "Get all customers" ,
59
+ description = "Retrieve a list of all customers in the system"
60
+ )
61
+ @ ApiResponses (value = {
62
+ @ ApiResponse (
63
+ responseCode = "200" ,
64
+ description = "List of customers retrieved successfully" ,
65
+ content = @ Content (
66
+ mediaType = "application/json" ,
67
+ array = @ ArraySchema (schema = @ Schema (implementation = CustomerDTO .class ))
68
+ )
69
+ ),
70
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
71
+ })
32
72
@ GetMapping
33
73
public ResponseEntity <List <CustomerDTO >> getAllCustomers () {
34
74
log .info ("Retrieving all customers" );
35
75
return ResponseEntity .ok (customerService .getAllCustomers ());
36
76
}
37
77
78
+ @ Operation (
79
+ summary = "Create new customer" ,
80
+ description = "Register a new customer in the system with their details"
81
+ )
82
+ @ ApiResponses (value = {
83
+ @ ApiResponse (
84
+ responseCode = "201" ,
85
+ description = "Customer created successfully" ,
86
+ content = @ Content (
87
+ mediaType = "application/json" ,
88
+ schema = @ Schema (implementation = CustomerDTO .class )
89
+ )
90
+ ),
91
+ @ ApiResponse (responseCode = "400" , description = "Invalid input data" ),
92
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
93
+ })
38
94
@ PostMapping ("/add" )
39
95
public ResponseEntity <CustomerDTO > createCustomer (@ Valid @ RequestBody CustomerDTO customerDTO ) {
40
96
log .info ("Creating new customer: {}" , customerDTO );
@@ -44,6 +100,23 @@ public ResponseEntity<CustomerDTO> createCustomer(@Valid @RequestBody CustomerDT
44
100
);
45
101
}
46
102
103
+ @ Operation (
104
+ summary = "Update customer" ,
105
+ description = "Update an existing customer's information"
106
+ )
107
+ @ ApiResponses (value = {
108
+ @ ApiResponse (
109
+ responseCode = "200" ,
110
+ description = "Customer updated successfully" ,
111
+ content = @ Content (
112
+ mediaType = "application/json" ,
113
+ schema = @ Schema (implementation = CustomerDTO .class )
114
+ )
115
+ ),
116
+ @ ApiResponse (responseCode = "400" , description = "Invalid input data" ),
117
+ @ ApiResponse (responseCode = "404" , description = "Customer not found" ),
118
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
119
+ })
47
120
@ PutMapping ("/{customerId}" )
48
121
public ResponseEntity <CustomerDTO > updateCustomer (
49
122
@ PathVariable Long customerId ,
@@ -52,13 +125,39 @@ public ResponseEntity<CustomerDTO> updateCustomer(
52
125
return ResponseEntity .ok (customerService .updateCustomer (customerId , customerDTO ));
53
126
}
54
127
128
+ @ Operation (
129
+ summary = "Delete customer" ,
130
+ description = "Remove a customer from the database"
131
+ )
132
+ @ ApiResponses (value = {
133
+ @ ApiResponse (responseCode = "204" , description = "Customer deleted successfully" ),
134
+ @ ApiResponse (responseCode = "404" , description = "Customer not found" ),
135
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
136
+ })
55
137
@ DeleteMapping ("/{customerId}" )
56
138
public ResponseEntity <Void > deleteCustomer (@ PathVariable Long customerId ) {
57
139
log .info ("Deleting customer with ID: {}" , customerId );
58
140
customerService .deleteCustomer (customerId );
59
141
return ResponseEntity .noContent ().build ();
60
142
}
61
143
144
+ @ Operation (
145
+ summary = "Create customer order" ,
146
+ description = "Place a new order for an existing customer"
147
+ )
148
+ @ ApiResponses (value = {
149
+ @ ApiResponse (
150
+ responseCode = "201" ,
151
+ description = "Order created successfully" ,
152
+ content = @ Content (
153
+ mediaType = "application/json" ,
154
+ schema = @ Schema (implementation = OrderResponse .class )
155
+ )
156
+ ),
157
+ @ ApiResponse (responseCode = "400" , description = "Invalid order data" ),
158
+ @ ApiResponse (responseCode = "404" , description = "Customer not found" ),
159
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
160
+ })
62
161
@ PostMapping ("/orders" )
63
162
public ResponseEntity <OrderResponse > customerOrders (@ Valid @ RequestBody OrderRequest orderRequest ) {
64
163
log .info ("Processing order for customer: {}" , orderRequest );
@@ -68,6 +167,23 @@ public ResponseEntity<OrderResponse> customerOrders(@Valid @RequestBody OrderReq
68
167
);
69
168
}
70
169
170
+ @ Operation (
171
+ summary = "Process customer payment" ,
172
+ description = "Process a payment for a customer's order"
173
+ )
174
+ @ ApiResponses (value = {
175
+ @ ApiResponse (
176
+ responseCode = "201" ,
177
+ description = "Payment processed successfully" ,
178
+ content = @ Content (
179
+ mediaType = "application/json" ,
180
+ schema = @ Schema (implementation = PaymentResponse .class )
181
+ )
182
+ ),
183
+ @ ApiResponse (responseCode = "400" , description = "Invalid payment data" ),
184
+ @ ApiResponse (responseCode = "404" , description = "Customer or order not found" ),
185
+ @ ApiResponse (responseCode = "500" , description = "Internal server error" )
186
+ })
71
187
@ PostMapping ("/payment" )
72
188
public ResponseEntity <PaymentResponse > customerPayment (@ Valid @ RequestBody PaymentRequest paymentRequest ) {
73
189
log .info ("Processing payment for customer: {}" , paymentRequest );
0 commit comments