I'm struggling to grasp a particular issue and could use some assistance.
Currently, I am working on an app in Rails utilizing Angular.js as my client-side MVC framework. One of the components I have created is a service that allows Angular to fetch images. Here's how it looks:
var ImageServices = angular.module("ImageServices", ["ngResource"]);
ImageServices.factory("Image", ["$resource",
function ($resource) {
return $resource("/images/:id.json", {}, {
"query" : { method: "GET", params: {}, isArray: true },
"update" : { method: "PUT", params: { id: "@id" } },
"remove" : { method: "DELETE" }
});
}
]);
However, this service may be too general for my needs. What I really want is a service that can provide me with all images linked to a specific user. One approach could be nesting image data within the user's information, like so:
user = {
// user attributes
blah: "blah",
//image objects
images: [
{}
]
}
Alternatively, I could write code in Rails to retrieve all images associated with a particular user using the following endpoint:
http://localhost:3000/users/1/images.json
Another possibility is creating individual services for each type of data that Angular needs.
From an architectural standpoint, I'm unsure of the best approach. Any insights on the most effective path forward would be greatly appreciated. If there isn't a definitive answer, I'm open to book recommendations on the subject. Thank you!