mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-05 23:19:10 +00:00
Add database path --do-not-notify parameters to backend
This commit is contained in:
@@ -27,15 +27,15 @@ object JavaDatabase {
|
||||
@Volatile
|
||||
private var instance: AppDatabase? = null
|
||||
|
||||
private fun getInstance(): AppDatabase {
|
||||
private fun getInstance(path: String): AppDatabase {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: AppDatabase(
|
||||
DatabaseDriverFactory().createDriver()
|
||||
DatabaseDriverFactory(path).createDriver()
|
||||
).also { instance = it }
|
||||
}
|
||||
}
|
||||
|
||||
fun getDaoInstance(): CircularDao {
|
||||
return CircularDao(getInstance())
|
||||
fun getDaoInstance(path: String): CircularDao {
|
||||
return CircularDao(getInstance(path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,29 @@ const val CHECK_DELAY_MILLIS = 900000L
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print("Starting Circolapp Push microservice \n")
|
||||
|
||||
if (args.isEmpty()) {
|
||||
print("ERROR: Database path not specified! Please specify the database path as a parameter \n")
|
||||
return
|
||||
} else {
|
||||
print("Database path is: " + args[0] + " \n")
|
||||
}
|
||||
|
||||
var enableNotifications = true
|
||||
if (args.size >= 2 && args[1] == "--do-not-notify") {
|
||||
print("Notifications are disabled \n")
|
||||
enableNotifications = false
|
||||
}
|
||||
|
||||
print("Initializing Firebase SDK \n")
|
||||
val options = FirebaseOptions.builder()
|
||||
.setCredentials(GoogleCredentials.getApplicationDefault())
|
||||
.build()
|
||||
|
||||
FirebaseApp.initializeApp(options)
|
||||
|
||||
val serverUtils = ServerUtils()
|
||||
print("Initializing database and server interfaces \n")
|
||||
val serverUtils = ServerUtils(args[0], enableNotifications)
|
||||
|
||||
print("Microservice started! \n")
|
||||
runBlocking {
|
||||
|
||||
@@ -23,10 +23,10 @@ import net.underdesk.circolapp.shared.server.KtorFactory
|
||||
import net.underdesk.circolapp.shared.server.Server
|
||||
import net.underdesk.circolapp.shared.server.ServerAPI
|
||||
|
||||
class ServerUtils {
|
||||
class ServerUtils(databasePath: String, private val enableNotifications: Boolean = true) {
|
||||
private val serverList: MutableList<Server> = mutableListOf()
|
||||
private val ktorClient = KtorFactory().createClient()
|
||||
private val circularDao = JavaDatabase.getDaoInstance()
|
||||
private val circularDao = JavaDatabase.getDaoInstance(databasePath)
|
||||
|
||||
init {
|
||||
for (serverId in ServerAPI.Companion.Servers.values()) {
|
||||
@@ -75,14 +75,18 @@ class ServerUtils {
|
||||
|
||||
if (newCirculars.second >= 0 && newCirculars.first.isNotEmpty()) {
|
||||
for (circular in newCirculars.first) {
|
||||
PushNotificationUtils.createPushNotification(
|
||||
circular,
|
||||
ServerAPI.getServerTopic(server.serverID)
|
||||
)
|
||||
PushNotificationUtils.createPushNotificationiOS(
|
||||
circular,
|
||||
ServerAPI.getServerTopic(server.serverID)
|
||||
)
|
||||
if (enableNotifications) {
|
||||
PushNotificationUtils.createPushNotification(
|
||||
circular,
|
||||
ServerAPI.getServerTopic(server.serverID)
|
||||
)
|
||||
PushNotificationUtils.createPushNotificationiOS(
|
||||
circular,
|
||||
ServerAPI.getServerTopic(server.serverID)
|
||||
)
|
||||
} else {
|
||||
print("Skipping notification for circular ${circular.id} of school ${circular.school} \n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ package net.underdesk.circolapp.shared.data
|
||||
import com.squareup.sqldelight.db.SqlDriver
|
||||
import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver
|
||||
|
||||
actual class DatabaseDriverFactory {
|
||||
actual class DatabaseDriverFactory(private val path: String) {
|
||||
actual fun createDriver(): SqlDriver {
|
||||
return JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY + "circolapp.db")
|
||||
return JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY + path)
|
||||
.also {
|
||||
val currentVer = getVersion(it)
|
||||
if (currentVer == 0) {
|
||||
|
||||
Reference in New Issue
Block a user