Skip to content

Commit

Permalink
Add courses filter to endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
romandykyi committed Dec 16, 2023
1 parent 40bea11 commit d3d6a33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion EUniversity/Controllers/University/CoursesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public CoursesController(ICoursesService coursesService)
/// </summary>
/// <remarks>
/// If there is no items in the requested page, then empty page will be returned.
/// If the query param 'semesterId' is 0, then courses that are not linked to any semesters will be returned.
/// </remarks>
/// <param name="properties">Pagination properties.</param>
/// <param name="filterProperties">Pagination properties.</param>
/// <param name="name">An optional name to filter courses by.</param>
/// <param name="sortingMode">
/// An optional sorting mode.
Expand All @@ -57,10 +59,11 @@ public CoursesController(ICoursesService coursesService)
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> GetCoursesPageAsync(
[FromQuery] PaginationProperties properties,
[FromQuery] CoursesFilterProperties filterProperties,
[FromQuery] string? name,
[FromQuery] DefaultFilterSortingMode sortingMode = DefaultFilterSortingMode.Name)
{
DefaultFilter<Course> filter = new(name ?? string.Empty, sortingMode);
CoursesFilter filter = new(filterProperties, name ?? string.Empty, sortingMode);
return Ok(await _coursesService.GetPageAsync(properties, filter));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CoursesControllerTests :

public override int DefaultId => 1;

public override string GetPageFilter => "name=testfilter&sortingMode=name";
public override string GetPageFilter => "name=testfilter&semesterId=77";

public override void SetUpService()
{
Expand All @@ -32,9 +32,9 @@ public override void SetUpService()

protected override bool AssertThatFilterWasApplied(IFilter<Course> filter)
{
return filter is DefaultFilter<Course> defaultFilter &&
defaultFilter.Name == "testfilter" &&
defaultFilter.SortingMode == DefaultFilterSortingMode.Name;
return filter is CoursesFilter coursesFilter &&
coursesFilter.Name == "testfilter" &&
coursesFilter.Properties.SemesterId == 77;
}

protected override CourseCreateDto GetInvalidCreateDto()
Expand Down

0 comments on commit d3d6a33

Please sign in to comment.