Skip to content

Commit

Permalink
Use delete and return nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseydew committed Mar 27, 2024
1 parent 3f60e48 commit 8cb7715
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import org.scanamo.syntax._
import com.gu.sfl.Logging
import com.gu.sfl.persistence.{DynamoSavedArticles, PersistenceConfig}
import com.gu.sfl.userdeletion.model.UserDeleteMessage
import org.scanamo.DeleteReturn.OldValue
import org.scanamo.DeleteReturn.Nothing
import org.scanamo.generic.auto.genericDerivedFormat
import software.amazon.awssdk.services.dynamodb.DynamoDbClient


class SflDynamoDb(persistanceConfig: PersistenceConfig) extends Logging {

private val table = Table[DynamoSavedArticles](persistanceConfig.tableName)
private val client = DynamoDbClient.create()
private val scanamo = Scanamo(client)
def deleteSavedArticleasForUser(user: UserDeleteMessage) = {
logger.info(s"Deleting record for user id: ${user.userId}")
val dbResponse = scanamo.exec(table.deleteAndReturn(OldValue)("userId" === user.userId))
val dbResponse = scanamo.exec(table.deleteAndReturn(Nothing)("userId" === user.userId))
.fold(s"Unable to delete record for user ${user.userId}")((_) => s"Deleted record for ${user.userId}")
logger.info(dbResponse)
}
Expand Down

0 comments on commit 8cb7715

Please sign in to comment.