Changeset 63f5ced for resTools_backend/backend
- Timestamp:
- 08/24/22 17:11:52 (2 years ago)
- Branches:
- master
- Children:
- d86edb7
- Parents:
- a569b7c
- Location:
- resTools_backend/backend
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
resTools_backend/backend/Controllers/ReviewsController.cs
ra569b7c r63f5ced 18 18 } 19 19 20 [HttpGet] 21 public async Task<List<ReviewResponse>> GetReviews(int page, int pageSize) 22 { 23 return await _reviewService.GetReviews(page, pageSize); 24 } 25 26 [HttpGet("count")] 27 public async Task<int> GetReviewsCount() 28 { 29 return await _reviewService.GetCount(); 30 } 20 31 21 32 [Authorize] -
resTools_backend/backend/Services/RestaurantService.cs
ra569b7c r63f5ced 47 47 Price = x.Price 48 48 }).ToList(), 49 Reviews = x.Reviews. OrderByDescending(x => x.CreatedAt).Select(x => new ReviewResponse()49 Reviews = x.Reviews.Select(x => new ReviewResponse() 50 50 { 51 CreatedAt = x.CreatedAt, 52 Description = x.Description, 51 53 Id = x.Id, 54 Stars = x.Stars, 52 55 Title = x.Title, 53 Description = x.Description,54 Stars = x.Stars,55 CreatedAt = x.CreatedAt,56 56 Username = x.User == null ? "Anonymous" : x.User.Email 57 57 }).ToList(), -
resTools_backend/backend/Services/ReviewService.cs
ra569b7c r63f5ced 9 9 { 10 10 public Task AddReview(CreateReviewRequest review, int userId); 11 public Task<List<ReviewResponse>> GetReviews(int page, int pageSize); 12 public Task<int> GetCount(); 11 13 } 12 14 public class ReviewService : IReviewService … … 38 40 await _context.SaveChangesAsync(); 39 41 } 42 43 public async Task<int> GetCount() 44 { 45 return await _context.Reviews.CountAsync(); 46 } 47 48 public async Task<List<ReviewResponse>> GetReviews(int page, int pageSize) 49 { 50 return await _context.Reviews 51 .Include(x => x.User) 52 .OrderByDescending(x => x.CreatedAt) 53 .Skip(page * pageSize) 54 .Take(pageSize) 55 .Select(x => new ReviewResponse() 56 { 57 CreatedAt = x.CreatedAt, 58 Description = x.Description, 59 Id = x.Id, 60 Stars = x.Stars, 61 Title = x.Title, 62 Username = x.User == null ? "Anonymous" : x.User.Email 63 }) 64 .ToListAsync(); 65 } 40 66 } 41 67 }
Note:
See TracChangeset
for help on using the changeset viewer.