File tree Expand file tree Collapse file tree 5 files changed +25
-4
lines changed Expand file tree Collapse file tree 5 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ namespace TableBooking.Logic.Interfaces
55 public interface IRatingRepository : IGenericRepository < Rating >
66 {
77 Task < IEnumerable < Rating > > GetRatingsAsync ( Guid restaurantId ) ;
8+ Task < Rating > GetRating ( Guid id ) ;
89 }
910}
Original file line number Diff line number Diff line change @@ -31,13 +31,13 @@ public async Task InsertAsync(T entity)
3131
3232 public async Task Delete ( object id )
3333 {
34- T entityToDelete = await _objectSet . FindAsync ( id ) ;
35- Delete ( entityToDelete ) ;
34+ T objectToDelete = await _objectSet . FindAsync ( id ) ;
35+ _objectSet . Remove ( objectToDelete ) ;
3636 }
3737
3838 public async virtual Task Update ( T entity )
3939 {
40- Update ( entity ) ;
40+ await Update ( entity ) ;
4141 }
4242
4343 }
Original file line number Diff line number Diff line change @@ -17,5 +17,13 @@ public async Task<IEnumerable<Rating>> GetRatingsAsync(Guid restaurantId)
1717 . Include ( x => x . AppUser )
1818 . Where ( x => x . RestaurantId . Equals ( restaurantId ) ) . ToListAsync ( ) ;
1919 }
20+
21+ public async Task < Rating > GetRating ( Guid id )
22+ {
23+ return await _objectSet
24+ . Include ( x => x . Restaurant )
25+ . Include ( x => x . AppUser )
26+ . FirstAsync ( x => x . Id == id ) ;
27+ }
2028 }
2129}
Original file line number Diff line number Diff line change @@ -34,5 +34,11 @@ public async Task<IActionResult> CreateRating([FromBody] CreateRatingDto createR
3434 {
3535 return await _ratingService . CreateRatingAsync ( createRatingDto ) ;
3636 }
37+
38+ [ HttpDelete ( "DeleteRating/{id}" ) ]
39+ public async Task < IActionResult > DeleteRating ( Guid id )
40+ {
41+ return await _ratingService . DeleteRatingAsync ( id ) ;
42+ }
3743 }
3844}
Original file line number Diff line number Diff line change @@ -39,7 +39,13 @@ public async Task<IActionResult> CreateRatingAsync(CreateRatingDto dto)
3939
4040 public async Task < IActionResult > DeleteRatingAsync ( Guid ratingId )
4141 {
42- throw new NotImplementedException ( ) ;
42+ var ratingToDelete = await _unitOfWork . RatingRepository . GetRating ( ratingId ) ;
43+ if ( ratingToDelete == null )
44+ return new NotFoundObjectResult ( $ "Rating with Id = { ratingId } not found") ;
45+ var deletedRating = _ratingConverter . RatingToRatingDto ( ratingToDelete ) ;
46+ await _unitOfWork . RatingRepository . Delete ( ratingId ) ;
47+ await _unitOfWork . SaveChangesAsync ( ) ;
48+ return new OkObjectResult ( deletedRating ) ;
4349 }
4450
4551 public async Task < IActionResult > GetAllRatingsAsync ( Guid restaurantId )
You can’t perform that action at this time.
0 commit comments