@@ -66,88 +66,88 @@ public List<Product> getAllProducts(){
66
66
}
67
67
68
68
69
- // @Operation(summary = "Create a Products")
70
- // @ApiResponses(value = {
71
- // @ApiResponse(
72
- // responseCode = "201",
73
- // description = "Successful Products creation",
74
- // content = {@Content(
75
- // mediaType = "application/json"
76
- // )}
77
- // ),
78
- // @ApiResponse(
79
- // responseCode = "406",
80
- // description = "Not Acceptable Post title exists",
81
- // content = @Content
82
- // )
83
- // })
84
- // @JsonView(Product.Detailed.class)
85
- // @PostMapping("/")
86
- // public ResponseEntity<Product> registerProduct( @Parameter(description="Object Type Product") @RequestBody Product product) throws IOException{
87
- // if (productService.existsProduct(product.getTitle ())) {
88
- // return new ResponseEntity<Product>(product,HttpStatus.NOT_ACCEPTABLE);
89
- // }
90
- // product.setImg1(false);
91
- // product.setImg2(false);
92
- // product.setImg3(false);
93
- // productService.save(product);
94
- // product = productService.getProductByTitle (product.getTitle ());
95
- // URI location = fromCurrentRequest().path("/{id}").buildAndExpand(product.getIdproduct()).toUri();
96
- // return ResponseEntity.created(location).body(product);
97
- // }
69
+ @ Operation (summary = "Create a Products" )
70
+ @ ApiResponses (value = {
71
+ @ ApiResponse (
72
+ responseCode = "201" ,
73
+ description = "Successful Products creation" ,
74
+ content = {@ Content (
75
+ mediaType = "application/json"
76
+ )}
77
+ ),
78
+ @ ApiResponse (
79
+ responseCode = "406" ,
80
+ description = "Not Acceptable Post title exists" ,
81
+ content = @ Content
82
+ )
83
+ })
84
+ @ JsonView (Product .Detailed .class )
85
+ @ PostMapping ("/" )
86
+ public ResponseEntity <Product > registerProduct ( @ Parameter (description ="Object Type Product" ) @ RequestBody Product product ) throws IOException {
87
+ if (productService .existsProduct (product .getNameproduct ())) {
88
+ return new ResponseEntity <Product >(product ,HttpStatus .NOT_ACCEPTABLE );
89
+ }
90
+ product .setImg1 (false );
91
+ product .setImg2 (false );
92
+ product .setImg3 (false );
93
+ productService .save (product );
94
+ product = productService .getProductByName (product .getNameproduct ());
95
+ URI location = fromCurrentRequest ().path ("/{id}" ).buildAndExpand (product .getIdproduct ()).toUri ();
96
+ return ResponseEntity .created (location ).body (product );
97
+ }
98
98
99
- // @Operation(summary = "Get a products by its id")
100
- // @ApiResponses(value = {
101
- // @ApiResponse(
102
- // responseCode = "200",
103
- // description = "Found the Product",
104
- // content = {@Content(
105
- // mediaType = "application/json"
106
- // )}
107
- // ),
108
- // @ApiResponse(
109
- // responseCode = "404",
110
- // description = "Product not found",
111
- // content = @Content
112
- // )
113
- // })
114
- // @JsonView(Product.Detailed.class)
115
- // @GetMapping("/{id}")
116
- // public ResponseEntity<Product> getProduct ( @Parameter(description="id of Product to be searched") @PathVariable int id) throws IOException{
117
- // Optional<Product> product = productService.getProductById(id);
118
- // if(!product.isEmpty()) {
119
- // return ResponseEntity.ok(product.get());
120
- // }else {
121
- // return ResponseEntity.notFound().build();
122
- // }
123
- // }
99
+ @ Operation (summary = "Get a products by its id" )
100
+ @ ApiResponses (value = {
101
+ @ ApiResponse (
102
+ responseCode = "200" ,
103
+ description = "Found the Product" ,
104
+ content = {@ Content (
105
+ mediaType = "application/json"
106
+ )}
107
+ ),
108
+ @ ApiResponse (
109
+ responseCode = "404" ,
110
+ description = "Product not found" ,
111
+ content = @ Content
112
+ )
113
+ })
114
+ @ JsonView (Product .Detailed .class )
115
+ @ GetMapping ("/{id}" )
116
+ public ResponseEntity <Product > getProduct ( @ Parameter (description ="id of Product to be searched" ) @ PathVariable int id ) throws IOException {
117
+ Optional <Product > product = productService .getProductById (id );
118
+ if (!product .isEmpty ()) {
119
+ return ResponseEntity .ok (product .get ());
120
+ }else {
121
+ return ResponseEntity .notFound ().build ();
122
+ }
123
+ }
124
124
125
- // @Operation(summary = "Create a Product")
126
- // @ApiResponses(value = {
127
- // @ApiResponse(
128
- // responseCode = "201",
129
- // description = "Successful Product creation ",
130
- // content = {@Content(
131
- // mediaType = "application/json"
132
- // )}
133
- // ),
134
- // @ApiResponse(
135
- // responseCode = "404",
136
- // description = "Product not found",
137
- // content = @Content
138
- // )
139
- // })
140
- // @JsonView(Product.Detailed.class)
141
- // @DeleteMapping("/{id}")
142
- // public ResponseEntity<Product> deleteProduct( @Parameter(description="id of Product to be searched") @PathVariable int id){
143
- // Optional<Product> product = productService.getProductById(id);
144
- // if(product.isPresent()){
145
- // productService.deleteProductbyid (product.get().getIdproduct());
146
- // return ResponseEntity.ok(product.get());
147
- // }else {
148
- // return ResponseEntity.notFound().build();
149
- // }
150
- // }
125
+ @ Operation (summary = "Delete a Product" )
126
+ @ ApiResponses (value = {
127
+ @ ApiResponse (
128
+ responseCode = "201" ,
129
+ description = "Successful Product delete " ,
130
+ content = {@ Content (
131
+ mediaType = "application/json"
132
+ )}
133
+ ),
134
+ @ ApiResponse (
135
+ responseCode = "404" ,
136
+ description = "Product not found" ,
137
+ content = @ Content
138
+ )
139
+ })
140
+ @ JsonView (Product .Detailed .class )
141
+ @ DeleteMapping ("/{id}" )
142
+ public ResponseEntity <Product > deleteProduct ( @ Parameter (description ="id of Product to be searched" ) @ PathVariable int id ){
143
+ Optional <Product > product = productService .getProductById (id );
144
+ if (product .isPresent ()){
145
+ productService .deleteProductApiById (product .get ().getIdproduct ());
146
+ return ResponseEntity .ok (product .get ());
147
+ }else {
148
+ return ResponseEntity .notFound ().build ();
149
+ }
150
+ }
151
151
152
152
// @Operation(summary = "Modify a Product")
153
153
// @ApiResponses(value = {
0 commit comments