Skip to content

Commit

Permalink
New Custom exceptions, InvalidRatingException
Browse files Browse the repository at this point in the history
  • Loading branch information
Novr_wz05 authored and Novr_wz05 committed May 15, 2024
1 parent 14a55f0 commit 55f2a36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Core/Application/Exceptions/InvalidRatingException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Application.Exceptions;

public class InvalidRatingException : Exception
{
public InvalidRatingException(string? message) : base(message)
{
}

public InvalidRatingException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
8 changes: 7 additions & 1 deletion Infrastructure/Infrastructure/Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Models.Requests;
using Application.Exceptions;
using Application.Models.Requests;
using Application.Models.Responses;
using Application.Repositories;
using Application.Services;
Expand Down Expand Up @@ -72,6 +73,11 @@ public Task<bool> RateCourse()

public async Task<bool> RateCourseAsync(RateCourseRequest request)
{
if (request.Rate > 5 || request.Rate < 1)
{
throw new InvalidRatingException("The rating value must be between 1 and 5. Please provide a valid rating.");
}

var course = await _unitOfWork.ReadCourseRepository.GetAsync(request.CourseId);

if (course is null)
Expand Down

0 comments on commit 55f2a36

Please sign in to comment.