diff --git a/occupi-backend/pkg/database/database.go b/occupi-backend/pkg/database/database.go index 0fe49011..3c48ecd1 100644 --- a/occupi-backend/pkg/database/database.go +++ b/occupi-backend/pkg/database/database.go @@ -110,7 +110,6 @@ func GetUserBookings(ctx *gin.Context, db *mongo.Client, email string) ([]models return nil, err } defer cursor.Close(ctx) - var bookings []models.Booking for cursor.Next(ctx) { var booking models.Booking @@ -118,6 +117,7 @@ func GetUserBookings(ctx *gin.Context, db *mongo.Client, email string) ([]models logrus.Error(err) return nil, err } + fmt.Println("Here") bookings = append(bookings, booking) } return bookings, nil diff --git a/occupi-backend/pkg/handlers/api_handlers.go b/occupi-backend/pkg/handlers/api_handlers.go index fc6585c4..afe17639 100644 --- a/occupi-backend/pkg/handlers/api_handlers.go +++ b/occupi-backend/pkg/handlers/api_handlers.go @@ -58,7 +58,7 @@ func BookRoom(ctx *gin.Context, appsession *models.AppSession) { // Generate a unique ID for the booking booking.ID = primitive.NewObjectID().Hex() - booking.OccupiID = 1 + booking.OccupiID = utils.GenerateBookingID() booking.CheckedIn = false // Save the booking to the database @@ -70,7 +70,7 @@ func BookRoom(ctx *gin.Context, appsession *models.AppSession) { // Prepare the email content subject := "Booking Confirmation - Occupi" - body := mail.FormatBookingEmailBody(booking.ID, booking.RoomID, booking.Slot) + body := mail.FormatBookingEmailBodyForBooker(booking.ID, booking.RoomID, booking.Slot, booking.Emails) // Send the confirmation email concurrently to all recipients emailErrors := mail.SendMultipleEmailsConcurrently(booking.Emails, subject, body) @@ -85,14 +85,15 @@ func BookRoom(ctx *gin.Context, appsession *models.AppSession) { // ViewBookings handles the retrieval of all bookings for a user func ViewBookings(ctx *gin.Context, appsession *models.AppSession) { - var userBooking models.User - if err := ctx.ShouldBindJSON(&userBooking); err != nil { + // Extract the email query parameter + email := ctx.Query("email") + if email == "" { ctx.JSON(http.StatusBadRequest, utils.ErrorResponse(http.StatusBadRequest, "Invalid request payload", constants.InvalidRequestPayloadCode, "Expected Email Address", nil)) return } // Get all bookings for the userBooking - bookings, err := database.GetUserBookings(ctx, appsession.DB, userBooking.Email) + bookings, err := database.GetUserBookings(ctx, appsession.DB, email) if err != nil { ctx.JSON(http.StatusInternalServerError, utils.ErrorResponse(http.StatusInternalServerError, "Failed to get bookings", constants.InternalServerErrorCode, "Failed to get bookings", nil)) return diff --git a/occupi-backend/pkg/mail/email_format.go b/occupi-backend/pkg/mail/email_format.go index cbaf1aa6..9ea9dc1d 100644 --- a/occupi-backend/pkg/mail/email_format.go +++ b/occupi-backend/pkg/mail/email_format.go @@ -21,7 +21,7 @@ func FormatBookingEmailBody(bookingID string, roomID string, slot int) string { } // formats booking email body to send person who booked -func FormatBookingEmailBodyForBooker(bookingID int, roomID string, slot int, attendees map[string]string) string { +func FormatBookingEmailBodyForBooker(bookingID string, roomID string, slot int, attendees []string) string { listOfAttendees := "