Dear attendees,
` + email + ` has booked an office space and invited you to join. Here are the booking details:
- Booking ID: ` + strconv.Itoa(bookingID) + `
+ Booking ID: ` + bookingID + `
Room ID: ` + roomID + `
Slot: ` + strconv.Itoa(slot) + `
If you have any questions, feel free to contact us.
diff --git a/occupi-backend/pkg/models/database.go b/occupi-backend/pkg/models/database.go
index 97f3472b..0f028712 100644
--- a/occupi-backend/pkg/models/database.go
+++ b/occupi-backend/pkg/models/database.go
@@ -16,14 +16,18 @@ type User struct {
// structure of booking
type Booking struct {
- ID string `json:"_id" bson:"_id,omitempty"`
- OccupiID int `json:"occupiId" bson:"occupiId,omitempty"`
- RoomID string `json:"roomId" bson:"roomId"`
- Slot int `json:"slot" bson:"slot"`
- Emails []string `json:"emails" bson:"emails"`
- CheckedIn bool `json:"checkedIn" bson:"checkedIn,omitempty"`
- Creator string `json:"creator" bson:"creator"`
- FloorNo int `json:"floorNo" bson:"floorNo"`
+ ID string `json:"_id" bson:"_id,omitempty"`
+ OccupiID string `json:"occupiId" bson:"occupiId,omitempty"`
+ RoomID string `json:"roomId" bson:"roomId"`
+ RoomName string `json:"roomName" bson:"roomName,omitempty"`
+ Slot int `json:"slot" bson:"slot"`
+ Emails []string `json:"emails" bson:"emails"`
+ CheckedIn bool `json:"checkedIn" bson:"checkedIn,omitempty"`
+ Creator string `json:"creator" bson:"creator"`
+ FloorNo int `json:"floorNo" bson:"floorNo"`
+ Date time.Time `json:"date" bson:"date,omitempty"`
+ Start time.Time `json:"start" bson:"start,omitempty"`
+ End time.Time `json:"end" bson:"end,omitempty"`
}
// structure of CheckIn
diff --git a/occupi-backend/pkg/router/router.go b/occupi-backend/pkg/router/router.go
index f105ff9a..30fb95dc 100644
--- a/occupi-backend/pkg/router/router.go
+++ b/occupi-backend/pkg/router/router.go
@@ -42,7 +42,7 @@ func OccupiRouter(router *gin.Engine, db *mongo.Client) {
api.POST("/book-room", middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.BookRoom(ctx, appsession) })
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-bookings"), middleware.UnProtectedRoute, func(ctx *gin.Context) { handlers.ViewBookings(ctx, appsession) })
api.GET("/view-rooms", middleware.ProtectedRoute, func(ctx *gin.Context) { handlers.ViewRooms(ctx, appsession) })
}
auth := router.Group("/auth")
diff --git a/occupi-backend/pkg/utils/utils.go b/occupi-backend/pkg/utils/utils.go
index 1f1dff29..b119e901 100644
--- a/occupi-backend/pkg/utils/utils.go
+++ b/occupi-backend/pkg/utils/utils.go
@@ -64,6 +64,17 @@ func GenerateEmployeeID() string {
return employeeID
}
+// Function to generate an employee ID with the structure OCCUPIYYYYXXXX
+func GenerateBookingID() string {
+ currentYear := time.Now().Year()
+ randomNum, err := generateRandomNumber()
+ if err != nil {
+ return "BOOKOCCUPI00000000"
+ }
+ employeeID := fmt.Sprintf("BOOKOCCUPI%d%04d", currentYear, randomNum)
+ return employeeID
+}
+
// generates a random auth0 state
func GenerateRandomState() (string, error) {
b := make([]byte, 32)
diff --git a/occupi-backend/tests/utils_test.go b/occupi-backend/tests/utils_test.go
index 83ec59a9..4c8a6c53 100644
--- a/occupi-backend/tests/utils_test.go
+++ b/occupi-backend/tests/utils_test.go
@@ -15,7 +15,10 @@ func TestGenEmpID(t *testing.T) {
empID := utils.GenerateEmployeeID()
t.Logf("Generated Employee ID: %s", empID)
}
-
+func TestGenBookID(t *testing.T) {
+ BookID := utils.GenerateBookingID()
+ t.Logf("Generated Booking ID: %s", BookID)
+}
func TestSanitizeInput(t *testing.T) {
tests := []struct {
name string