From 1f55fb5cc47e5c438f96dd825ad484ad582c32df Mon Sep 17 00:00:00 2001 From: Rethakgetse-Manaka Date: Sun, 9 Jun 2024 15:58:58 +0200 Subject: [PATCH 1/2] Updated api_handlers.go, database.go, and utils.go --- occupi-backend/pkg/handlers/api_handlers.go | 2 +- occupi-backend/pkg/models/database.go | 2 +- occupi-backend/pkg/utils/utils.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/occupi-backend/pkg/handlers/api_handlers.go b/occupi-backend/pkg/handlers/api_handlers.go index 63de0880..dda100a2 100644 --- a/occupi-backend/pkg/handlers/api_handlers.go +++ b/occupi-backend/pkg/handlers/api_handlers.go @@ -49,7 +49,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.GenerateOccupiBookID() booking.CheckedIn = false // Save the booking to the database diff --git a/occupi-backend/pkg/models/database.go b/occupi-backend/pkg/models/database.go index 08211297..76689ad7 100644 --- a/occupi-backend/pkg/models/database.go +++ b/occupi-backend/pkg/models/database.go @@ -17,7 +17,7 @@ type User struct { // structure of booking type Booking struct { ID string `json:"_id" bson:"_id,omitempty"` - OccupiID int `json:"occupiId" bson:"occupiId,omitempty"` + OccupiID string `json:"occupiId" bson:"occupiId,omitempty"` RoomID string `json:"roomId" bson:"roomId"` Slot int `json:"slot" bson:"slot"` Emails []string `json:"emails" bson:"emails"` diff --git a/occupi-backend/pkg/utils/utils.go b/occupi-backend/pkg/utils/utils.go index 814193a8..b1281557 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 a Booking ID with the structure BOOKYYYYMMDDXXXX +func GenerateOccupiBookID() string { + currentYear := time.Now().Year() + randomNum, err := generateRandomNumber() + if err != nil { + return "BOOK00000000" + } + BookID := fmt.Sprintf("BOOK%d%04d", currentYear, randomNum) + return BookID +} + // generates a random auth0 state func GenerateRandomState() (string, error) { b := make([]byte, 32) From 70917078a42d934e5eeaf72ca371c50c5e8b4cdb Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 9 Jun 2024 18:11:14 +0200 Subject: [PATCH 2/2] chore: removing dead code --- occupi-backend/pkg/utils/utils.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/occupi-backend/pkg/utils/utils.go b/occupi-backend/pkg/utils/utils.go index 5b872d39..4848f151 100644 --- a/occupi-backend/pkg/utils/utils.go +++ b/occupi-backend/pkg/utils/utils.go @@ -180,8 +180,3 @@ func CompareArgon2IDHash(password string, hashedPassword string) (bool, error) { } return match, nil } - -func WillRemove() { - // This function is only here to make sure that the package is not empty - // and that the linter does not complain about it -}