in app/services/editions/db/IssueQueries.scala [23:111]
def insertIssue(
edition: Edition,
issueSkeleton: EditionsIssueSkeleton,
user: User,
now: OffsetDateTime
): String = DB localTx { implicit session =>
val truncatedNow = EditionsDB.truncateDateTime(now)
val userName = EditionsDB.getUserName(user)
val issueId =
sql"""
INSERT INTO edition_issues (
name,
issue_date,
timezone_id,
created_on,
created_by,
created_email
) VALUES (${edition.entryName}, ${issueSkeleton.issueDate}, ${issueSkeleton.zoneId.toString}, $truncatedNow, $userName, ${user.email})
RETURNING id;
""".map(_.string("id")).single.apply().get
issueSkeleton.fronts.zipWithIndex.foreach { case (front, fIndex) =>
val frontId =
sql"""
INSERT INTO fronts (
issue_id,
index,
name,
is_hidden,
metadata,
is_special
) VALUES ($issueId, $fIndex, ${front.name}, ${front.hidden}, ${front
.metadata()}, ${front.isSpecial})
RETURNING id;
""".map(_.string("id")).single.apply().get
front.collections.zipWithIndex.foreach { case (collection, cIndex) =>
val collectionId =
sql"""
INSERT INTO collections (
front_id,
index,
name,
is_hidden,
metadata,
prefill,
path_type,
content_prefill_window_start,
content_prefill_window_end,
updated_on,
updated_by,
updated_email
) VALUES (
$frontId
, $cIndex
, ${collection.name}
, ${collection.hidden}
, NULL
, ${collection.prefill.map(_.queryString)}
, ${collection.prefill.map(_.pathType.entryName)}
, ${collection.capiQueryTimeWindow.fromDate}
, ${collection.capiQueryTimeWindow.toDate}
, $truncatedNow
, $userName
, ${user.email}
)
RETURNING id;
""".map(_.string("id")).single.apply().get
collection.items.zipWithIndex.foreach { case (card, tIndex) =>
sql"""
INSERT INTO cards (
collection_id,
id,
card_type,
index,
added_on,
metadata
) VALUES ($collectionId, ${card.id}, ${card.cardType.entryName}, $tIndex, $truncatedNow, ${card.metadata
.map(Json.toJson(_).toString)
.getOrElse("{}")}::JSONB)
""".execute.apply()
}
}
}
issueId
}