Skip to content

Commit

Permalink
Need to write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rethakgetse-Manaka committed Jun 16, 2024
1 parent 7608c31 commit cca12a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions occupi-backend/pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,18 @@ func GetAllRooms(ctx *gin.Context, db *mongo.Client, floorNo int) ([]models.Room
var cursor *mongo.Cursor
var err error

if floorNo == -1 {
findOptions := options.Find()
findOptions.SetLimit(10) // Limit the results to 10
findOptions.SetSkip(int64(10)) // Skip the specified number of documents for pagination

if floorNo == 0 {
// Find all rooms
filter := bson.M{"floorNo": 0}
cursor, err = collection.Find(context.TODO(), filter)
cursor, err = collection.Find(context.TODO(), filter, findOptions)
} else {
// Find all rooms on the specified floor
filter := bson.M{"floorNo": floorNo}
cursor, err = collection.Find(context.TODO(), filter)
cursor, err = collection.Find(context.TODO(), filter, findOptions)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion occupi-backend/pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func OccupiRouter(router *gin.Engine, db *mongo.Client) {
api.POST("/check-in", middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.CheckIn(ctx, appsession) })
api.POST("cancel-booking", middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.CancelBooking(ctx, appsession) })
api.GET(("view-bookings"), middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.ViewBookings(ctx, appsession) })
api.GET("/view-rooms", middleware.UnProtectedRoute, func(ctx *gin.Context) { handlers.ViewRooms(ctx, appsession) })
api.GET("/view-rooms", middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.ViewRooms(ctx, appsession) })
}
auth := router.Group("/auth")
{
Expand Down

0 comments on commit cca12a5

Please sign in to comment.