-
Notifications
You must be signed in to change notification settings - Fork 3
クエリパラメータで size / next / prev のいずれかを指定した場合 Chunkable インスタンスの direction を @ChunkableDefault の値に設定する
#51
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
Conversation
…n を `@ChunkableDefault` の値に設定する
897cb93 to
fbb47d9
Compare
| pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; | ||
|
|
||
| Direction direction = Direction.fromOptionalString(directionString).orElse(null); | ||
| Direction direction = Direction.fromOptionalString(directionString).orElse(defaultOrFallback.getDirection()); |
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.
directionString はクエリパラメータ direction の値。
defaultOrFallback は、@ChunkableDefault の設定値を初期値にした Chunkable インスタンス。
以前は クエリパラメータ direction が null もしくは Direction に含まない文字列を指定した時、null を返していた。
| assertThat(actualChunkable.getPaginationRelation(), is(PaginationRelation.PREV)); | ||
| assertThat(actualChunkable.getPaginationToken(), is("prev_token")); | ||
| assertThat(actualChunkable.getMaxPageSize(), is(12)); | ||
| assertThat(actualChunkable.getDirection(), is(Direction.DESC)); |
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.
DESC を指定したら DESC
| assertThat(actualChunkable.getPaginationRelation(), is(nullValue())); | ||
| assertThat(actualChunkable.getPaginationToken(), is(nullValue())); | ||
| assertThat(actualChunkable.getMaxPageSize(), is(12)); | ||
| assertThat(actualChunkable.getDirection(), is(Direction.ASC)); |
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.
ASC を指定したら ASC
| assertThat(actualChunkable.getPaginationRelation(), is(nullValue())); | ||
| assertThat(actualChunkable.getPaginationToken(), is(nullValue())); | ||
| assertThat(actualChunkable.getMaxPageSize(), is(12)); | ||
| assertThat(actualChunkable.getDirection(), is(Direction.DESC)); |
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.
クエリパラメータ未指定の時は @ChunkableDefault の初期値を使用する
(この動きは変えていない)
| assertThat(actualChunkable.getPaginationToken(), is("next_token")); | ||
| assertThat(actualChunkable.getMaxPageSize(), is(1234)); | ||
| // defaultHandlerWithInitValue に付与した ChunkableDefault の direction の初期値は DESC | ||
| assertThat(actualChunkable.getDirection(), is(Direction.DESC)); |
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.
size や next 指定時でも、direction 未指定時は ChunkableDefault の初期値を使用する
| assertThat(actualChunkable.getPaginationToken(), is(nullValue())); | ||
| assertThat(actualChunkable.getMaxPageSize(), is(123)); | ||
| assertThat(actualChunkable.getDirection(), is(nullValue())); | ||
| assertThat(actualChunkable.getDirection(), is(Direction.ASC)); // ChunkableDefault の direction の初期値は ASC |
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.
null を返していたが、@ChunkableDefault の初期値 ASC を返すようにした
inabajunmr
left a comment
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.
nitsのみ
| ModelAndViewContainer mavContainer = mock(ModelAndViewContainer.class); | ||
| NativeWebRequest webRequest = mock(NativeWebRequest.class); | ||
| // size と next 指定 | ||
| when(webRequest.getParameter(eq("direction"))).thenReturn(Direction.DESC.name()); |
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.
デフォルトDESCなのでここはASCのがテスト的によいきがしますがどうでしょ
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.
そういえば direction のデフォルトとリクエストが一緒だった時のテストがなかったなぁと思ったのであえての DESC にしたのでした。特に問題がなければこのままで。
(コメントは間違ってたので修正しました)
内容
See #50
@ChunkableDefault(size = 10, direction = Sort.Direction.DESC)を設定している時、なのに
なのはおかしいので修正。
spring-data-mirage の場合、direction が null の場合 ASC 扱いとしているので問題にはなっていないが、direction の初期値の扱いが明らかにおかしい。
(direction が未指定の場合に使用する値となるべき)
この対応で発生しうる不具合
ケース1
@ChunkableDefault(size = 10, direction = Sort.Direction.DESC)を指定した時にクエリパラメータで size / next / prev のいずれかを指定していると Chunkable インスタンスの direction は null
を期待している処理が存在する場合
↓
そんな期待するのは矛盾していると思われるし、現在の Pz で
@ChunkableDefaultの direction を指定しているのは1つだけだったので問題無しと判断。(braking-change ではない筈)
ケース2
@ChunkableDefaultを指定した時(初期値の変更無し)にクエリパラメータで size の指定をして、Chunkable インスタンスの direction に null
を期待している処理が存在する場合(対応後は ASC が設定されてしまうのでエラーになる)
↓
spring-data-mirage の場合、direction が null の場合 ASC 扱いとしているので問題ない筈。
クエリパラメータに ASC 指定された時に direction には ASC が指定されるので ASC での動作確認は行っているハズ。
むしろ既存の振る舞いを受け入れているのに ASC の対応をしていない方がおかしい。