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

EES-5593 Public API wildcard data set versioning #5577

Merged

Conversation

mmoalin
Copy link
Collaborator

@mmoalin mmoalin commented Jan 31, 2025

This PR (originally #5559) adds datasets wildcard versioning support to the following API endpoints:

[get]
data-sets/{dataSetId}/meta
data-sets/{dataSetId}/query
data-sets/{dataSetId}/csv
data-sets/{dataSetId}/versions/{dataSetVersion}
data-sets/{dataSetId}/versions/{dataSetVersion}/changes

[post]
data-sets/{dataSetId}/query

For example:

  • dataSetVersion=2.* should return the latest minor version in the v2 series
  • dataSetVersion=2.1 should return v2.1
  • dataSetVersion=2.0 should return v2.0
  • dataSetVersion=2 should return v2.0

Huge thanks to @leeoades for your support on this.


namespace GovUk.Education.ExploreEducationStatistics.Common.Utils;

public record DataSetVersionRecord(int? Major, int? Minor, int? Patch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSetVersionNumber would probably be a better name for this?

Suffixing names with 'record' is also a bit funky and would absolutely avoid naming things like this unless there were no better options.

The test class would need to be updated as well

return successful;
}

static bool TryParseWildCard(string versionString, [NotNullWhen(true)] ref DataSetVersionRecord? version)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should be private?
  • Typo - 'Wildcard' not 'WildCard'

Copy link
Collaborator Author

@mmoalin mmoalin Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and apologies, you left the typo comment before but it's crept in again with my refactor

public static bool TryParse(string versionString, out DataSetVersionRecord? version)
{
version = null;
if (versionString.Contains("*"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use '*' char here to save allocating a string

Comment on lines 14 to 15
if (versionString.Contains("*"))
return TryParseWildCard(versionString, ref version);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda nitpicky, but we're going against the grain for most of the project's code style by not having if statements with braces.

The main issue is that it highlights as warnings in Rider (green squiggles):

image

In general, we consider most of the default formatting in Rider as the project's style. If you're not against using different tooling, there'll be fewer issues if you switch to Rider instead of VS.

Regardless of tooling, to avoid potentially causing friction later on with people updating the code to match the expected style, would suggest adding in the line breaks.

Same with the successful case below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to incorporate this with my IDE

Comment on lines 47 to 48
if (parts.Length > 3)
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to earlier comment - could add braces.

Same below as well for next conditional

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

public static async Task<Either<ActionResult, DataSetVersion>> FindByVersion(
this IQueryable<DataSetVersion> queryable,
Guid dataSetId,
string version,
CancellationToken cancellationToken = default)
{
if (!VersionUtils.TryParse(version, out var semVersion))
{
if (!DataSetVersionRecord.TryParse(version, out var parsedVersion))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to other comments - would suggest keeping conditional braces in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nick. I'll make it a habit of doing this (+ see if my IDE can help me).

@mmoalin mmoalin merged commit 6cf93df into dev Feb 4, 2025
10 checks passed
@mmoalin mmoalin deleted the EES-5593-Allow-wildcard-data-set-versions-in-public-API branch February 4, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants