Skip to content

Commit 5643e8e

Browse files
authored
AllowedToReview was added to application controller (#759)
* AllowedToReview was added to application controller * Fix
1 parent f0943bc commit 5643e8e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

OutOfSchool/OutOfSchool.WebApi/Controllers/V1/ApplicationController.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,24 @@ public async Task<IActionResult> AllowedNewApplicationByChildStatus(Guid worksho
348348
.ConfigureAwait(false));
349349
}
350350

351+
/// <summary>
352+
/// Check if exists an any application with approve status in workshop for parent.
353+
/// </summary>
354+
/// <param name="parentId">Parent's key.</param>
355+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
356+
/// <response code="200">Entity was updated and returned.</response>
357+
/// <response code="401">If the user is not authorized.</response>
358+
/// <response code="500">If any server error occures.</response>
359+
[HasPermission(Permissions.ApplicationAddNew)]
360+
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
361+
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
362+
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
363+
[HttpGet]
364+
public async Task<IActionResult> AllowedToReview(Guid parentId)
365+
{
366+
return Ok(await applicationService.AllowedToReview(parentId).ConfigureAwait(false));
367+
}
368+
351369
private async Task<SearchResult<ApplicationDto>> GetByWorkshopId(Guid id, ApplicationFilter filter)
352370
{
353371
var workshop = await workshopService.GetById(id).ConfigureAwait(false);

OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ public async Task<bool> AllowedNewApplicationByChildStatus(Guid workshopId, Guid
501501
return !await applicationRepository.Any(filter).ConfigureAwait(false);
502502
}
503503

504+
public async Task<bool> AllowedToReview(Guid parentId)
505+
{
506+
var statuses = new[]
507+
{
508+
ApplicationStatus.Completed,
509+
ApplicationStatus.Approved,
510+
ApplicationStatus.StudyingForYears,
511+
};
512+
513+
Expression<Func<Application, bool>> filter = a => a.ParentId == parentId
514+
&& statuses.Contains(a.Status);
515+
516+
return await applicationRepository.Any(filter).ConfigureAwait(false);
517+
}
518+
504519
private async Task<bool> IsNewApplicationAllowed(Guid workshopId)
505520
{
506521
var workshop = await workshopRepository.GetById(workshopId).ConfigureAwait(false);

OutOfSchool/OutOfSchool.WebApi/Services/IApplicationService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,13 @@ public interface IApplicationService
110110
/// The task result contains <see langword="true" /> if allowed to create a new application by the child status;
111111
/// otherwise, <see langword="false" />.</returns>
112112
Task<bool> AllowedNewApplicationByChildStatus(Guid workshopId, Guid childId);
113+
114+
/// <summary>
115+
/// Check if exists an any application with approve status in workshop for parent.
116+
/// </summary>
117+
/// <param name="parentId">Parent's key.</param>
118+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.
119+
/// The task result contains <see langword="true" /> if exists an any application with approve status in workshop for parent;
120+
/// otherwise, <see langword="false" />.</returns>
121+
Task<bool> AllowedToReview(Guid parentId);
113122
}

0 commit comments

Comments
 (0)