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

feat: Create StartDate and EndDate types [DHIS2-16019] #17454

Merged
merged 16 commits into from
May 22, 2024

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented May 16, 2024

We are adding 2 new web parameter types for date filters StartDate and EndDate.
In a lot of APIs we have filters to get entities before and after something and most of them are of type DateTime.

Everything works correctly if the client specifies the time together with the date but if only the date is passed then the before filter default to the beginning of the day filtering out all the entities with the date in that day.

Now

  • StartDate passed without a time, defaults to the beginning of the day (some behavior already present in DateTime type)
  • EndDate passed without a time, defaults to the end of the day

StartDate and EndDate are meant to be used only in the web layer.

@enricocolasante enricocolasante marked this pull request as ready for review May 16, 2024 14:37
@enricocolasante enricocolasante requested a review from a team May 16, 2024 14:37
Copy link
Contributor

@teleivo teleivo left a comment

Choose a reason for hiding this comment

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

StartDate and EndDate are meant to be used only in the web layer.

So these are used to convert the HTTP query parameters into a Date which is what we use in the service/repo layer?

I think it would make sense to already use these types in some controller in this PR.

*
* <p>This behavior, combined with {@link EndDate}, allows to correctly implement an interval search
* including start and end dates. startDate=2020-10-10&endDate=2020-10-12 will include anything
* between 2020-10-10T00:00:00.000 and 2020-10-12T23:59:59.999.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we leave

startDate=2020-10-10&endDate=2020-10-12 will include anything between 2020-10-10T00:00:00.000 and 2020-10-12T23:59:59.999.

from these docs here as this is at the discretion of the endpoint itself?

Or do we "standardize" on this behavior, in that case it makes sense to keep it here. I am not sure its 100% clear right now with include anything between that the endpoints are included as well. So maybe we could change the wording or add (represent a closed interval [startDate, endDate].

@enricocolasante
Copy link
Contributor Author

StartDate and EndDate are meant to be used only in the web layer.

So these are used to convert the HTTP query parameters into a Date which is what we use in the service/repo layer?

I think it would make sense to already use these types in some controller in this PR.

I was trying to separate the creation of the parameter types and their application, but I agree that it makes sense to have at least one example.
I am not sure what is the best way to test them though

@enricocolasante enricocolasante requested a review from muilpp May 20, 2024 12:11
MockMvcBuilders.standaloneSetup(new BindingController())
.setControllerAdvice(new CrudControllerAdvice())
.build();
mockMvc = MockMvcBuilders.standaloneSetup(new BindingController()).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

There is enum related code in the CrudControllerAdvice. Not sure what it does but I wonder if CrudControllerAdvice should stay in here or the code in CrudControllerAdvice relating enums should be removed if it has no influence. Either way maybe do this in a separate PR.

@enricocolasante enricocolasante requested a review from teleivo May 21, 2024 14:22
Copy link
Contributor

@jbee jbee left a comment

Choose a reason for hiding this comment

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

Happy to see this being introduced. As far as I could see from a glance this should work nicely. Some suggestions on API details.

public class EndDateTime {
private final Date date;

public static EndDateTime valueOf(String date) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Javadoc on the list of valid patterns for date would be nice. Is this YYYYmmdd only?

public class StartDateTime {
private final Date date;

public static StartDateTime valueOf(String date) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a strong opinion but in newer Java APIs this is usually just called of, e.g. List.of, LocalDate.of

Copy link
Contributor

Choose a reason for hiding this comment

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

of should work as well with Springs conversion system as it looks for either a constructor or a factory called of, valueOf or from.

(see #16673)

@NoArgsConstructor
@Data
private class Params {
private StartDateTime after;
Copy link
Contributor

Choose a reason for hiding this comment

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

start and end would probably make it easier to read the test as one does not need to translate what before refers to.

Copy link

sonarcloud bot commented May 22, 2024


@NoArgsConstructor
@Data
private class Params {

Check notice

Code scanning / CodeQL

Inner class could be static Note test

Params should be made static, since the enclosing instance is not used.
}

@NoArgsConstructor
@Data

Check notice

Code scanning / CodeQL

Use of default toString() Note test

Default toString(): EndDateTime inherits toString() from Object, and so is not suitable for printing.
Default toString(): StartDateTime inherits toString() from Object, and so is not suitable for printing.
@enricocolasante enricocolasante merged commit 971003f into master May 22, 2024
15 checks passed
@enricocolasante enricocolasante deleted the DHIS2-16019 branch May 22, 2024 11:54
enricocolasante added a commit that referenced this pull request May 30, 2024
* feat: Create StartDate and EndDate types [DHIS2-16019]

* Fix docs

* Fix tests

* Fix tests

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* fix: Remove unused tracker services from program-rule module

* Fix review comments

* Fix review comments

* Fix review comments
enricocolasante added a commit that referenced this pull request May 30, 2024
…9] (2.41) (#17646)

* feat: Create StartDate and EndDate types [DHIS2-16019] (#17454)

* feat: Create StartDate and EndDate types [DHIS2-16019]

* Fix docs

* Fix tests

* Fix tests

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* Fix review comments

* fix: Remove unused tracker services from program-rule module

* Fix review comments

* Fix review comments

* Fix review comments

* fix: Use new start and end date types in tracker exporter [DHIS2-16019] (#17522)

* fix: Use new start and end date types in tracker exporter [DHIS2-16019]

* Fix review comments

* Fix review comments

* docs: Update OpenAPI for tracker exporter endpoints [DHIS2-16019] (#17569)

* docs: Update OpenAPI for tracker exporter endpoints [DHIS2-16019]

* Fix review comments

* Use last OpenApi changes
enricocolasante added a commit that referenced this pull request May 30, 2024
…9] (2.40) (#17648)

* feat: Create StartDate and EndDate types [DHIS2-16019] (#17454)

* fix: Use new start and end date types in tracker exporter [DHIS2-16019] (#17522)

* Fix tests
enricocolasante added a commit that referenced this pull request May 31, 2024
…9] (2.39) (#17650)

* feat: Create StartDate and EndDate types [DHIS2-16019] (#17454)

* fix: Use new start and end date types in tracker exporter [DHIS2-16019] (#17522)

* Fix test
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.

4 participants