fixing search
This commit is contained in:
@@ -31,8 +31,17 @@ func (app *App) UpSearch(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
// render template
|
||||
t := template.Must(template.ParseFiles("assets/templates/article.html"))
|
||||
err = t.ExecuteTemplate(w, "content", articleVMs)
|
||||
t := template.Must(template.ParseFiles(
|
||||
"assets/templates/article.html",
|
||||
"assets/templates/layout.html",
|
||||
"assets/templates/components/pagination.html"))
|
||||
|
||||
data := map[string]interface{}{
|
||||
"SelectedNavItemArticle": true,
|
||||
"ArticleVMs": &articleVMs,
|
||||
"Paginations": nil,
|
||||
}
|
||||
err = t.ExecuteTemplate(w, "base", data)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to render template", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package database
|
||||
import (
|
||||
"crowsnest/internal/model"
|
||||
"database/sql"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ArticleModel struct {
|
||||
@@ -68,6 +69,7 @@ func (m *ArticleModel) Search(query string) ([]model.Article, error) {
|
||||
LIMIT 10
|
||||
`
|
||||
|
||||
query = strings.Join(strings.Split(strings.TrimSpace(query), " "), " | ")
|
||||
rows, err := m.DB.Query(stmt, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user