source: resTools_backend/backend/Controllers/ReviewsController.cs

Last change on this file was 13f1472, checked in by Danilo <danilo.najkov@…>, 2 years ago

vip functionallity + menu fields + alergens filtering + google/fb login + email queueing

  • Property mode set to 100644
File size: 1.6 KB
Line 
1using backend.DTOs;
2using backend.Helpers;
3using backend.Services;
4using Microsoft.AspNetCore.Http;
5using Microsoft.AspNetCore.Mvc;
6
7namespace backend.Controllers
8{
9 [ApiController]
10 [Route("[controller]")]
11 public class ReviewsController : ControllerBase
12 {
13 private readonly IReviewService _reviewService = null;
14 private readonly IUserService _userService = null;
15
16 public ReviewsController(IReviewService reviewService, IUserService userService)
17 {
18 _reviewService = reviewService;
19 _userService = userService;
20 }
21
22 [HttpGet]
23 public async Task<List<ReviewResponse>> GetReviews(int page, int pageSize)
24 {
25 return await _reviewService.GetReviews(page, pageSize);
26 }
27
28 [HttpGet("count")]
29 public async Task<int> GetReviewsCount()
30 {
31 return await _reviewService.GetCount();
32 }
33
34 [Authorize]
35 [HttpPost()]
36 public async Task<IActionResult> CreateReview([FromBody] CreateReviewRequest req)
37 {
38 int userId = 0;
39 try
40 {
41 userId = (int)this.HttpContext.Items["User"];
42 }
43 catch (Exception ex) {
44 var user = await _userService.GetByEmail((string)this.HttpContext.Items["User"]);
45 if (user == null)
46 {
47 return null;
48 }
49 userId = user.Id;
50 }
51 await _reviewService.AddReview(req, userId);
52 return Ok();
53 }
54
55 }
56
57}
Note: See TracBrowser for help on using the repository browser.