Skip to content

Commit 09861aa

Browse files
committed
update final
1 parent 3d81f1b commit 09861aa

File tree

7 files changed

+733
-247
lines changed

7 files changed

+733
-247
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
.openapi-generator-ignore
21
index.html
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a201d2c638e68b650f466a7ac819d407471fc2dc3a1e8d29045b9be1dcced9f4
1+
4eea05514f25e84e24f2723c638bc6380552784287f1a35f0859628fd72cd9a6

backend/webandtech/api-docs/api-docs.html

Lines changed: 608 additions & 198 deletions
Large diffs are not rendered by default.

backend/webandtech/api-docs/api-docs.yaml

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ paths:
125125
"404":
126126
description: Product not found
127127
content: {}
128-
"406":
129-
description: Not Acceptable Post title exists
130128
"201":
131129
description: Successful Product modification
132130
content:
133131
application/json: {}
132+
"406":
133+
description: Not Acceptable Post title exists
134134
delete:
135135
tags:
136136
- products-rest-controller
@@ -303,6 +303,73 @@ paths:
303303
description: Successful user creation
304304
content:
305305
application/json: {}
306+
/api/products/{id}/ratings:
307+
get:
308+
tags:
309+
- products-rest-controller
310+
summary: Ratings
311+
operationId: getProductRatings
312+
parameters:
313+
- name: id
314+
in: path
315+
description: id of Product to be searched
316+
required: true
317+
schema:
318+
type: integer
319+
format: int32
320+
- name: page
321+
in: query
322+
description: page
323+
required: false
324+
schema:
325+
type: string
326+
responses:
327+
"404":
328+
description: ratings not found
329+
content: {}
330+
"200":
331+
description: Found the ratings Product
332+
content:
333+
application/json: {}
334+
"204":
335+
description: ratings not found
336+
post:
337+
tags:
338+
- products-rest-controller
339+
summary: Ratings
340+
operationId: setProductRatings
341+
parameters:
342+
- name: id
343+
in: path
344+
description: id of Product to be searched
345+
required: true
346+
schema:
347+
type: integer
348+
format: int32
349+
requestBody:
350+
content:
351+
application/json:
352+
schema:
353+
type: object
354+
properties:
355+
ratingtext:
356+
type: string
357+
description: Text of rating
358+
iduser:
359+
type: integer
360+
description: Id user
361+
format: int32
362+
required: true
363+
responses:
364+
"404":
365+
description: ratings not found
366+
content: {}
367+
"200":
368+
description: Found the ratings Product
369+
content:
370+
application/json: {}
371+
"204":
372+
description: ratings not found
306373
/api/products/{id}/image3:
307374
get:
308375
tags:
@@ -321,12 +388,12 @@ paths:
321388
"404":
322389
description: Product not found
323390
content: {}
324-
"204":
325-
description: Image not found
326391
"200":
327392
description: Found the Image Product
328393
content:
329394
application/json: {}
395+
"204":
396+
description: Image not found
330397
post:
331398
tags:
332399
- products-rest-controller
@@ -380,12 +447,12 @@ paths:
380447
"404":
381448
description: Product not found
382449
content: {}
383-
"204":
384-
description: Image not found
385450
"200":
386451
description: Found the Image Product
387452
content:
388453
application/json: {}
454+
"204":
455+
description: Image not found
389456
post:
390457
tags:
391458
- products-rest-controller
@@ -439,12 +506,12 @@ paths:
439506
"404":
440507
description: Product not found
441508
content: {}
442-
"204":
443-
description: Image not found
444509
"200":
445510
description: Found the Image Product
446511
content:
447512
application/json: {}
513+
"204":
514+
description: Image not found
448515
post:
449516
tags:
450517
- products-rest-controller
@@ -598,36 +665,6 @@ paths:
598665
'*/*':
599666
schema:
600667
$ref: '#/components/schemas/AuthResponse'
601-
/api/products/{id}/ratings:
602-
get:
603-
tags:
604-
- products-rest-controller
605-
summary: Ratings
606-
operationId: getProductRatings
607-
parameters:
608-
- name: id
609-
in: path
610-
description: id of Product to be searched
611-
required: true
612-
schema:
613-
type: integer
614-
format: int32
615-
- name: page
616-
in: query
617-
description: page
618-
required: false
619-
schema:
620-
type: string
621-
responses:
622-
"404":
623-
description: Product not found
624-
content: {}
625-
"204":
626-
description: Image not found
627-
"200":
628-
description: Found the Image Product
629-
content:
630-
application/json: {}
631668
/api/products/phones:
632669
get:
633670
tags:

backend/webandtech/src/main/java/webapp8/webandtech/controller/api/products/ProductsRestController.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import io.swagger.v3.oas.annotations.responses.ApiResponses;
3939
import webapp8.webandtech.model.Product;
4040
import webapp8.webandtech.model.Rating;
41+
import webapp8.webandtech.model.User;
4142
import webapp8.webandtech.service.ProductService;
4243
import webapp8.webandtech.service.RatingService;
44+
import webapp8.webandtech.service.UserService;
4345

4446
@RestController
4547
@CrossOrigin
@@ -53,6 +55,9 @@ public class ProductsRestController {
5355
@Autowired
5456
private RatingService ratingService;
5557

58+
@Autowired
59+
private UserService userService;
60+
5661
@Operation(summary = "Get New Six Products")
5762
@ApiResponses(value = {
5863
@ApiResponse(
@@ -502,19 +507,19 @@ public List<Product> getPhonesPage ( @Parameter(description="page") @RequestPara
502507
@ApiResponses(value = {
503508
@ApiResponse(
504509
responseCode = "200",
505-
description = "Found the Image Product",
510+
description = "Found the ratings Product",
506511
content = {@Content(
507512
mediaType = "application/json"
508513
)}
509514
),
510515
@ApiResponse(
511516
responseCode = "404",
512-
description = "Product not found",
517+
description = "ratings not found",
513518
content = @Content
514519
),
515520
@ApiResponse(
516521
responseCode = "204",
517-
description = "Image not found",
522+
description = "ratings not found",
518523
content = @Content
519524
)
520525
})
@@ -530,6 +535,42 @@ public List<Rating> getProductRatings( @Parameter(description="id of Product to
530535

531536
}
532537

538+
@Operation(summary = "Ratings")
539+
@ApiResponses(value = {
540+
@ApiResponse(
541+
responseCode = "200",
542+
description = "Found the ratings Product",
543+
content = {@Content(
544+
mediaType = "application/json"
545+
)}
546+
),
547+
@ApiResponse(
548+
responseCode = "404",
549+
description = "ratings not found",
550+
content = @Content
551+
),
552+
@ApiResponse(
553+
responseCode = "204",
554+
description = "ratings not found",
555+
content = @Content
556+
)
557+
})
558+
@PostMapping("/{id}/ratings")
559+
public Rating setProductRatings( @Parameter(description="id of Product to be searched") @PathVariable int id, @Parameter(description="Text of rating") @RequestBody String ratingtext, @Parameter(description="Id user") @RequestBody int iduser) throws SQLException{
560+
Optional<Product> product = productService.getProductById(id);
561+
Optional<User> user = userService.getUserId(iduser);
562+
Rating rating = new Rating();
563+
if(!product.isEmpty()) {
564+
rating.setIduser(user.get());
565+
rating.setIdproduct(product.get());
566+
ratingService.save(rating);
567+
return rating;
568+
}else {
569+
return null;
570+
}
571+
572+
}
573+
533574

534575

535576
}

0 commit comments

Comments
 (0)