Skip to content

Commit

Permalink
Merge pull request #471 from DigitalExcellence/feature/470-sort-proje…
Browse files Browse the repository at this point in the history
…cts-onlikes

Added like sorting
  • Loading branch information
RubenFricke authored Jun 28, 2021
2 parents 0de84dd + 9d1ae35 commit 8be1144
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ public async Task<IActionResult> GetAllProjects(
if(projectFilterParamsResource.SortBy != null &&
projectFilterParamsResource.SortBy != "name" &&
projectFilterParamsResource.SortBy != "created" &&
projectFilterParamsResource.SortBy != "updated")
projectFilterParamsResource.SortBy != "updated" &&
projectFilterParamsResource.SortBy != "likes")
{
problem.Detail = "Invalid sort value: Use \"name\", \"created\" or \"updated\".";
problem.Detail = "Invalid sort value: Use \"name\", \"created\", \"updated\" or \"likes\".";
problem.Instance = "5CE2F569-C0D5-4179-9299-62916270A058";
return BadRequest(problem);
}
Expand Down
2 changes: 1 addition & 1 deletion API/Resources/ProjectFilterParamsResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ProjectFilterParamsResource

/// <summary>
/// Get or Set the sort by query parameter
/// Possible sorts are: name, created, updated
/// Possible sorts are: name, created, updated, likes
/// </summary>
[FromQuery(Name = "sortBy")]
public string SortBy { get; set; }
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added fontys gitlab to the wizard, and the functionality to get private projects - [#377](https://github.com/DigitalExcellence/dex-backend/issues/377)
- Performance testing using K6 - [#379](https://github.com/DigitalExcellence/dex-backend/issues/379)
- Project sorting by likes - [#470](https://github.com/DigitalExcellence/dex-backend/issues/470)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Models/ProjectFilterParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ProjectFilterParams

/// <summary>
/// By which property the results should be sorted
/// Possible values are: name, created, updated
/// Possible values are: name, created, updated, likes
/// </summary>
public string SortBy { get; set; }

Expand Down
3 changes: 3 additions & 0 deletions Services/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public Task<List<Project>> GetAllWithUsersCollaboratorsAndInstitutionsAsync(Proj
case "created":
orderBy = project => project.Created;
break;
case "likes":
orderBy = project => project.Likes.Count;
break;
default:
orderBy = project => project.Updated;
break;
Expand Down

0 comments on commit 8be1144

Please sign in to comment.