more room routes
This commit is contained in:
41
database.go
41
database.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user