Skip to content

Commit 420f75f

Browse files
committed
added rating removing endpoint
1 parent 1934bd2 commit 420f75f

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

TableBookingAPI/TableBooking.Logic/Interfaces/IRatingRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

TableBookingAPI/TableBooking.Logic/Repositories/GenericRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

TableBookingAPI/TableBooking.Logic/Repositories/RatingRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

TableBookingAPI/TableBooking/Controllers/RatingController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

TableBookingAPI/TableBooking/Services/RatingService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)