mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-07-07 13:31:00 +02:00
refactor(connector): follow CRUD for when to define functions, used map for getProjectById
This commit is contained in:
parent
2b1294c822
commit
e8888965e5
@ -6,6 +6,17 @@ internal class ProjectDatabase (driverFactory: DriverFactory) {
|
||||
private val database = Database(driverFactory.createDriver())
|
||||
private val dbQuery = database.projectQueries
|
||||
|
||||
/**
|
||||
* Inserts a project into the database
|
||||
*/
|
||||
internal fun createProject(name: String, aircraftType: String, createdUTC: String) {
|
||||
dbQuery.createProject(
|
||||
name = name,
|
||||
aircraftType = aircraftType,
|
||||
createdUTC = createdUTC,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the Projects in the database
|
||||
*/
|
||||
@ -13,6 +24,22 @@ internal class ProjectDatabase (driverFactory: DriverFactory) {
|
||||
return dbQuery.selectAllProjects(::mapProjectSelecting).executeAsList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Project from the unique ID of the Project
|
||||
* @param id Project id
|
||||
* @return [Project]
|
||||
*/
|
||||
internal fun getProjectById(id: Int): Project {
|
||||
return dbQuery.selectProjectById(id.toLong(), ::mapProjectSelecting).executeAsOne()
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the amount of entries there are for projects
|
||||
*/
|
||||
internal fun countProjects(): Long {
|
||||
return dbQuery.countProjects().executeAsOne()
|
||||
}
|
||||
|
||||
private fun mapProjectSelecting(
|
||||
id: Long,
|
||||
name: String,
|
||||
@ -28,42 +55,4 @@ internal class ProjectDatabase (driverFactory: DriverFactory) {
|
||||
modifiedUTC = modifiedUTC,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts database [Project](io.anthonyberg.connector.shared.database.Project) data class to entity [Project] class
|
||||
*/
|
||||
private fun io.anthonyberg.connector.shared.database.Project.toProject() = Project(
|
||||
id = id.toInt(),
|
||||
name = name,
|
||||
aircraftType = aircraftType,
|
||||
createdUTC = createdUTC,
|
||||
modifiedUTC = modifiedUTC,
|
||||
)
|
||||
|
||||
/**
|
||||
* Gets Project from the unique ID of the Project
|
||||
* @param id Project id
|
||||
* @return [Project]
|
||||
*/
|
||||
internal fun getProjectById(id: Int): Project {
|
||||
return dbQuery.selectProjectById(id.toLong()).executeAsOne().toProject()
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a project into the database
|
||||
*/
|
||||
internal fun createProject(name: String, aircraftType: String, createdUTC: String) {
|
||||
dbQuery.createProject(
|
||||
name = name,
|
||||
aircraftType = aircraftType,
|
||||
createdUTC = createdUTC,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the amount of entries there are for projects
|
||||
*/
|
||||
internal fun countProjects(): Long {
|
||||
return dbQuery.countProjects().executeAsOne()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user