1 | package edu.gjoko.schedlr.controllers.rest;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.dto.ReviewDto;
|
---|
4 | import edu.gjoko.schedlr.entity.Review;
|
---|
5 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
6 | import edu.gjoko.schedlr.mappers.ReviewDtoMapper;
|
---|
7 | import edu.gjoko.schedlr.services.ReviewService;
|
---|
8 | import lombok.AllArgsConstructor;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | import javax.servlet.http.HttpServletRequest;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | @RestController
|
---|
15 | @RequestMapping("api/review")
|
---|
16 | @AllArgsConstructor
|
---|
17 | public class ReviewApi {
|
---|
18 |
|
---|
19 | private final ReviewService reviewService;
|
---|
20 | private final ReviewDtoMapper reviewDtoMapper;
|
---|
21 |
|
---|
22 | @PostMapping
|
---|
23 | public void getBusinessTypes(@RequestBody Review review, HttpServletRequest request) {
|
---|
24 | Long customerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
25 | Stakeholder customer = new Stakeholder();
|
---|
26 | customer.setId(customerId);
|
---|
27 | reviewService.save(review, customerId);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @GetMapping(path = "/me")
|
---|
31 | public List<ReviewDto> getReviews(HttpServletRequest request) {
|
---|
32 | Long customerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
33 | return reviewService.getReviewsByCustomerId(customerId).stream()
|
---|
34 | .map(reviewDtoMapper::mapToReviewDto)
|
---|
35 | .toList();
|
---|
36 | }
|
---|
37 |
|
---|
38 | @GetMapping(path = "/{serviceId}")
|
---|
39 | public List<ReviewDto> getReviewsForService(@PathVariable("serviceId") Long serviceId) {
|
---|
40 | return reviewService.getReviewsByServiceId(serviceId).stream()
|
---|
41 | .map(reviewDtoMapper::mapToReviewDto)
|
---|
42 | .toList();
|
---|
43 | }
|
---|
44 | }
|
---|