Room Dao返回类型和Retrofit api返回类型不同(存储库模式需要相同的返回类型)

时间:2018-07-06 18:06:12

标签: android rx-java retrofit repository-pattern android-room

API响应:

{
 "items": [
  {
   "id": "abcd",
   "sku": "2134",
   "name": "Blue Jeans",
   "price": {
    "current": 4.99,
    "original": 7.99,
    "currency": "EUR"
   },
   "brand": "Reebok",
   "image": "www.google.com",
   "published_at": "2015-09-22 17:43:12",
   "is_active": true
  },
  {
   "id": "efgh",
   "sku": "123",
   "name": "Black Jeans",
   "price": {
    "current": 6.99,
    "original": 8.99,
    "currency": "EUR"
   },
   "brand": "Nike",
   "image": "www.google.com",
   "published_at": "2015-09-02 10:35:07",
   "is_active": true
  }
 ]
}

房间Dao:

@Dao
interface ProductsDao {

    @Query("SELECT * FROM product")
    fun queryProducts(): Single<List<Product>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertProduct(product: Product)

}

API方法:

@GET()
fun getProducts(@Url format: String): Observable<ProductsResponse>

ProductsResponse类:

data class ProductsResponse(
        val items: List<Product>
)

现在,当我尝试为离线优先应用程序实现存储库模式时,我需要会议室数据库和API返回相同类型的数据。我该怎么办?

0 个答案:

没有答案