diff --git a/cmd/backend/config.go b/cmd/backend/config.go index a63054f..6e02da2 100644 --- a/cmd/backend/config.go +++ b/cmd/backend/config.go @@ -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", } } diff --git a/cmd/calls/articles.go b/cmd/calls/articles.go index 9908780..ceec867 100644 --- a/cmd/calls/articles.go +++ b/cmd/calls/articles.go @@ -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 + } + } +} diff --git a/cmd/main.go b/cmd/main.go index 4c730b5..91fb977 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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"))