2021-03-19 14:23:37 +07:00
|
|
|
package io.spring.application;
|
|
|
|
|
|
|
|
import io.spring.application.CursorPager.Direction;
|
|
|
|
import lombok.Data;
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
|
|
@Data
|
|
|
|
@NoArgsConstructor
|
2021-03-23 14:54:04 +07:00
|
|
|
public class CursorPageParameter<T> {
|
2021-03-19 14:23:37 +07:00
|
|
|
private static final int MAX_LIMIT = 1000;
|
|
|
|
private int limit = 20;
|
2021-03-23 14:54:04 +07:00
|
|
|
private T cursor;
|
2021-03-19 14:23:37 +07:00
|
|
|
private Direction direction;
|
|
|
|
|
2021-03-23 14:54:04 +07:00
|
|
|
public CursorPageParameter(T cursor, int limit, Direction direction) {
|
2021-03-19 14:23:37 +07:00
|
|
|
setLimit(limit);
|
|
|
|
setCursor(cursor);
|
|
|
|
setDirection(direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNext() {
|
|
|
|
return direction == Direction.NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getQueryLimit() {
|
|
|
|
return limit + 1;
|
|
|
|
}
|
|
|
|
|
2021-03-23 14:54:04 +07:00
|
|
|
private void setCursor(T cursor) {
|
|
|
|
this.cursor = cursor;
|
2021-03-19 14:23:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setLimit(int limit) {
|
|
|
|
if (limit > MAX_LIMIT) {
|
|
|
|
this.limit = MAX_LIMIT;
|
|
|
|
} else if (limit > 0) {
|
|
|
|
this.limit = limit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|