Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1.  
  2. /**********************************************
  3. * EMBER MODELS
  4. ***********************************************/
  5.  
  6. //Account model.
  7. export default DS.Model.extend({
  8. email: DS.String('string')
  9. policy: DS.belongsTo('policy') // one-to-one rel. with Policy model.
  10. roles: DS.hasMany('role') // one-to-many rel. with Role model.
  11. });
  12.  
  13. // Role model.
  14. export default DS.Model.extend({
  15. roleName: DS.attr('string')
  16. });
  17.  
  18. // Policy model.
  19. export default DS.Model.extend({
  20. policyNumber: DS.attr('string')
  21. });
  22.  
  23. /**********************************************
  24. * REST OPERATIONS
  25. ***********************************************/
  26. 1. GET /accounts //Get all
  27.  
  28. Response:
  29.  
  30. {
  31. accounts: [
  32. {
  33. id: 1 // primary key is always called id
  34. email: 'test@gmail.com'
  35. policy: 1 // policy foreign key
  36. roles: [1] // role foreign keys
  37. },
  38. {
  39. id: 1
  40. accountName: 'test2'
  41. policy: 2
  42. roles: [1,2]
  43. }
  44. ],
  45.  
  46. //Sideloading relationship [Optional]
  47.  
  48. roles: [
  49. {
  50. id: 1
  51. roleName: 'superAdmin'
  52. },
  53. {
  54. id: 2
  55. roleName: 'admin'
  56. }
  57. ],
  58.  
  59. policy: {
  60. id: 1
  61. policyNumber: '9999999'
  62. }
  63. }
  64.  
  65. 2. GET /accounts/:id
  66.  
  67. Response:
  68.  
  69. {
  70. account: {
  71. id: 1 // primary key is always called id
  72. email: 'test@gmail.com'
  73. policy: 1 // policy foreign key
  74. roles: [1] // role foreign keys
  75. },
  76.  
  77. //Sideloading relationship [Optional]
  78.  
  79. roles: [
  80. {
  81. id: 1
  82. roleName: 'superAdmin'
  83. },
  84. {
  85. id: 2
  86. roleName: 'admin'
  87. }
  88. ],
  89.  
  90. policy: {
  91. id: 1
  92. policyNumber: '9999999'
  93. }
  94. }
  95.  
  96. 3. POST /accounts
  97.  
  98. Request payload:
  99.  
  100. {
  101. account: {
  102. email: 'test@gmail.com'
  103. policy: 1 // policy foreign key
  104. roles: [1] // role foreign keys
  105. }
  106. }
  107.  
  108. Response payload:
  109.  
  110. {
  111. account: {
  112. id: 1 // return the id.
  113. email: 'test@gmail.com'
  114. policy: 1 // policy foreign key
  115. roles: [1] // role foreign keys
  116. }
  117. }
  118.  
  119. 4. PUT /accounts/:id
  120.  
  121. Request payload:
  122.  
  123. {
  124. account: {
  125. id: 1
  126. email: 'test@gmail.com'
  127. policy: 1 // policy foreign key
  128. roles: [1] // role foreign keys
  129. }
  130. }
  131.  
  132. Response payload:
  133.  
  134. {
  135. account: {
  136. id: 1
  137. email: 'test@gmail.com'
  138. policy: 1 // policy foreign key
  139. roles: [1] // role foreign keys
  140. }
  141. }
  142.  
  143. /**********************************************
  144. * NOTES
  145. ***********************************************/
  146.  
  147. 1. The primary key should always be named "id"
  148. 2. Foreign key should always be named by model it reference. (Ex: Instead of user_id, should be user)
  149. 3. Sideloading is optional, if the reference model is not part of the response ember will do GET to retrieve it if required.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement