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