making frontend responsive starting item backend routes

This commit is contained in:
2022-03-30 22:57:38 -04:00
parent 1bed72250d
commit a70baddc4b
17 changed files with 909 additions and 242 deletions

View File

@@ -26,16 +26,16 @@ type Location struct {
// Room is a containerized area at a location
type Room struct {
ID int `storm:"id,increment,index"`
Name string `storm:"unique"`
Description string
CoverPhoto string // A "cover photo" for the room
Photos []string // A list of additional photos for the room
Notes string
Cabinets []Cabinet
Items []Item
SquareFeet int
ID int `storm:"id,increment,index"`
Name string `storm:"unique"`
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
@@ -62,8 +62,11 @@ type Item struct {
Serial string
Warranty string
Notes string
Files []string //filepath to any files relevant to this item
}
// Location Routes
//SetupDatabase initializes the storm/bbolt database
func SetupDatabase(s *Server) (db *storm.DB) {
db, err := storm.Open(filepath.Clean("./app/database/goInventorize.db"))
@@ -115,6 +118,8 @@ func (s *Server) GetLocation(locID int) (location Location, err error) {
return location, nil
}
// Room Routes
// AddRoom adds a room to a location
func (s *Server) AddRoom(room Room) error {
s.Log.Info().Msgf("Adding new room to location: %s", room)
@@ -159,17 +164,6 @@ func (s *Server) GetRoom(roomID int) (room Room, err error) {
return room, nil
}
// AddItem adds an item to a room
func (s *Server) AddItem(item Item) error {
s.Log.Info().Msgf("Adding new item to room: ", item)
err := s.Database.Save(&item)
if err != nil {
s.Log.Error().Msgf("Unable to add new item to room: %s error: %s", item, err)
return err
}
return nil
}
// GetRoomsAtLocation fetches all the rooms assigned to a location by location ID
func (s *Server) GetRoomsAtLocation(locID int) (rooms []Room, err error) {
err = s.Database.Find("LocationID", locID, &rooms)
@@ -190,6 +184,19 @@ func (s *Server) GetCabinetsInRoom(roomID int) (cabinets []Cabinet, err error) {
return cabinets, nil
}
// ITEM ROUTES
// GetAllItems gets all of the items
func (s *Server) GetAllItems() (items []Item, err error) {
s.Log.Info().Msg("Getting all Items")
err = s.Database.All(&items)
if err != nil {
s.Log.Error().Msgf("Unable to fetch all room with error: %s", err)
return items, err
}
return items, nil
}
// GetItemsInRoom fetches all of the items assigned to a room
func (s *Server) GetItemsInRoom(roomID int) (items []Item, err error) {
err = s.Database.Find("Room", roomID, &items)
@@ -199,3 +206,25 @@ func (s *Server) GetItemsInRoom(roomID int) (items []Item, err error) {
}
return items, nil
}
// AddItem adds an item to a room
func (s *Server) AddItem(item Item) error {
s.Log.Info().Msgf("Adding new item to room: ", item)
err := s.Database.Save(&item)
if err != nil {
s.Log.Error().Msgf("Unable to add new item to room: %s error: %s", item, err)
return err
}
return nil
}
// DeleteItem deletes an item
func (s *Server) DeleteItem(item Item) error {
s.Log.Info().Msgf("Deleting Item from database: %s", item)
err := s.Database.DeleteStruct(&item)
if err != nil {
s.Log.Error().Msgf("Unable to delete location from database: %s error: %s ", item, err)
return err
}
return nil
}