move query param name to method

This commit is contained in:
Jake Potrebic 2021-03-25 12:36:54 -07:00
parent af775ee613
commit 1e97e576ca
No known key found for this signature in database
GPG Key ID: 7C58557EC9C421F8
4 changed files with 15 additions and 7 deletions

View File

@ -4,9 +4,11 @@ import io.papermc.hangar.controller.extras.pagination.Filter.FilterInstance;
import org.jdbi.v3.core.statement.SqlStatement; import org.jdbi.v3.core.statement.SqlStatement;
import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.NativeWebRequest;
public interface Filter<F extends FilterInstance> { public interface Filter<F extends FilterInstance> extends QueryIdentified {
boolean supports(NativeWebRequest webRequest); default boolean supports(NativeWebRequest webRequest) {
return webRequest.getParameterMap().containsKey(getQueryParamName());
}
F create(NativeWebRequest webRequest); F create(NativeWebRequest webRequest);

View File

@ -10,13 +10,13 @@ public class ProjectCategoryFilter implements Filter<ProjectCategoryFilterInstan
private static final String QUERY_PARAM = "projectCategory"; private static final String QUERY_PARAM = "projectCategory";
@Override @Override
public boolean supports(NativeWebRequest webRequest) { public ProjectCategoryFilterInstance create(NativeWebRequest webRequest) {
return webRequest.getParameterMap().containsKey(QUERY_PARAM); return new ProjectCategoryFilterInstance(webRequest);
} }
@Override @Override
public ProjectCategoryFilterInstance create(NativeWebRequest webRequest) { public String getQueryParamName() {
return new ProjectCategoryFilterInstance(webRequest); return QUERY_PARAM;
} }
static class ProjectCategoryFilterInstance implements FilterInstance { static class ProjectCategoryFilterInstance implements FilterInstance {

View File

@ -0,0 +1,6 @@
package io.papermc.hangar.controller.extras.pagination;
public interface QueryIdentified {
String getQueryParamName();
}

View File

@ -1,6 +1,6 @@
package io.papermc.hangar.controller.extras.pagination; package io.papermc.hangar.controller.extras.pagination;
public interface SortBy { public interface SortBy extends QueryIdentified {
void createSql(StringBuilder sb); void createSql(StringBuilder sb);
} }