Skip to content

Commit

Permalink
Merge pull request #347 from COS301-SE-2024/tests/backend/tests
Browse files Browse the repository at this point in the history
Tests/backend/tests
  • Loading branch information
waveyboym authored Aug 27, 2024
2 parents 2f3fdbf + 7b53daf commit 9bb99ad
Show file tree
Hide file tree
Showing 2 changed files with 783 additions and 21 deletions.
42 changes: 21 additions & 21 deletions occupi-backend/pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,27 @@ func AddImageIDToRoom(ctx *gin.Context, appsession *models.AppSession, roomID, i
return nil
}

func DeleteImageIDFromRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
// check if database is nil
if appsession.DB == nil {
logrus.Error("Database is nil")
return errors.New("database is nil")
}

collection := appsession.DB.Database(configs.GetMongoDBName()).Collection("Rooms")

filter := bson.M{"roomId": roomID}
update := bson.M{"$pull": bson.M{"roomImageIds": imageID}}

_, err := collection.UpdateOne(ctx, filter, update)
if err != nil {
logrus.Error(err)
return err
}

return nil
}

func CheckIfUserHasMFAEnabled(ctx *gin.Context, appsession *models.AppSession, email string) (bool, error) {
// check if database is nil
if appsession.DB == nil {
Expand Down Expand Up @@ -1477,24 +1498,3 @@ func GetAvailableSlots(ctx *gin.Context, appsession *models.AppSession, request

return slots, nil
}

func DeleteImageIDFromRoom(ctx *gin.Context, appsession *models.AppSession, roomID, imageID string) error {
// check if database is nil
if appsession.DB == nil {
logrus.Error("Database is nil")
return errors.New("database is nil")
}

collection := appsession.DB.Database(configs.GetMongoDBName()).Collection("Rooms")

filter := bson.M{"roomId": roomID}
update := bson.M{"$pull": bson.M{"roomImageIds": imageID}}

_, err := collection.UpdateOne(ctx, filter, update)
if err != nil {
logrus.Error(err)
return err
}

return nil
}
Loading

0 comments on commit 9bb99ad

Please sign in to comment.