Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reordering already ordered missions #1038

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/api/Controllers/MissionDefinitionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public MissionDefinitionController(ILogger<MissionDefinitionController> logger,
/// </remarks>
[HttpGet("")]
[Authorize(Roles = Role.Any)]
[ProducesResponseType(typeof(IList<MissionDefinitionResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(IList<CondensedMissionDefinitionResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionDefinitionResponse>>> GetMissionDefinitions(
public async Task<ActionResult<IList<CondensedMissionDefinitionResponse>>> GetMissionDefinitions(
[FromQuery] MissionDefinitionQueryStringParameters parameters
)
{
Expand Down Expand Up @@ -66,7 +66,7 @@ [FromQuery] MissionDefinitionQueryStringParameters parameters
JsonSerializer.Serialize(metadata)
);

var missionDefinitionResponses = missionDefinitions.Select(m => new MissionDefinitionResponse(_missionDefinitionService, m));
var missionDefinitionResponses = missionDefinitions.Select(m => new CondensedMissionDefinitionResponse(m));
return Ok(missionDefinitionResponses);
}

Expand Down
6 changes: 5 additions & 1 deletion backend/api/Utilities/PagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ int pageSize
// Adding order by constant value 1, which does not change order of rows
// but stops the runtime warning
int totalCount = await source.CountAsync();
var items = await source.OrderBy(x => 1).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync();
List<T> items;
if (source.Expression.Type is IOrderedQueryable)
items = await source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync();
else
items = await source.OrderBy(x => 1).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync();
return new PagedList<T>(items, pageNumber, pageSize, totalCount);
}
}
Expand Down