feat(android): Update API responses to use Contract v1 DTOs
- Update getContentCache() to use NotificationContentMapper.cacheToDTO() - Update contentCacheToJson() helper to use DTO mapper - All content cache methods now return Contract v1 format: - fetchTime (not fetchedAt) - mediaUrl (not url) - Structured fields (title, body, metadata) instead of payload string BREAKING CHANGE: API responses now use Contract v1 field names. See docs/CONTRACT_V1_BREAKING_CHANGES.md for migration guide.
This commit is contained in:
@@ -1674,17 +1674,30 @@ open class DailyNotificationPlugin : Plugin() {
|
|||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
try {
|
try {
|
||||||
val latestCache = getDatabase().contentCacheDao().getLatest()
|
val latestCache = getDatabase().contentCacheDao().getLatest()
|
||||||
val result = JSObject()
|
|
||||||
|
|
||||||
if (latestCache != null) {
|
if (latestCache != null) {
|
||||||
result.put("id", latestCache.id)
|
// Use Contract v1 DTO via mapper
|
||||||
result.put("fetchedAt", latestCache.fetchedAt)
|
val dto = com.timesafari.dailynotification.dto.NotificationContentMapper.cacheToDTO(latestCache)
|
||||||
result.put("ttlSeconds", latestCache.ttlSeconds)
|
if (dto != null) {
|
||||||
result.put("payload", String(latestCache.payload))
|
// Convert DTO to JSObject for Capacitor response (Contract v1 field names)
|
||||||
result.put("meta", latestCache.meta)
|
val result = JSObject().apply {
|
||||||
|
put("id", dto.id)
|
||||||
|
put("title", dto.title)
|
||||||
|
if (dto.body != null) put("body", dto.body)
|
||||||
|
if (dto.scheduledTime != null) put("scheduledTime", dto.scheduledTime)
|
||||||
|
put("fetchTime", dto.fetchTime) // Contract v1 field name
|
||||||
|
if (dto.mediaUrl != null) put("mediaUrl", dto.mediaUrl)
|
||||||
|
if (dto.ttlSeconds != null) put("ttlSeconds", dto.ttlSeconds)
|
||||||
|
if (dto.dedupeKey != null) put("dedupeKey", dto.dedupeKey)
|
||||||
|
if (dto.priority != null) put("priority", dto.priority)
|
||||||
|
}
|
||||||
|
call.resolve(result)
|
||||||
|
} else {
|
||||||
|
call.reject("Failed to convert cache to DTO")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
call.resolve(JSObject())
|
||||||
}
|
}
|
||||||
|
|
||||||
call.resolve(result)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Failed to get content cache", e)
|
Log.e(TAG, "Failed to get content cache", e)
|
||||||
call.reject("Content cache retrieval failed: ${e.message}")
|
call.reject("Content cache retrieval failed: ${e.message}")
|
||||||
@@ -2398,12 +2411,30 @@ open class DailyNotificationPlugin : Plugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun contentCacheToJson(cache: ContentCache): JSObject {
|
private fun contentCacheToJson(cache: ContentCache): JSObject {
|
||||||
return JSObject().apply {
|
// Use Contract v1 DTO via mapper
|
||||||
put("id", cache.id)
|
val dto = com.timesafari.dailynotification.dto.NotificationContentMapper.cacheToDTO(cache)
|
||||||
put("fetchedAt", cache.fetchedAt)
|
return if (dto != null) {
|
||||||
put("ttlSeconds", cache.ttlSeconds)
|
// Convert DTO to JSObject for Capacitor response (Contract v1 field names)
|
||||||
put("payload", String(cache.payload))
|
JSObject().apply {
|
||||||
put("meta", cache.meta)
|
put("id", dto.id)
|
||||||
|
put("title", dto.title)
|
||||||
|
if (dto.body != null) put("body", dto.body)
|
||||||
|
if (dto.scheduledTime != null) put("scheduledTime", dto.scheduledTime)
|
||||||
|
put("fetchTime", dto.fetchTime) // Contract v1 field name
|
||||||
|
if (dto.mediaUrl != null) put("mediaUrl", dto.mediaUrl)
|
||||||
|
if (dto.ttlSeconds != null) put("ttlSeconds", dto.ttlSeconds)
|
||||||
|
if (dto.dedupeKey != null) put("dedupeKey", dto.dedupeKey)
|
||||||
|
if (dto.priority != null) put("priority", dto.priority)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to old format if conversion fails
|
||||||
|
JSObject().apply {
|
||||||
|
put("id", cache.id)
|
||||||
|
put("fetchedAt", cache.fetchedAt)
|
||||||
|
put("ttlSeconds", cache.ttlSeconds)
|
||||||
|
put("payload", String(cache.payload))
|
||||||
|
put("meta", cache.meta)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user