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

View File

@@ -6,71 +6,6 @@ import (
"github.com/asdine/storm/v3"
)
// Location is a top level component that starts the containerization process
type Location struct {
ID int `storm:"id,increment,index"`
Name string `storm:"unique"`
Description string
CoverPhoto string // A "cover photo" for the location
Photos []string // A list of additional photos for the location
Rooms []Room
Notes string
Address string
SquareFeet int
Latitude string
Longitude string
DatePurchased string
PurchasePrice string
CurrentValue string
}
// Room is a containerized area at a location
type Room struct {
ID int `storm:"id,increment,index"`
Name string
Description string
CoverPhoto string // A "cover photo" for the room
Photos []string // A list of additional photos for the room
Paint string // Details about the paint
Notes string
Cabinets []Cabinet
Items []Item
SquareFeet int
LocationID int //Which location room is assigned to
LocationName string // Location name room belongs to
}
// Cabinet is a containerized area in a room
type Cabinet struct {
ID int `storm:"id, increment"`
RoomID int // Room ID that the cabinet is assigned to
RoomName string // Room name cabinet belongs to
CoverPhoto string // A "Cover photo" for this item
Items []Item // List of items in the cabinet
Name string
Notes string
}
// Item is contained inside a room or cabinet
type Item struct {
ID int `storm:"id, increment"`
LocType string // Can be Room or Cabinet to show where it is stored
RoomID int // Room ID that item is assigned to (can also be in a cabinet)
RoomName string // Room name that item is assigned to
CabinetID int //The cabinet id that an item is assigned to
CabinetName string // The name of the cabinet it belongs to
CoverPhoto string // A "cover photo" for the item
Photos []string // A list of additional photos for the item
Count int // If item has duplicates
Name string
Product string
Serial string
Warranty string
Notes string
Files []string //filepath to any files relevant to this item
}
// Location Routes
//SetupDatabase initializes the storm/bbolt database
@@ -301,3 +236,51 @@ func (s *Server) DeleteItem(item Item) error {
}
return nil
}
// Misc calls
type SearchResults struct {
Locations []Location `json:"locations"`
Rooms []Room `json:"rooms"`
Cabinets []Cabinet `json:"cabinets"`
Items []Item `json:"items"`
}
// SearchAllByField searches the entire database (locs, rooms, cabinets, items) by the field and search term passed in
func (s *Server) SearchAllByField(fieldFilter string, searchTerm string) (results SearchResults, err error) {
s.Log.Info().Msgf("Searching all items for term: %s", searchTerm)
var locs []Location
var rooms []Room
var cabinets []Cabinet
var items []Item
results = SearchResults{}
err = s.Database.Find(fieldFilter, searchTerm, &locs)
if err != nil && err != storm.ErrNotFound {
s.Log.Error().Msgf("Unable to search locations in database with term: %s :error: %s ", searchTerm, err)
return results, err
}
err = s.Database.Find(fieldFilter, searchTerm, &rooms)
if err != nil && err != storm.ErrNotFound {
s.Log.Error().Msgf("Unable to search rooms in database with term: %s error: %s ", searchTerm, err)
return results, err
}
err = s.Database.Find(fieldFilter, searchTerm, &cabinets)
if err != nil && err != storm.ErrNotFound {
s.Log.Error().Msgf("Unable to search cabinets in database with term: %s error: %s ", searchTerm, err)
return results, err
}
err = s.Database.Find(fieldFilter, searchTerm, &items)
if err != nil && err != storm.ErrNotFound {
s.Log.Error().Msgf("Unable to search items in database with term: %s error: %s ", searchTerm, err)
return results, err
}
results.Locations = locs
results.Rooms = rooms
results.Cabinets = cabinets
results.Items = items
return results, nil
}