44import dev .nano .clients .order .OrderResponse ;
55import dev .nano .clients .payment .PaymentRequest ;
66import 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 ;
714import jakarta .validation .Valid ;
815import lombok .AllArgsConstructor ;
916import lombok .extern .slf4j .Slf4j ;
1017import org .springframework .http .HttpStatus ;
1118import org .springframework .http .ResponseEntity ;
1219import org .springframework .web .bind .annotation .*;
20+ import swagger .BaseController ;
1321
1422import java .util .List ;
1523
1826
1927@ RestController
2028@ RequestMapping (path = CUSTOMER_URI_REST_API )
29+ @ Tag (name = BaseController .CUSTOMER_TAG , description = BaseController .CUSTOMER_DESCRIPTION )
2130@ AllArgsConstructor @ Slf4j
2231public class CustomerController {
2332
2433 private final CustomerService customerService ;
2534
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}" )
2752 public ResponseEntity <CustomerDTO > getCustomer (@ PathVariable ("customerId" ) Long customerId ) {
2853 log .info ("Retrieving customer with ID: {}" , customerId );
2954 return ResponseEntity .ok (customerService .getCustomer (customerId ));
3055 }
3156
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+ })
3272 @ GetMapping
3373 public ResponseEntity <List <CustomerDTO >> getAllCustomers () {
3474 log .info ("Retrieving all customers" );
3575 return ResponseEntity .ok (customerService .getAllCustomers ());
3676 }
3777
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+ })
3894 @ PostMapping ("/add" )
3995 public ResponseEntity <CustomerDTO > createCustomer (@ Valid @ RequestBody CustomerDTO customerDTO ) {
4096 log .info ("Creating new customer: {}" , customerDTO );
@@ -44,6 +100,23 @@ public ResponseEntity<CustomerDTO> createCustomer(@Valid @RequestBody CustomerDT
44100 );
45101 }
46102
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+ })
47120 @ PutMapping ("/{customerId}" )
48121 public ResponseEntity <CustomerDTO > updateCustomer (
49122 @ PathVariable Long customerId ,
@@ -52,13 +125,39 @@ public ResponseEntity<CustomerDTO> updateCustomer(
52125 return ResponseEntity .ok (customerService .updateCustomer (customerId , customerDTO ));
53126 }
54127
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+ })
55137 @ DeleteMapping ("/{customerId}" )
56138 public ResponseEntity <Void > deleteCustomer (@ PathVariable Long customerId ) {
57139 log .info ("Deleting customer with ID: {}" , customerId );
58140 customerService .deleteCustomer (customerId );
59141 return ResponseEntity .noContent ().build ();
60142 }
61143
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+ })
62161 @ PostMapping ("/orders" )
63162 public ResponseEntity <OrderResponse > customerOrders (@ Valid @ RequestBody OrderRequest orderRequest ) {
64163 log .info ("Processing order for customer: {}" , orderRequest );
@@ -68,6 +167,23 @@ public ResponseEntity<OrderResponse> customerOrders(@Valid @RequestBody OrderReq
68167 );
69168 }
70169
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+ })
71187 @ PostMapping ("/payment" )
72188 public ResponseEntity <PaymentResponse > customerPayment (@ Valid @ RequestBody PaymentRequest paymentRequest ) {
73189 log .info ("Processing payment for customer: {}" , paymentRequest );
0 commit comments