Skip to content

Commit

Permalink
Originals: Move to generated DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Aug 2, 2024
1 parent 561e2db commit 018b237
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 137 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
api/app/db/OriginalsDao.scala: private val parser: anorm.RowParser[InternalOriginal] = {

"org.webjars" % "bootstrap" % "3.4.1",
webjars

Expand Down
50 changes: 50 additions & 0 deletions api/app/db/InternalOriginalsDao.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package db

import db.generated.OriginalsDao
import io.apibuilder.api.v0.models.{Original, OriginalType}

import java.util.UUID
import javax.inject.Inject

case class InternalOriginal(db: generated.Original) {
val id: Long = db.id
val versionGuid: UUID = db.versionGuid
val `type`: OriginalType = OriginalType(db.`type`)
val data: String = db.data
}

class InternalOriginalsDao @Inject()(dao: OriginalsDao) {

def create(
implicit c: java.sql.Connection,
user: InternalUser,
versionGuid: UUID,
original: Original
): Unit = {
dao.insert(c, user.guid, generated.OriginalForm(
versionGuid = versionGuid,
`type` = original.`type`.toString,
data = original.data,
))
}

def softDeleteByVersionGuid(
implicit c: java.sql.Connection,
user: InternalUser,
versionGuid: UUID
): Unit = {
dao.deleteAllByVersionGuid(c, user.guid, versionGuid)
}

def findAllByVersionGuids(versionGuids: Seq[UUID]): Seq[InternalOriginal] = {
dao.findAll(
versionGuids = Some(versionGuids),
limit = None,
) { q => q.isNull("deleted_at") }.map(InternalOriginal(_))
}

def findByVersionGuid(guid: UUID): Option[InternalOriginal] = {
findAllByVersionGuids(Seq(guid)).headOption
}

}
16 changes: 8 additions & 8 deletions api/app/db/InternalVersionsDao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ case class InternalVersion(db: generated.Version) {
}

class InternalVersionsDao @Inject()(
dao: VersionsDao,
applicationsDao: InternalApplicationsDao,
originalsDao: OriginalsDao,
tasksDao: InternalTasksDao,
usersDao: InternalUsersDao,
organizationsDao: InternalOrganizationsDao,
versionsModel: VersionsModel,
servicesDao: ServicesDao
dao: VersionsDao,
applicationsDao: InternalApplicationsDao,
originalsDao: InternalOriginalsDao,
tasksDao: InternalTasksDao,
usersDao: InternalUsersDao,
organizationsDao: InternalOrganizationsDao,
versionsModel: VersionsModel,
servicesDao: ServicesDao
) extends ValidatedHelpers {

private val logger: Logger = Logger(this.getClass)
Expand Down
84 changes: 0 additions & 84 deletions api/app/db/OriginalsDao.scala

This file was deleted.

4 changes: 2 additions & 2 deletions api/app/models/VersionsModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import builder.api_json.upgrades.ServiceParser
import cats.data.Validated.{Invalid, Valid}
import cats.data.ValidatedNec
import cats.implicits.*
import db.{Authorization, InternalApplicationsDao, InternalOrganizationsDao, InternalVersion, OriginalsDao}
import db.{Authorization, InternalApplicationsDao, InternalOrganizationsDao, InternalVersion, InternalOriginalsDao}
import db.generated.cache.ServicesDao
import io.apibuilder.api.v0.models.Version
import io.apibuilder.common.v0.models.{Audit, Reference, ReferenceGuid}
Expand All @@ -17,7 +17,7 @@ import javax.inject.Inject
class VersionsModel @Inject()(
applicationsDao: InternalApplicationsDao,
organizationsDao: InternalOrganizationsDao,
originalsDao: OriginalsDao,
originalsDao: InternalOriginalsDao,
serviceParser: ServiceParser,
servicesDao: ServicesDao,
originalsModel: OriginalsModel
Expand Down
2 changes: 1 addition & 1 deletion api/test/util/Daos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait Daos {
def organizationDomainsDao: InternalOrganizationDomainsDao = injector.instanceOf[db.InternalOrganizationDomainsDao]
def organizationLogsDao: OrganizationLogsDao = injector.instanceOf[db.OrganizationLogsDao]
def organizationsDao: InternalOrganizationsDao = injector.instanceOf[db.InternalOrganizationsDao]
def originalsDao: OriginalsDao = injector.instanceOf[db.OriginalsDao]
def originalsDao: InternalOriginalsDao = injector.instanceOf[db.InternalOriginalsDao]
def passwordResetsDao: InternalPasswordResetsDao = injector.instanceOf[db.InternalPasswordResetsDao]
def sessionsDao: SessionsDao = injector.instanceOf[SessionsDao]

Expand Down
3 changes: 1 addition & 2 deletions dao/spec/psql-apibuilder-generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"package": "db.generated.generators",
"user_class": "java.util.UUID",
"pkey_generator": {
"method": "java.util.UUID.randomUUID",
"returns": "uuid"
"method": "java.util.UUID.randomUUID"
}
}
},
Expand Down
Loading

0 comments on commit 018b237

Please sign in to comment.