fixing add item route, working on finishing cabinet routes

This commit is contained in:
2022-04-01 21:57:35 -04:00
parent a70baddc4b
commit cc60aa59d5
6 changed files with 449 additions and 64 deletions

View File

@@ -29,6 +29,20 @@ func (s *Server) DeleteRoomHandler(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).SendString(fmt.Sprintf("Room Deleted! %d", roomID))
}
// GetRoomHandler returns a single room from an ID
func (s *Server) GetRoomHandler(c *fiber.Ctx) error {
roomID, err := c.ParamsInt("roomID")
if err != nil {
return err
}
room, err := s.GetRoom(roomID)
if err != nil {
s.Log.Err(err).Msgf("Unable to fetch room with id: %d", roomID)
return err
}
return c.Status(fiber.StatusOK).JSON(room)
}
// AddNewRoomHandler adds a new room
func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
locID, err := c.ParamsInt("locID")
@@ -113,15 +127,15 @@ func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
if err != nil {
return err
}
// Update our location in the db to add the new room as attached to the ID
loc, err = s.GetLocation(newRoom.LocationID)
if err != nil {
return err
}
// // Update our location in the db to add the new room as attached to the ID
// loc, err = s.GetLocation(newRoom.LocationID)
// if err != nil {
// return err
// }
roomList := loc.Rooms
roomList = append(roomList, newRoom)
err = s.Database.UpdateField(&Location{ID: newRoom.LocationID}, "Rooms", roomList)
err = s.Database.UpdateField(&Location{ID: locID}, "Rooms", roomList)
if err != nil {
return err
}