commit 12/02/2026
This commit is contained in:
69
src/database/table/AdzanSetting.kt
Normal file
69
src/database/table/AdzanSetting.kt
Normal file
@@ -0,0 +1,69 @@
|
||||
package database.table
|
||||
|
||||
import codes.Somecodes.Companion.ValidLatitude
|
||||
import codes.Somecodes.Companion.ValidLongitude
|
||||
import codes.Somecodes.Companion.ValidScheduleTime
|
||||
import codes.Somecodes.Companion.ValidTimeZone
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
|
||||
data class AdzanSetting(
|
||||
val latitude: Double,
|
||||
val longitude: Double,
|
||||
val timezone: String,
|
||||
val fajar_sound: String,
|
||||
val fajar_enable : Boolean,
|
||||
val fajar_time : String,
|
||||
val dzuhur_sound: String,
|
||||
val dzuhur_enable : Boolean,
|
||||
val dzuhur_time : String,
|
||||
val ashar_sound: String,
|
||||
val ashar_enable : Boolean,
|
||||
val ashar_time : String,
|
||||
val maghrib_sound: String,
|
||||
val maghrib_enable : Boolean,
|
||||
val maghrib_time : String,
|
||||
val isya_sound: String,
|
||||
val isya_enable : Boolean,
|
||||
val isya_time : String
|
||||
) {
|
||||
companion object{
|
||||
/**
|
||||
* Create AdzanSetting from JsonNode
|
||||
* @param json JsonNode object
|
||||
* @return AdzanSetting object
|
||||
* @throws Exception if any required field is missing
|
||||
*/
|
||||
fun FromJsonNode(json: JsonNode): AdzanSetting{
|
||||
val xx = AdzanSetting(
|
||||
latitude = json.get("latitude")?.asDouble() ?: throw Exception("latitude is missing"),
|
||||
longitude = json.get("longitude")?.asDouble() ?: throw Exception("longitude is missing"),
|
||||
timezone = json.get("timezone")?.asText() ?: throw Exception("timezone is missing"),
|
||||
fajar_sound = json.get("fajar_sound")?.asText("") ?: throw Exception("fajar_sound is missing"),
|
||||
fajar_enable = json.get("fajar_enable")?.asBoolean(false) ?: throw Exception("fajar_enable is missing"),
|
||||
fajar_time = json.get("fajar_time")?.asText() ?: throw Exception("fajar_time is missing"),
|
||||
dzuhur_sound = json.get("dzuhur_sound")?.asText() ?: throw Exception("dzuhur_sound is missing"),
|
||||
dzuhur_enable = json.get("dzuhur_enable")?.asBoolean() ?: throw Exception("dzuhur_enable is missing"),
|
||||
dzuhur_time = json.get("dzuhur_time")?.asText() ?: throw Exception("dzuhur_time is missing"),
|
||||
ashar_sound = json.get("ashar_sound")?.asText() ?: throw Exception("ashar_sound is missing"),ashar_enable = json.get("ashar_enable").asBoolean(false),
|
||||
ashar_time = json.get("ashar_time")?.asText() ?: throw Exception("ashar_time is missing"),
|
||||
maghrib_sound = json.get("maghrib_sound")?.asText() ?: throw Exception("maghrib_sound is missing"),
|
||||
maghrib_enable = json.get("maghrib_enable")?.asBoolean() ?: throw Exception("maghrib_enable is missing"),
|
||||
maghrib_time = json.get("maghrib_time")?.asText() ?: throw Exception("maghrib_time is missing"),
|
||||
isya_sound = json.get("isya_sound")?.asText() ?: throw Exception("isya_sound is missing"),
|
||||
isya_enable = json.get("isya_enable")?.asBoolean() ?: throw Exception("isya_enable is missing"),
|
||||
isya_time = json.get("isya_time")?.asText() ?: throw Exception("isya_time is missing")
|
||||
)
|
||||
if (!ValidLatitude(xx.latitude)) throw Exception("Invalid latitude value")
|
||||
if (!ValidLongitude(xx.longitude)) throw Exception("Invalid longitude value")
|
||||
if (!ValidTimeZone(xx.timezone)) throw Exception("Invalid timezone value")
|
||||
if (!ValidScheduleTime(xx.fajar_time)) throw Exception("Invalid fajar_time value")
|
||||
if (!ValidScheduleTime(xx.dzuhur_time)) throw Exception("Invalid dzuhur_time value")
|
||||
if (!ValidScheduleTime(xx.ashar_time)) throw Exception("Invalid ashar_time value")
|
||||
if (!ValidScheduleTime(xx.maghrib_time)) throw Exception("Invalid maghrib_time value")
|
||||
if (!ValidScheduleTime(xx.isya_time)) throw Exception("Invalid isya_time value")
|
||||
return xx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user