in app/controllers/EditionsController.scala [529:591]
private def lookupCollection(collectionId: String) =
db.getCollections(List(GetCollectionsFilter(collectionId, None))).headOption
def feastCollectionToContainer(
frontId: String,
collectionId: String,
collectionCardId: String
) = EditEditionsAuthAction { req =>
// collectionId is the ID of the _container_ where the Feast collection card is.
// collectionCardId is the ID of the feast collection itself, which is a _card_ in terms of Fronts
lookupCollection(collectionId) match {
case None =>
NotFound
case Some(sourceContainer) =>
val result = for {
feastCollection <- getFeastCollectionContent(
sourceContainer,
collectionCardId
)
updateData <- db.addCollectionToFront(
frontId = frontId,
user = req.user,
now = OffsetDateTime.now(),
name = feastCollection.title
)
newCollection <- db
.getCollections(List(GetCollectionsFilter(updateData._2, None)))
.find(_.id == updateData._2)
.toRight(
Left(
EditionsDB
.InvariantError("Could not find created new collection")
)
)
_ = db.updateCollection(
newCollection.copy(items = feastCollection.collectionItems)
)
updatedFront <- DB localTx { implicit session =>
db.getFront(frontId)
.toRight(
EditionsDB.InvariantError(
"The front was deleted while processing"
)
)
}
} yield updatedFront
result match {
case Left(EditionsDB.NotFoundError(msg)) =>
NotFound(msg)
case Left(EditionsDB.InvariantError(msg)) =>
Conflict(msg)
case Left(err) =>
logger.error(
s"Unexpected error when converting a Feast collection into a container: $err"
)
InternalServerError("")
case Right(updatedFront) =>
val collections = toClientCollections(updatedFront)
Ok(Json.toJson(collections))
}
}