From 0701c781ff20d4371aed6e6ce6445a38422bf178 Mon Sep 17 00:00:00 2001 From: Brian Wakenshaw <36340167+BriWak@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:07:23 +0000 Subject: [PATCH] BDOG-3350: Add updateOne method for UsersRepository --- .../controllers/UserManagementController.scala | 2 +- .../usermanagement/persistence/UsersRepository.scala | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/uk/gov/hmrc/usermanagement/controllers/UserManagementController.scala b/app/uk/gov/hmrc/usermanagement/controllers/UserManagementController.scala index 6cb491f..d7417c6 100644 --- a/app/uk/gov/hmrc/usermanagement/controllers/UserManagementController.scala +++ b/app/uk/gov/hmrc/usermanagement/controllers/UserManagementController.scala @@ -94,7 +94,7 @@ class UserManagementController @Inject()( case UserAttribute.Github => existingUser.copy(githubUsername = Some(editRequest.value)) case UserAttribute.Organisation => existingUser.copy(organisation = Some(editRequest.value)) case UserAttribute.PhoneNumber => existingUser.copy(phoneNumber = Some(editRequest.value)) - usersRepository.putAll(Seq(updatedUser)).map(_ => Accepted) + usersRepository.updateOne(updatedUser).map(_ => Accepted) case None => umpConnector.editUserDetails(editRequest).map:_ => logger.info(s"Updated successfully on UMP but username '${editRequest.username}' not found in mongo. Awaiting scheduler for mongo update.") diff --git a/app/uk/gov/hmrc/usermanagement/persistence/UsersRepository.scala b/app/uk/gov/hmrc/usermanagement/persistence/UsersRepository.scala index 9613336..806ca25 100644 --- a/app/uk/gov/hmrc/usermanagement/persistence/UsersRepository.scala +++ b/app/uk/gov/hmrc/usermanagement/persistence/UsersRepository.scala @@ -68,6 +68,16 @@ class UsersRepository @Inject()( else collection.bulkWrite(bulkUpdates).toFuture().map(_=> ()) yield () + def updateOne(user: User): Future[Unit] = + collection + .replaceOne( + filter = Filters.equal("username" , user.username), + replacement = user, + options = ReplaceOptions().upsert(true) + ) + .toFuture() + .map(_ => ()) + def find( team : Option[String] = None, github: Option[String] = None