source: src/main/java/edu/gjoko/schedlr/controllers/rest/ReviewApi.java

Last change on this file was 77205be, checked in by gjoko kostadinov <gjokokostadinov@…>, 11 months ago

Add entire code

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package edu.gjoko.schedlr.controllers.rest;
2
3import edu.gjoko.schedlr.dto.ReviewDto;
4import edu.gjoko.schedlr.entity.Review;
5import edu.gjoko.schedlr.entity.Stakeholder;
6import edu.gjoko.schedlr.mappers.ReviewDtoMapper;
7import edu.gjoko.schedlr.services.ReviewService;
8import lombok.AllArgsConstructor;
9import org.springframework.web.bind.annotation.*;
10
11import javax.servlet.http.HttpServletRequest;
12import java.util.List;
13
14@RestController
15@RequestMapping("api/review")
16@AllArgsConstructor
17public 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}
Note: See TracBrowser for help on using the repository browser.