2016-05-06 18 views
5

Ürünler, Fiyatlar ve Ücretli Ürünler'i içeren basit bir uygulamam var.Yay veriminde yansımaya kendiliğinden bağlantı ekleme

PricedProducts listesini istediğimde Fiyat ve Ürünün satır içi olmasını istiyorum. Fiyat Deposu'nu @RestResource (exported = false) ile işaretledim, bu yüzden bu işe yaradı. Bununla birlikte, ürünler kendiliğinden duran varlıklar olmalıdır (örneğin, aynı Ürünü kullanarak birkaç PricedProducts üretebilmem gerekir).

Ben PricedProduct için bir projeksiyon oluşturdu excerptProjection olarak eklenmiş ve/pricedProducts getiriler için GET: Bu ürünümü inlines

{ 
    "_embedded": { 
    "pricedProducts": [ 
     { 
     "price": { 
      "value": "100.50", 
      "currency": "EUR" 
     }, 
     "product": { 
      "name": "Poatato", 
      "description": null, 
      "pictureUrl": null 
     }, 
     "_links": { 
      "self": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1" 
      }, 
      "pricedProduct": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1{?projection}", 
      "templated": true 
      }, 
      "product": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1/product" 
      } 
     } 
     } 
    ] 
    }, 
    "_links": { 
    "self": { 
     "href": "http://localhost:4200/api/v1.0/pricedProducts" 
    }, 
    "profile": { 
     "href": "http://localhost:4200/api/v1.0/profile/pricedProducts" 
    } 
    } 
} 

, ancak bunun için bir öz bağlantısını temin etmez. Yani, benim müşteri uygulamasında, biri ürünün adını düzenlediğinde, örneğin, ekstra bir istek yapmadıkça, hangi ürünü güncellemem gerektiğini bilmiyorum.

Daha sonra yaptığım, ProductedProduct için projeksiyonda kullandığım Ürün için bir projeksiyon oluşturmaktı./PricedProducts için GET şimdi verir:

Şimdi
{ 
    "_embedded": { 
    "pricedProducts": [ 
     { 
     "price": { 
      "value": "100.50", 
      "currency": "EUR" 
     }, 
     "product": { 
      "pictureUrl": null, 
      "description": null, 
      "name": "Potato", 
      "_links": { 
      "self": { 
       "href": "http://localhost:4200/api/v1.0/products/1{?projection}", 
       "templated": true 
      } 
      } 
     }, 
     "_links": { 
      "self": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1" 
      }, 
      "pricedProduct": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1{?projection}", 
      "templated": true 
      }, 
      "product": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1/product" 
      } 
     } 
     } 
    ] 
    }, 
    "_links": { 
    "self": { 
     "href": "http://localhost:4200/api/v1.0/pricedProducts" 
    }, 
    "profile": { 
     "href": "http://localhost:4200/api/v1.0/profile/pricedProducts" 
    } 
    } 
} 

benim Ürün kendinden bağlantı vardır, ama onun projeksiyon işaret (http://localhost:4200/api/v1.0/products/1 {projeksiyon?}). Ne istiyorum:

{ 
    "_embedded": { 
    "pricedProducts": [ 
     { 
     "price": { 
      "value": "100.50", 
      "currency": "RON" 
     }, 
     "product": { 
      "pictureUrl": null, 
      "description": null, 
      "name": "Potato", 
      "_links": { 
      "self": { 
       "href": "http://localhost:4200/api/v1.0/products/1 
      } 
      } 
     }, 
     "_links": { 
      "self": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1" 
      }, 
      "pricedProduct": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1{?projection}", 
      "templated": true 
      }, 
      "product": { 
      "href": "http://localhost:4200/api/v1.0/pricedProducts/1/product" 
      } 
     } 
     } 
    ] 
    }, 
    "_links": { 
    "self": { 
     "href": "http://localhost:4200/api/v1.0/pricedProducts" 
    }, 
    "profile": { 
     "href": "http://localhost:4200/api/v1.0/profile/pricedProducts" 
    } 
    } 
} 

Teşekkürler!

+0

Bunun için bir çözüm buldunuz mu? –

cevap

0

Yapılması gereken en basit ve doğru olan şey, bir çocuk projeksiyonu kullanmak ve istemci tarafında öz bağlantıyı ayrıştırmaktır.

İlgili konular