Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated api_handlers.go, database.go, and utils.go #57

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 11 additions & 5 deletions occupi-backend/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@
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 Expand Up @@ -153,8 +164,3 @@
}
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
}
Loading