more database work, added search route, starting frontend new location form
This commit is contained in:
22
handlers_other.go
Normal file
22
handlers_other.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// SearchAllByField searches all of the DB by specified field
|
||||
func (s *Server) SearchAllHandler(c *fiber.Ctx) error {
|
||||
searchField := c.Query("field", "Name")
|
||||
searchTerm := c.Query("term")
|
||||
|
||||
s.Log.Debug().Msgf("Search by term: %s in all items at field: %s", searchTerm, searchField)
|
||||
results, err := s.SearchAllByField(searchField, searchTerm)
|
||||
if err != nil {
|
||||
s.Log.Error().Msgf("SearchAllByField failed to return results: %s ", err)
|
||||
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Database failure! error: %s", err))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(results)
|
||||
}
|
Reference in New Issue
Block a user