Skip to content

Commit

Permalink
Can't send an application while a service provider is blocked (#1002)
Browse files Browse the repository at this point in the history
* Can't send an application while a service provider is blocked

* Refactoring

---------

Co-authored-by: Valerii <[email protected]>
  • Loading branch information
valerabad and Valerii authored Feb 27, 2023
1 parent 0bb9772 commit 4a9ff64
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
40 changes: 30 additions & 10 deletions OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class ApplicationService : IApplicationService, INotificationReciever
private readonly IRegionAdminService regionAdminService;
private readonly ICodeficatorService codeficatorService;

private readonly string errorNullWorkshopMessage = "Operation failed. Workshop in Application dto is null";
private readonly string errorBlockedWorkshopMessage = "Unable to create a new application for a workshop because workshop is blocked";
private readonly string errorClosedWorkshopMessage = "Unable to create a new application for a workshop because workshop status is closed";
private readonly string errorNoAllowedNewApplicationMessage = "Unable to create a new application for a child because there's already appropriate status were found in this workshop";

/// <summary>
/// Initializes a new instance of the <see cref="ApplicationService"/> class.
/// </summary>
Expand Down Expand Up @@ -594,7 +599,20 @@ private async Task<bool> IsNewApplicationAllowed(Guid workshopId)
return workshop.Status == WorkshopStatus.Open;
}

logger.LogInformation("Operation failed. Workshop in Application dto is null");
logger.LogError(this.errorNullWorkshopMessage);
throw new ArgumentException(@"Workshop in Application dto is null.", nameof(workshopId));
}

private async Task<bool> IsBlokedWorkshop(Guid workshopId)
{
var workshop = await combinedWorkshopService.GetById(workshopId).ConfigureAwait(false);

if (workshop is not null)
{
return workshop.IsBlocked;
}

logger.LogError(this.errorNullWorkshopMessage);
throw new ArgumentException(@"Workshop in Application dto is null.", nameof(workshopId));
}

Expand Down Expand Up @@ -650,7 +668,7 @@ private void FillProviderAdminInfo(string userId, out Guid providerId, out bool

if (providerAdmin == null)
{
logger.LogInformation("ProviderAdmin with userId = {UserId} not exists", userId);
logger.LogError("ProviderAdmin with userId = {UserId} not exists", userId);

throw new ArgumentException($"There is no providerAdmin with userId = {userId}");
}
Expand Down Expand Up @@ -721,14 +739,18 @@ private async Task<ModelWithAdditionalData<ApplicationDto, int>> ExecuteCreateAs
{
await currentUserService.UserHasRights(new ParentRights(applicationDto.ParentId, applicationDto.ChildId));

if (await IsBlokedWorkshop(applicationDto.WorkshopId))
{
logger.LogError(this.errorBlockedWorkshopMessage);
throw new ArgumentException(this.errorBlockedWorkshopMessage);
}

var isNewApplicationAllowed = await IsNewApplicationAllowed(applicationDto.WorkshopId).ConfigureAwait(false);

if (!isNewApplicationAllowed)
{
logger.LogInformation(
"Unable to create a new application for a workshop because workshop status is closed");
throw new ArgumentException(
"Unable to create a new application for a workshop because workshop status is closed.");
logger.LogError(this.errorClosedWorkshopMessage);
throw new ArgumentException(this.errorClosedWorkshopMessage);
}

var allowedNewApplicationForChild =
Expand All @@ -737,10 +759,8 @@ await AllowedNewApplicationByChildStatus(applicationDto.WorkshopId, applicationD

if (!allowedNewApplicationForChild)
{
logger.LogInformation(
"Unable to create a new application for a child because there's already appropriate status were found in this workshop");
throw new ArgumentException(
"Unable to create a new application for a child because there's already appropriate status were found in this workshop.");
logger.LogError(this.errorNoAllowedNewApplicationMessage);
throw new ArgumentException(this.errorNoAllowedNewApplicationMessage);
}

(bool IsCorrect, int SecondsRetryAfter) resultOfCheck =
Expand Down
5 changes: 5 additions & 0 deletions OutOfSchool/OutOfSchool.WebApi/Services/StatisticService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public async Task<IEnumerable<WorkshopCard>> GetPopularWorkshopsFromDatabase(int
.Where(w => w.InstitutionHierarchy.InstitutionId == regionAdmin.InstitutionId);
}

if (!currentUserService.IsAdmin())
{
workshops = workshops.Where(w => !w.IsBlocked);
}

if (catottgId > 0)
{
workshops = workshops
Expand Down

0 comments on commit 4a9ff64

Please sign in to comment.