more room routes

This commit is contained in:
2022-01-09 12:56:07 -05:00
parent c811a8e2b9
commit 6ced49f5cd
7 changed files with 185 additions and 30 deletions

View File

@@ -19,15 +19,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
LocationID int //Which location room is assigned to
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
LocationID int //Which location room is assigned to
LocationName string // Location name room belongs to
}
@@ -116,6 +117,17 @@ func (s *Server) AddRoom(room Room) error {
return nil
}
// DeleteRoom deletes a room
func (s *Server) DeleteRoom(room Room) error {
s.Log.Info().Msgf("Deleting room from database: %s", room)
err := s.Database.DeleteStruct(&room)
if err != nil {
s.Log.Error().Msgf("Unable to delete location from database: %s error: %s ", room, err)
return err
}
return nil
}
// GetAllRooms gets all of the rooms
func (s *Server) GetAllRooms() (rooms []Room, err error) {
s.Log.Info().Msg("Getting all Rooms")
@@ -127,6 +139,17 @@ func (s *Server) GetAllRooms() (rooms []Room, err error) {
return rooms, nil
}
// GetRoom gets a room based on id
func (s *Server) GetRoom(roomID int) (room Room, err error) {
s.Log.Info().Msgf("Fetching room with id: %d", roomID)
err = s.Database.One("ID", roomID, &room)
if err != nil {
s.Log.Error().Msgf("Unable to fetch room with id: %d with error: %s", roomID, err)
return room, err
}
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)