Skip to content

Commit

Permalink
Merge pull request #706 from nationalarchives/add_series_name
Browse files Browse the repository at this point in the history
Add seriesName too if user passed a seriesId while calling addConsignment
  • Loading branch information
vimleshtna authored Oct 11, 2023
2 parents 7606052 + 83b9d77 commit 6ff23de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ConsignmentService(
for {
sequence <- consignmentRepository.getNextConsignmentSequence
body <- transferringBodyService.getBodyByCode(userBody)
seriesName <- getSeriesName(seriesId)
consignmentRef = ConsignmentReference.createConsignmentReference(yearNow, sequence)
consignmentId = uuidSource.uuid
consignmentRow = ConsignmentRow(
Expand All @@ -84,7 +85,7 @@ class ConsignmentService(
consignmentreference = consignmentRef,
consignmenttype = consignmentType,
bodyid = body.bodyId,
seriesname = None,
seriesname = seriesName,
transferringbodyname = Some(body.name)
)
descriptiveMetadataStatusRow = ConsignmentstatusRow(uuidSource.uuid, consignmentId, DescriptiveMetadata, NotEntered, timestampNow, Option(timestampNow))
Expand Down Expand Up @@ -123,8 +124,8 @@ class ConsignmentService(

def updateSeriesOfConsignment(updateConsignmentSeriesIdInput: UpdateConsignmentSeriesIdInput): Future[Int] = {
for {
series <- seriesRepository.getSeries(updateConsignmentSeriesIdInput.seriesId)
result <- consignmentRepository.updateSeriesOfConsignment(updateConsignmentSeriesIdInput, series.headOption.map(_.name))
seriesName <- getSeriesName(Some(updateConsignmentSeriesIdInput.seriesId))
result <- consignmentRepository.updateSeriesOfConsignment(updateConsignmentSeriesIdInput, seriesName)
seriesStatus = if (result == 1) Completed else Failed
_ <- consignmentStatusRepository.updateConsignmentStatus(updateConsignmentSeriesIdInput.consignmentId, "Series", seriesStatus, Timestamp.from(timeSource.now))
} yield result
Expand Down Expand Up @@ -172,6 +173,14 @@ class ConsignmentService(
.map(cr => convertRowToConsignment(cr))
.map(c => ConsignmentEdge(c, c.consignmentReference))
}

private def getSeriesName(seriesId: Option[UUID]): Future[Option[String]] = {
if (seriesId.isDefined) {
seriesRepository.getSeries(seriesId.get).map(_.headOption.map(_.name))
} else {
Future(None)
}
}
}

case class PaginatedConsignments(lastCursor: Option[String], consignmentEdges: Seq[ConsignmentEdge])
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ConsignmentServiceSpec extends AnyFlatSpec with MockitoSugar with ResetMoc
consignmentreference = consignmentReference,
consignmenttype = "standard",
bodyid = bodyId,
seriesname = None,
seriesname = Some(seriesName),
transferringbodyname = Some(bodyName)
)

Expand Down Expand Up @@ -93,12 +93,14 @@ class ConsignmentServiceSpec extends AnyFlatSpec with MockitoSugar with ResetMoc

val result = consignmentService.addConsignment(AddConsignmentInput(Some(seriesId), "standard"), mockToken).futureValue

verify(seriesRepositoryMock).getSeries(seriesId)

result.consignmentid shouldBe consignmentId
result.seriesid shouldBe Some(seriesId)
result.userid shouldBe userId
result.consignmentType shouldBe "standard"
result.bodyId shouldBe bodyId
result.seriesName shouldBe None
result.seriesName shouldBe Some(seriesName)
result.transferringBodyName shouldBe Some(bodyName)
}

Expand Down Expand Up @@ -136,6 +138,7 @@ class ConsignmentServiceSpec extends AnyFlatSpec with MockitoSugar with ResetMoc
val mockToken = mock[Token]
val mockBody = mock[TransferringBody]
val consignmentStatusRow = mock[ConsignmentstatusRow]
when(seriesRepositoryMock.getSeries(seriesId)).thenReturn(Future.successful(Seq(mockSeries)))
when(consignmentStatusRepoMock.addConsignmentStatuses(any[Seq[ConsignmentstatusRow]])).thenReturn(Future.successful(Seq(consignmentStatusRow)))
when(consignmentRepoMock.getNextConsignmentSequence).thenReturn(Future.successful(consignmentSequence))
when(consignmentRepoMock.addConsignment(any[ConsignmentRow])).thenReturn(mockResponse)
Expand Down

0 comments on commit 6ff23de

Please sign in to comment.