Add ability to query the article index
This commit is contained in:
parent
0cd964343b
commit
d6c58cf532
@ -57,7 +57,7 @@ func newConfig() *Config {
|
||||
MaxImgWidth: 1920,
|
||||
PDFDir: "/var/www/cpolis/pdfs",
|
||||
Port: ":1664",
|
||||
Version: "v0.16.2",
|
||||
Version: "v0.17.0",
|
||||
WebDir: "/var/www/cpolis/web",
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package calls
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -109,3 +110,21 @@ func ServeClicks(db *b.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func QueryArticles(i *b.Index) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := i.Query(r.PathValue("query"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(result); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, fmt.Sprintf("error encoding results to JSON: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ func main() {
|
||||
mux.HandleFunc("GET /article/delete/{id}", f.DeleteArticle(config, db, sessions))
|
||||
mux.HandleFunc("GET /article/edit/{id}", f.EditArticle(config, db, sessions))
|
||||
mux.HandleFunc("GET /article/publish/{id}", f.PublishArticle(config, db, sessions, index))
|
||||
mux.HandleFunc("GET /article/query/{query}", c.QueryArticles(index))
|
||||
mux.HandleFunc("GET /article/reject/{id}", f.RejectArticle(config, db, sessions))
|
||||
mux.HandleFunc("GET /article/review-delete/{id}", f.ReviewArticle(config, db, sessions, "delete", "Artikel löschen", "Löschen"))
|
||||
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, sessions, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user