Changeset 63f5ced
- Timestamp:
- 08/24/22 17:11:52 (2 years ago)
- Branches:
- master
- Children:
- d86edb7
- Parents:
- a569b7c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/Dashboard/Review.js
ra569b7c r63f5ced 1 1 import React, {useEffect, useState} from 'react' 2 import {Button, Card, Input, List, notification, Rate, Spin, Tooltip} from "antd";2 import {Button, Card, Input, List, notification, Pagination, Rate, Spin, Tooltip} from "antd"; 3 3 import axios from "axios"; 4 4 import env from "../env"; … … 6 6 7 7 const Review = props => { 8 const [restaurant, setRestaurant] = useState({}); 8 const [reviews, setReviews] = useState([]); 9 const [restaurant, setRestaurant] = useState({}) 9 10 const [loading, setLoading] = useState(true); 11 const [reviewSize, setReviewSize] = useState(0) 12 10 13 11 14 useEffect(()=> { … … 18 21 },[props.refresh]) 19 22 20 const getRestaurant = () => { 23 24 const getRestaurant = (pg = 1, size = 5) => { 25 axios.get(env.api + 'Reviews/count',).then(res=>{ 26 setReviewSize(res.data); 27 }); 21 28 axios.get(env.api + 'Restaurants').then(res=>{ 22 29 setRestaurant(res.data); 23 setLoading(false); 30 console.log(pg, size) 31 axios.get(env.api + 'Reviews',{params:{page:pg-1, pageSize: size}}).then(res=>{ 32 setReviews(res.data); 33 setLoading(false); 34 }); 24 35 }); 25 36 } … … 45 56 <div> 46 57 <div style={{backgroundColor: 'white',padding:'10px', border:'1px solid lightgray', borderTop: 'none'}}> 47 <h3>Средна оценка: <Rate disabled allowHalf value={restaurant.averageReview}/> од вкупно {re staurant.reviews.length} оценки</h3>58 <h3>Средна оценка: <Rate disabled allowHalf value={restaurant.averageReview}/> од вкупно {reviewSize} оценки</h3> 48 59 </div> 49 <List dataSource={re staurant.reviews} itemLayout={'horizontal'} locale={{emptyText:'Нема оставени оценки за овој ресторан'}}60 <List dataSource={reviews} itemLayout={'horizontal'} locale={{emptyText:'Нема оставени оценки за овој ресторан'}} 50 61 renderItem={item => ( 51 62 <Card title={item.title} style={{width:'98%',backgroundColor:'white',margin:'1%'}}> … … 55 66 </Card> 56 67 )}/> 68 <div style={{paddingBottom:'20px', textAlign:'center'}}> 69 <Pagination defaultPageSize={5} total={reviewSize} onChange={(pg,size)=>getRestaurant(pg,size)} showSizeChanger pageSizeOptions={[5,10,20,50]}/> 70 </div> 57 71 </div> 58 59 72 } 60 73 </div> -
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.