more database work, added search route, starting frontend new location form

This commit is contained in:
2022-04-02 23:15:23 -04:00
parent cc60aa59d5
commit 03dd723c57
14 changed files with 431 additions and 1110 deletions

22
handlers_other.go Normal file
View 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)
}