From cca12a56bceb5cf063797dd35b2a3062c33c753e Mon Sep 17 00:00:00 2001 From: Rethakgetse-Manaka Date: Sun, 16 Jun 2024 10:07:16 +0200 Subject: [PATCH] Need to write tests --- occupi-backend/pkg/database/database.go | 10 +++++++--- occupi-backend/pkg/router/router.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/occupi-backend/pkg/database/database.go b/occupi-backend/pkg/database/database.go index aba7cd55..fa6e9c6f 100644 --- a/occupi-backend/pkg/database/database.go +++ b/occupi-backend/pkg/database/database.go @@ -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 { diff --git a/occupi-backend/pkg/router/router.go b/occupi-backend/pkg/router/router.go index 8d33ccdd..6882f3d8 100644 --- a/occupi-backend/pkg/router/router.go +++ b/occupi-backend/pkg/router/router.go @@ -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") {