more room routes
This commit is contained in:
@@ -220,3 +220,98 @@
|
||||
{"level":"info","time":"2022-01-08T22:50:04-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-08T22:50:04-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-08T22:50:04-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T10:47:35-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T10:47:35-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T10:47:35-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"logtype":"webserver", "pid":"20004", "requestid":"", "status":"200", "method":"GET", "path":"/api/config"}
|
||||
{"level":"info","time":"2022-01-09T10:48:38-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T10:48:38-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T10:48:38-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T10:52:16-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T10:52:16-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T10:52:16-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T11:32:12-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T11:32:12-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T11:32:12-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T11:41:54-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T11:41:54-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T11:41:54-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T11:42:49-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T11:42:49-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T11:42:49-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:29:36-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:29:36-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:29:36-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:30:55-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:30:55-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:30:55-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"debug","time":"2022-01-09T12:31:01-05:00","message":"Returning Locations: [{ID:3 Name:Location1 Description: CoverPhoto:Location1_cover.png Photos:[Location1_0.png Location1_1.png] Rooms:[] Notes:Notes for my location!} {ID:4 Name:Location4 Description: CoverPhoto:Location4_cover.png Photos:[Location4_0.png Location4_1.png] Rooms:[] Notes:Notes for my location!}]"}
|
||||
{"logtype":"webserver", "pid":"22320", "requestid":"", "status":"200", "method":"GET", "path":"/api/locations"}
|
||||
{"level":"info","time":"2022-01-09T12:34:38-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:34:38-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:34:38-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:35:29-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:35:29-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:35:29-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:35:33-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:35:33-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:35:33-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:35:49-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:35:49-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:35:49-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:36:10-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:36:10-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:36:10-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:37:37-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:37:37-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:37:37-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:38:28-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:38:28-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:38:28-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"logtype":"webserver", "pid":"23980", "requestid":"", "status":"500", "method":"POST", "path":"/api/rooms/3/new"}
|
||||
{"level":"info","time":"2022-01-09T12:39:35-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:39:35-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:39:35-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:40:20-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:40:20-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:40:20-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:40:33-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:40:33-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:40:33-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"logtype":"webserver", "pid":"38540", "requestid":"", "status":"500", "method":"POST", "path":"/api/rooms/3/new"}
|
||||
{"level":"info","time":"2022-01-09T12:42:04-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:42:04-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:42:04-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:44:05-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:44:05-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:44:05-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:44:07-05:00","message":"Adding new room to location: {%!s(int=0) Kitchen Location1/Kitchen/Kitchen_cover.png [Location1/Kitchen/Kitchen_0.png] Notes For My Room! [] [] %!s(int=3)}"}
|
||||
{"level":"debug","time":"2022-01-09T12:44:07-05:00","message":"Adding new Room: {0 Kitchen Location1/Kitchen/Kitchen_cover.png [Location1/Kitchen/Kitchen_0.png] Notes For My Room! [] [] 3}"}
|
||||
{"logtype":"webserver", "pid":"22756", "requestid":"", "status":"200", "method":"POST", "path":"/api/rooms/3/new"}
|
||||
{"level":"info","time":"2022-01-09T12:44:15-05:00","message":"Getting all Rooms"}
|
||||
{"logtype":"webserver", "pid":"22756", "requestid":"", "status":"200", "method":"GET", "path":"/api/rooms"}
|
||||
{"level":"info","time":"2022-01-09T12:48:32-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:48:32-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:48:32-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:49:26-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:49:26-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:49:26-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:50:22-05:00","message":"Configuration loaded successfully..."}
|
||||
{"level":"debug","time":"2022-01-09T12:50:22-05:00","message":"{Timezone:America/New_York Server:{Port:3500 LocationPhotoDir:./app/photos/locations/} Logger:{Level:debug LoggingFile:./app/log/goInventorize.log} Authentication:{BasicAuth:false UserName:admin Password:password} Development:false}"}
|
||||
{"level":"info","time":"2022-01-09T12:50:22-05:00","message":"Database and Config loaded, starting webserver..."}
|
||||
{"level":"info","time":"2022-01-09T12:50:59-05:00","message":"Fetching room with id: 1"}
|
||||
{"level":"info","time":"2022-01-09T12:50:59-05:00","message":"Deleting room from database: {%!s(int=1) Kitchen Location1/Kitchen/Kitchen_cover.png [Location1/Kitchen/Kitchen_0.png] Notes For My Room! [] [] %!s(int=3) }"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"DELETE", "path":"/api/rooms/1"}
|
||||
{"level":"info","time":"2022-01-09T12:51:03-05:00","message":"Getting all Rooms"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"GET", "path":"/api/rooms"}
|
||||
{"level":"info","time":"2022-01-09T12:53:49-05:00","message":"Adding new room to location: {%!s(int=0) Kitchen Location1/Kitchen/Kitchen_cover.png [Location1/Kitchen/Kitchen_0.png] Notes For My Room! [] [] %!s(int=3) Location1}"}
|
||||
{"level":"debug","time":"2022-01-09T12:53:49-05:00","message":"Adding new Room: {0 Kitchen Location1/Kitchen/Kitchen_cover.png [Location1/Kitchen/Kitchen_0.png] Notes For My Room! [] [] 3 Location1}"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"POST", "path":"/api/rooms/3/new"}
|
||||
{"level":"info","time":"2022-01-09T12:54:00-05:00","message":"Getting all Rooms"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"GET", "path":"/api/rooms"}
|
||||
{"level":"debug","time":"2022-01-09T12:54:45-05:00","message":"Returning Locations: [{ID:3 Name:Location1 Description: CoverPhoto:Location1_cover.png Photos:[Location1_0.png Location1_1.png] Rooms:[] Notes:Notes for my location!} {ID:4 Name:Location4 Description: CoverPhoto:Location4_cover.png Photos:[Location4_0.png Location4_1.png] Rooms:[] Notes:Notes for my location!}]"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"GET", "path":"/api/locations"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"304", "method":"GET", "path":"/photos/locations/Location4/Location4_cover.png"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"304", "method":"GET", "path":"/photos/locations/Location1/Location1_cover.png"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"200", "method":"GET", "path":"/api/rooms/3"}
|
||||
{"logtype":"webserver", "pid":"14596", "requestid":"", "status":"404", "method":"GET", "path":"/photos/rooms/Kitchen/Location1/Kitchen/Kitchen_cover.png"}
|
||||
|
BIN
app/photos/locations/Location1/Kitchen/Kitchen_0.png
Normal file
BIN
app/photos/locations/Location1/Kitchen/Kitchen_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 282 KiB |
BIN
app/photos/locations/Location1/Kitchen/Kitchen_cover.png
Normal file
BIN
app/photos/locations/Location1/Kitchen/Kitchen_cover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
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)
|
||||
|
@@ -58,9 +58,9 @@ function RoomsPage(props) {
|
||||
</Card.Section>
|
||||
<Group position="apart">
|
||||
<Text weight={500}>{room.Name}</Text>
|
||||
{/* <Badge color="pink" variant="light">
|
||||
On Sale
|
||||
</Badge> */}
|
||||
<Badge color="pink" variant="light">
|
||||
{room.LocationName}
|
||||
</Badge>
|
||||
</Group>
|
||||
<Text size="sm">{room.Description}</Text>
|
||||
</Card>
|
||||
|
70
handlers.go
70
handlers.go
@@ -125,26 +125,59 @@ func (s *Server) DeleteLocationHandler(c *fiber.Ctx) error {
|
||||
s.Log.Err(err).Msgf("Unable to delete location with id: %d", locID)
|
||||
return err
|
||||
}
|
||||
fmt.Println("LocID: ", locID)
|
||||
return c.Status(fiber.StatusOK).SendString(fmt.Sprintf("Location Deleted! %d", locID))
|
||||
}
|
||||
|
||||
// Add a new location
|
||||
// DeleteRoomHandler deletes a room based on an ID
|
||||
func (s *Server) DeleteRoomHandler(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
|
||||
}
|
||||
err = s.DeleteRoom(room)
|
||||
if err != nil {
|
||||
s.Log.Err(err).Msgf("Unable to delete room with id: %d", roomID)
|
||||
return err
|
||||
}
|
||||
return c.Status(fiber.StatusOK).SendString(fmt.Sprintf("Room Deleted! %d", roomID))
|
||||
}
|
||||
|
||||
// AddNewRoomHandler adds a new room
|
||||
func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
|
||||
locID, err := c.ParamsInt("locID")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
s.Log.Err(err).Msgf("Unable to fetch rooms: ", err)
|
||||
return err
|
||||
}
|
||||
roomName := form.Value["Name"][0]
|
||||
fmt.Println("COverphoto: ", form.File["CoverPhoto"])
|
||||
roomPhoto := form.File["CoverPhoto"][0]
|
||||
if err != nil {
|
||||
s.Log.Err(err).Msgf("Unable to get CoverPhoto for Room: ", err)
|
||||
return err
|
||||
}
|
||||
roomAdditionalPhotos := form.File["AdditionalPhotos"]
|
||||
// Create the directory for this location to store the photos
|
||||
err = os.MkdirAll(s.Config.Server.LocationPhotoDir+roomName, 0755)
|
||||
// Fetch the location information
|
||||
loc, err := s.GetLocation(locID)
|
||||
if err != nil {
|
||||
s.Log.Err(err).Msgf("Unable to fetch location by id: %d with error: %s", locID, err)
|
||||
return err
|
||||
}
|
||||
// setting the path prepend for the photos
|
||||
urlPrepend := loc.Name + "/" + roomName + "/"
|
||||
pathPrepend := s.Config.Server.LocationPhotoDir + "/" + urlPrepend
|
||||
|
||||
// Create the directory for this room to store the photos
|
||||
err = os.MkdirAll(filepath.ToSlash(s.Config.Server.LocationPhotoDir+"/"+loc.Name+"/"+roomName), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -156,8 +189,8 @@ func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
photoPath := filepath.ToSlash(s.Config.Server.LocationPhotoDir + roomName + "/" + roomName + "_" + strconv.Itoa(i) + filepath.Ext(photo.Filename))
|
||||
photoURL := roomName + "_" + strconv.Itoa(i) + filepath.Ext(photo.Filename)
|
||||
photoPath := filepath.ToSlash(pathPrepend + roomName + "_" + strconv.Itoa(i) + filepath.Ext(photo.Filename))
|
||||
photoURL := urlPrepend + roomName + "_" + strconv.Itoa(i) + filepath.Ext(photo.Filename)
|
||||
photoURLsList = append(photoURLsList, photoURL)
|
||||
photoData, err := io.ReadAll(src)
|
||||
if err != nil {
|
||||
@@ -166,12 +199,12 @@ func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
|
||||
os.WriteFile(photoPath, photoData, 0644)
|
||||
}
|
||||
// create files on server for all uploads
|
||||
locNotes := form.Value["Notes"][0]
|
||||
roomNotes := form.Value["Notes"][0]
|
||||
|
||||
// saving the uploaded image to our images dir
|
||||
coverImagePath := filepath.ToSlash(s.Config.Server.LocationPhotoDir + roomName + "/" + roomName + "_cover" + filepath.Ext(roomPhoto.Filename))
|
||||
coverImagePath := filepath.ToSlash(pathPrepend + roomName + "_cover" + filepath.Ext(roomPhoto.Filename))
|
||||
// Creating the URL to retrieve photo
|
||||
coverImageURL := roomName + "_cover" + filepath.Ext(roomPhoto.Filename)
|
||||
coverImageURL := urlPrepend + roomName + "_cover" + filepath.Ext(roomPhoto.Filename)
|
||||
src, err := roomPhoto.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -186,18 +219,20 @@ func (s *Server) AddNewRoomHandler(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newLocation := Location{
|
||||
Name: roomName,
|
||||
CoverPhoto: coverImageURL,
|
||||
Photos: photoURLsList,
|
||||
Notes: locNotes,
|
||||
newRoom := Room{
|
||||
Name: roomName,
|
||||
CoverPhoto: coverImageURL,
|
||||
Photos: photoURLsList,
|
||||
Notes: roomNotes,
|
||||
LocationID: locID,
|
||||
LocationName: loc.Name,
|
||||
}
|
||||
err = s.AddLocation(newLocation)
|
||||
err = s.AddRoom(newRoom)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.Log.Debug().Msgf("Adding new location: %v", newLocation)
|
||||
return c.Status(fiber.StatusOK).SendString(fmt.Sprintf("New Location Created! %s", newLocation.Name))
|
||||
s.Log.Debug().Msgf("Adding new Room: %v", newRoom)
|
||||
return c.Status(fiber.StatusOK).SendString(fmt.Sprintf("New Room Created! %s", newRoom.Name))
|
||||
}
|
||||
|
||||
// GetAllRoomsHandler gets all of the rooms in the db
|
||||
@@ -209,6 +244,7 @@ func (s *Server) GetAllRoomsHandler(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(rooms)
|
||||
}
|
||||
|
||||
// GetRoomsAtLocationHandler gets rooms at a location
|
||||
func (s *Server) GetRoomsAtLocationHandler(c *fiber.Ctx) error {
|
||||
locID, err := c.ParamsInt("locID")
|
||||
if err != nil {
|
||||
|
3
main.go
3
main.go
@@ -102,7 +102,8 @@ func main() {
|
||||
// Room Routes
|
||||
server.WebServer.Get("/api/rooms", server.GetAllRoomsHandler)
|
||||
server.WebServer.Get("/api/rooms/:locID", server.GetRoomsAtLocationHandler)
|
||||
server.WebServer.Post("/api/rooms/new", server.AddNewRoomHandler)
|
||||
server.WebServer.Post("/api/rooms/:locID/new", server.AddNewRoomHandler)
|
||||
server.WebServer.Delete("/api/rooms/:roomID", server.DeleteRoomHandler)
|
||||
fmt.Println("Everything ready, starting server! ", fmt.Sprintf(":%s", server.Config.Server.Port))
|
||||
server.WebServer.Listen(fmt.Sprintf(":%s", server.Config.Server.Port))
|
||||
}
|
||||
|
Reference in New Issue
Block a user