Skip to content

Commit

Permalink
Merge pull request #32 from hmrc/BDOG-3350
Browse files Browse the repository at this point in the history
BDOG-3350: Add updateOne method for UsersRepository
  • Loading branch information
BriWak authored Jan 24, 2025
2 parents 7501835 + 0701c78 commit 04abba8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
10 changes: 10 additions & 0 deletions app/uk/gov/hmrc/usermanagement/persistence/UsersRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04abba8

Please sign in to comment.