Skip to content

Commit

Permalink
Refactor API documentation to remove unused resource section
Browse files Browse the repository at this point in the history
  • Loading branch information
waveyboym committed Sep 25, 2024
1 parent 0a81ac8 commit ed3cb72
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 61 deletions.
33 changes: 0 additions & 33 deletions documentation/occupi-docs/pages/api-documentation/api-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ The API also allows you to retrieve information about these resources.
- [Table of Contents](#table-of-contents)
- [Base URL](#base-url)
- [Api](#api)
- [Resources](#resources)
- [Book Room](#BookRoom)
- [View Bookings](#ViewBookings)
- [View Rooms](#ViewRooms)
Expand Down Expand Up @@ -51,38 +50,6 @@ The base URL for the Occupi API is `https://occupi.tech`, `https://dev.occupi.te

The API endpoints are used to interact with the Occupi platform. Mainly GET, POST, PUT, DELETE requests are used.

### Resources

The resources endpoints are used to create, read, update, and delete resources.

- **URL**

`/api/resources`

- **Method**

`GET`

- **Success Response**

- **Code:** 200
- **Content:** `{ "message": "Resources fetched successfully" }`

- **Error Response**

- **Code:** 400
- **Content:** `{ "message": "Bad Request" }`

- **Error Response**
- **Code:** 500
- **Content:** `{ "message": "Internal server error" }`

**_Example json to send:_**

```json copy
{}
```

### BookRoom

This endpoint is used to book a room in the Occupi system. The client needs to provide the room ID,
Expand Down
12 changes: 9 additions & 3 deletions frontend/occupi-web/src/pages/rooms/Rooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ interface Room {
roomId: string;
roomName: string;
roomNo: string;
imageUrl?: string;
roomImage?: {
uuid: string;
thumbnailRes: string;
lowRes: string;
midRes: string;
highRes: string;
};
isDisabled: boolean;
}

Expand Down Expand Up @@ -304,9 +310,9 @@ const Rooms: React.FC = () => {
)}
<div className="p-4 flex flex-col md:flex-row">
<div className="w-full md:w-1/3 mb-4 md:mb-0 md:mr-4">
{room.imageUrl ? (
{room.roomImage ? (
<Image
src={room.imageUrl}
src={room.roomImage.midRes}
alt={room.roomName}
className="w-full h-48 object-cover rounded-lg"
/>
Expand Down
33 changes: 28 additions & 5 deletions occupi-backend/pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ func UpdateNotificationSettings(ctx *gin.Context, appsession *models.AppSession,
return nil
}

func AddImageIDToRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
func AddImageToRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
// check if database is nil
if appsession.DB == nil {
logrus.Error("Database is nil")
Expand All @@ -1300,8 +1300,19 @@ func AddImageIDToRoom(ctx *gin.Context, appsession *models.AppSession, roomID, i

collection := appsession.DB.Database(configs.GetMongoDBName()).Collection("Rooms")

thumbnailURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s%s", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), imageID, constants.ThumbnailRes)
lowURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s%s", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), imageID, constants.LowRes)
midURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s%s", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), imageID, constants.MidRes)
highURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s%s", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), imageID, constants.HighRes)

filter := bson.M{"roomId": roomID}
update := bson.M{"$addToSet": bson.M{"roomImageIds": imageID}}
update := bson.M{"$set": bson.M{
"roomImage.uuid": imageID,
"roomImage.thumbnailRes": thumbnailURL,
"roomImage.lowRes": lowURL,
"roomImage.midRes": midURL,
"roomImage.highRes": highURL,
}}

_, err := collection.UpdateOne(ctx, filter, update)
if err != nil {
Expand All @@ -1312,7 +1323,7 @@ func AddImageIDToRoom(ctx *gin.Context, appsession *models.AppSession, roomID, i
return nil
}

func DeleteImageIDFromRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
func DeleteImageFromRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
// check if database is nil
if appsession.DB == nil {
logrus.Error("Database is nil")
Expand All @@ -1322,7 +1333,13 @@ func DeleteImageIDFromRoom(ctx *gin.Context, appsession *models.AppSession, room
collection := appsession.DB.Database(configs.GetMongoDBName()).Collection("Rooms")

filter := bson.M{"roomId": roomID}
update := bson.M{"$pull": bson.M{"roomImageIds": imageID}}
update := bson.M{"$set": bson.M{
"roomImage.uuid": "",
"roomImage.thumbnailRes": fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.ThumbnailRes),
"roomImage.lowRes": fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.LowRes),
"roomImage.midRes": fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.MidRes),
"roomImage.highRes": fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.HighRes),
}}

_, err := collection.UpdateOne(ctx, filter, update)
if err != nil {
Expand Down Expand Up @@ -1374,7 +1391,13 @@ func AddRoom(ctx *gin.Context, appsession *models.AppSession, rroom models.Reque
MaxOccupancy: rroom.MaxOccupancy,
Description: rroom.Description,
RoomName: rroom.RoomName,
RoomImageIDs: []string{},
RoomImage: models.RoomImage{
UUID: "",
ThumbnailRes: fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.ThumbnailRes),
LowRes: fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.LowRes),
MidRes: fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.MidRes),
HighRes: fmt.Sprintf("https://%s.blob.core.windows.net/%s/default-office-%s.png", configs.GetAzureAccountName(), configs.GetAzureRoomsContainerName(), constants.HighRes),
},
}

// filter - ensure no room exists with the same roomid or roomno before inserting
Expand Down
4 changes: 2 additions & 2 deletions occupi-backend/pkg/handlers/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ func UploadRoomImage(ctx *gin.Context, appsession *models.AppSession) {
}

// Update the room details with the image id
err = database.AddImageIDToRoom(ctx, appsession, roomid, uuid)
err = database.AddImageToRoom(ctx, appsession, roomid, uuid)

if err != nil {
configs.CaptureError(ctx, err)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func DeleteRoomImage(ctx *gin.Context, appsession *models.AppSession) {
}

// Update the room details with the image id
if err := database.DeleteImageIDFromRoom(ctx, appsession, request.RoomID, request.ID); err != nil {
if err := database.DeleteImageFromRoom(ctx, appsession, request.RoomID, request.ID); err != nil {
configs.CaptureError(ctx, err)
logrus.WithError(err).Error("Failed to delete image id")
ctx.JSON(http.StatusInternalServerError, utils.ErrorResponse(http.StatusInternalServerError, "Failed to delete room image id", constants.InternalServerErrorCode, "Failed to delete room image", nil))
Expand Down
28 changes: 18 additions & 10 deletions occupi-backend/pkg/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,24 @@ type ViewBookings struct {
}

type Room struct {
ID string `json:"_id" bson:"_id,omitempty"`
RoomID string `json:"roomId" bson:"roomId,omitempty"`
RoomNo string `json:"roomNo" bson:"roomNo,omitempty"`
FloorNo string `json:"floorNo" bson:"floorNo" binding:"required"`
MinOccupancy int `json:"minOccupancy" bson:"minOccupancy,omitempty"`
MaxOccupancy int `json:"maxOccupancy" bson:"maxOccupancy"`
Description string `json:"description" bson:"description"`
RoomName string `json:"roomName" bson:"roomName"`
RoomImageIDs []string `json:"roomImageIds" bson:"roomImageIds"`
Resources []string `json:"resources" bson:"resources"`
ID string `json:"_id" bson:"_id,omitempty"`
RoomID string `json:"roomId" bson:"roomId,omitempty"`
RoomNo string `json:"roomNo" bson:"roomNo,omitempty"`
FloorNo string `json:"floorNo" bson:"floorNo" binding:"required"`
MinOccupancy int `json:"minOccupancy" bson:"minOccupancy,omitempty"`
MaxOccupancy int `json:"maxOccupancy" bson:"maxOccupancy"`
Description string `json:"description" bson:"description"`
RoomName string `json:"roomName" bson:"roomName"`
RoomImage RoomImage `json:"roomImage" bson:"roomImage"`
}

type RoomImage struct {
ID string `json:"_id" bson:"_id,omitempty"`
UUID string `json:"uuid" bson:"uuid"`
ThumbnailRes string `json:"thumbnailRes" bson:"thumbnailRes"`
LowRes string `json:"lowRes" bson:"lowRes"`
MidRes string `json:"midRes" bson:"midRes"`
HighRes string `json:"highRes" bson:"highRes"`
}

type ResetToken struct {
Expand Down
15 changes: 7 additions & 8 deletions occupi-backend/pkg/models/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ type ImageRequest struct {
}

type RequestRoom struct {
RoomID string `json:"roomId" binding:"required,startswith=RM"`
RoomNo string `json:"roomNo" binding:"required"`
FloorNo string `json:"floorNo" binding:"required"`
MinOccupancy int `json:"minOccupancy" binding:"required"`
MaxOccupancy int `json:"maxOccupancy" binding:"required"`
Description string `json:"description" binding:"required"`
RoomName string `json:"roomName" binding:"required"`
Resources []string `json:"resources" binding:"required"`
RoomID string `json:"roomId" binding:"required,startswith=RM"`
RoomNo string `json:"roomNo" binding:"required"`
FloorNo string `json:"floorNo" binding:"required"`
MinOccupancy int `json:"minOccupancy" binding:"required"`
MaxOccupancy int `json:"maxOccupancy" binding:"required"`
Description string `json:"description" binding:"required"`
RoomName string `json:"roomName" binding:"required"`
}

type WebAuthnSession struct {
Expand Down

0 comments on commit ed3cb72

Please sign in to comment.