Add option to query webmentions with source (using like)

This commit is contained in:
Jan-Lukas Else 2021-05-24 10:09:37 +02:00
parent bc1a978793
commit 0dd256579a
2 changed files with 22 additions and 10 deletions

View File

@ -129,6 +129,7 @@ func reverifyWebmention(id int) error {
type webmentionsRequestConfig struct {
target string
status webmentionStatus
sourcelike string
id int
asc bool
offset, limit int
@ -138,17 +139,21 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
args = []interface{}{}
filter := ""
if config != nil {
if config.target != "" && config.status != "" {
filter = "where target = @target and status = @status"
args = append(args, sql.Named("target", unescapedPath(config.target)), sql.Named("status", config.status))
} else if config.target != "" {
filter = "where target = @target"
filter = "where 1 = 1"
if config.target != "" {
filter += " and target = @target"
args = append(args, sql.Named("target", config.target))
} else if config.status != "" {
filter = "where status = @status"
}
if config.status != "" {
filter += " and status = @status"
args = append(args, sql.Named("status", config.status))
} else if config.id != 0 {
filter = "where id = @id"
}
if config.sourcelike != "" {
filter += " and source like @sourcelike"
args = append(args, sql.Named("sourcelike", "%"+config.sourcelike+"%"))
}
if config.id != 0 {
filter += " and id = @id"
args = append(args, sql.Named("id", config.id))
}
}

View File

@ -44,7 +44,11 @@ func webmentionAdmin(w http.ResponseWriter, r *http.Request) {
case webmentionStatusApproved:
status = webmentionStatusApproved
}
p := paginator.New(&webmentionPaginationAdapter{config: &webmentionsRequestConfig{status: status}}, 10)
sourcelike := r.URL.Query().Get("source")
p := paginator.New(&webmentionPaginationAdapter{config: &webmentionsRequestConfig{
status: status,
sourcelike: sourcelike,
}}, 10)
p.SetPage(pageNo)
var mentions []*mention
err := p.Results(&mentions)
@ -80,6 +84,9 @@ func webmentionAdmin(w http.ResponseWriter, r *http.Request) {
if status != "" {
params.Add("status", string(status))
}
if sourcelike != "" {
params.Add("source", sourcelike)
}
if len(params) > 0 {
query = "?" + params.Encode()
}