-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show projects you are a member of on profile
Closes #1380
- Loading branch information
Showing
6 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../io/papermc/hangar/controller/extras/pagination/filters/projects/ProjectMemberFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.papermc.hangar.controller.extras.pagination.filters.projects; | ||
|
||
import io.papermc.hangar.controller.extras.pagination.Filter; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import org.jdbi.v3.core.statement.SqlStatement; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
|
||
@Component | ||
public class ProjectMemberFilter implements Filter<ProjectMemberFilter.ProjectMemberFilterInstance, String> { | ||
|
||
@Override | ||
public Set<String> getQueryParamNames() { | ||
return Set.of("member"); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "The member of the project"; | ||
} | ||
|
||
@Override | ||
public String getValue(final NativeWebRequest webRequest) { | ||
return webRequest.getParameter(this.getSingleQueryParam()); | ||
} | ||
|
||
@Override | ||
public @NotNull ProjectMemberFilterInstance create(final NativeWebRequest webRequest) { | ||
return new ProjectMemberFilterInstance(this.getValue(webRequest)); | ||
} | ||
|
||
static class ProjectMemberFilterInstance implements Filter.FilterInstance { | ||
|
||
private final String memberName; | ||
|
||
ProjectMemberFilterInstance(final String memberName) { | ||
this.memberName = memberName; | ||
} | ||
|
||
@Override | ||
public void createSql(final StringBuilder sb, final SqlStatement<?> q) { | ||
sb.append(" AND :memberName = ANY(hp.project_member_names)"); | ||
q.bind("memberName", this.memberName.toLowerCase(Locale.ROOT)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ProjectMemberFilterInstance{" + | ||
"memberName='" + this.memberName + '\'' + | ||
'}'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters