-
Notifications
You must be signed in to change notification settings - Fork 354
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
Conversation
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
There was a problem hiding this 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. |
There was a problem hiding this comment.
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]
.
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Outdated
Show resolved
Hide resolved
dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java
Outdated
Show resolved
Hide resolved
dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/DateUtils.java
Outdated
Show resolved
Hide resolved
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. |
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
...i/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParams.java
Outdated
Show resolved
Hide resolved
dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/EndDate.java
Outdated
Show resolved
Hide resolved
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Show resolved
Hide resolved
MockMvcBuilders.standaloneSetup(new BindingController()) | ||
.setControllerAdvice(new CrudControllerAdvice()) | ||
.build(); | ||
mockMvc = MockMvcBuilders.standaloneSetup(new BindingController()).build(); |
There was a problem hiding this comment.
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.
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/DatesBindingTest.java
Fixed
Show fixed
Hide fixed
There was a problem hiding this 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.
...main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapper.java
Outdated
Show resolved
Hide resolved
public class EndDateTime { | ||
private final Date date; | ||
|
||
public static EndDateTime valueOf(String date) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Quality Gate passedIssues Measures |
|
||
@NoArgsConstructor | ||
@Data | ||
private class Params { |
Check notice
Code scanning / CodeQL
Inner class could be static Note test
} | ||
|
||
@NoArgsConstructor | ||
@Data |
Check notice
Code scanning / CodeQL
Use of default toString() Note test
Default toString(): StartDateTime inherits toString() from Object, and so is not suitable for printing.
* 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
…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
We are adding 2 new web parameter types for date filters
StartDate
andEndDate
.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 inDateTime
type)EndDate
passed without a time, defaults to the end of the dayStartDate
andEndDate
are meant to be used only in the web layer.