Skip to content

Commit

Permalink
Updated api_handlers.go, database.go, and utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Rethakgetse-Manaka committed Jun 9, 2024
1 parent 24c4985 commit 1f55fb5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion occupi-backend/pkg/handlers/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion occupi-backend/pkg/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 11 additions & 0 deletions occupi-backend/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 72 in occupi-backend/pkg/utils/utils.go

View check run for this annotation

Codecov / codecov/patch

occupi-backend/pkg/utils/utils.go#L68-L72

Added lines #L68 - L72 were not covered by tests
}
BookID := fmt.Sprintf("BOOK%d%04d", currentYear, randomNum)
return BookID

Check warning on line 75 in occupi-backend/pkg/utils/utils.go

View check run for this annotation

Codecov / codecov/patch

occupi-backend/pkg/utils/utils.go#L74-L75

Added lines #L74 - L75 were not covered by tests
}

// generates a random auth0 state
func GenerateRandomState() (string, error) {
b := make([]byte, 32)
Expand Down

0 comments on commit 1f55fb5

Please sign in to comment.