From e3ce4a4c2dacee9f88e9336d3ae09f8b5c42f979 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 7 Apr 2018 14:06:20 -0500 Subject: [PATCH] server: Rename create method to upsert on BlockDataHandler --- .../com/xsn/explorer/data/BlockDataHandler.scala | 2 +- .../data/anorm/BlockPostgresDataHandler.scala | 4 ++-- .../explorer/data/anorm/dao/BlockPostgresDAO.scala | 2 +- .../data/BlockPostgresDataHandlerSpec.scala | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/app/com/xsn/explorer/data/BlockDataHandler.scala b/server/app/com/xsn/explorer/data/BlockDataHandler.scala index 76fa7f8..3969f32 100644 --- a/server/app/com/xsn/explorer/data/BlockDataHandler.scala +++ b/server/app/com/xsn/explorer/data/BlockDataHandler.scala @@ -8,7 +8,7 @@ import scala.language.higherKinds trait BlockDataHandler[F[_]] { - def create(block: Block): F[Block] + def upsert(block: Block): F[Block] def getBy(blockhash: Blockhash): F[Block] diff --git a/server/app/com/xsn/explorer/data/anorm/BlockPostgresDataHandler.scala b/server/app/com/xsn/explorer/data/anorm/BlockPostgresDataHandler.scala index 390b262..4841b62 100644 --- a/server/app/com/xsn/explorer/data/anorm/BlockPostgresDataHandler.scala +++ b/server/app/com/xsn/explorer/data/anorm/BlockPostgresDataHandler.scala @@ -17,8 +17,8 @@ class BlockPostgresDataHandler @Inject() ( extends BlockBlockingDataHandler with AnormPostgresDataHandler { - override def create(block: Block): ApplicationResult[Block] = database.withConnection { implicit conn => - val maybe = blockPostgresDAO.create(block) + override def upsert(block: Block): ApplicationResult[Block] = database.withConnection { implicit conn => + val maybe = blockPostgresDAO.upsert(block) Or.from(maybe, One(BlockUnknownError)) } diff --git a/server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala b/server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala index 29b6f53..3cfaba4 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala @@ -9,7 +9,7 @@ import com.xsn.explorer.models.rpc.Block class BlockPostgresDAO { - def create(block: Block)(implicit conn: Connection): Option[Block] = { + def upsert(block: Block)(implicit conn: Connection): Option[Block] = { SQL( """ |INSERT INTO blocks diff --git a/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala index a2ebab5..ea9f07e 100644 --- a/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/BlockPostgresDataHandlerSpec.scala @@ -13,23 +13,23 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec { lazy val dataHandler = new BlockPostgresDataHandler(database, new BlockPostgresDAO) - "create" should { + "upsert" should { "add a new block" in { // PoS block val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - val result = dataHandler.create(block) + val result = dataHandler.upsert(block) result.isGood mustEqual true matches(block, result.get) } "override an existing block" in { val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - dataHandler.create(block) + dataHandler.upsert(block) val newBlock = BlockLoader.get("25762bf01143f7fe34912c926e0b95528b082c6323de35516de0fc321f5d8058").copy(hash = block.hash) val expected = newBlock.copy(hash = block.hash) - val result = dataHandler.create(newBlock) + val result = dataHandler.upsert(newBlock) result.isGood mustEqual true matches(expected, result.get) } @@ -39,7 +39,7 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec { "return a block" in { val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - dataHandler.create(block) + dataHandler.upsert(block) val result = dataHandler.getBy(block.hash) result.isGood mustEqual true @@ -57,7 +57,7 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec { "delete" should { "delete a block" in { val block = BlockLoader.get("1ca318b7a26ed67ca7c8c9b5069d653ba224bf86989125d1dfbb0973b7d6a5e0") - dataHandler.create(block) + dataHandler.upsert(block) val result = dataHandler.delete(block.hash) result.isGood mustEqual true @@ -80,7 +80,7 @@ class BlockPostgresDataHandlerSpec extends PostgresDataHandlerSpec { val block1 = BlockLoader.get("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7") val block2 = BlockLoader.get("000004645e2717b556682e3c642a4c6e473bf25c653ff8e8c114a3006040ffb8") - List(block1, block2, block0).foreach(dataHandler.create) + List(block1, block2, block0).foreach(dataHandler.upsert) val result = dataHandler.getLatestBlock() result.isGood mustEqual true