Reputation: 959
i have a question that needs answers.
I'm trying to implement the Repository pattern for the first time, i successfully implemented it for most parts of my project but now i don't know how to go about solving this.
Basically i need to update the picture of a user, so in my repository i have an
updatePicture(userId: Int, picture: File)
interface, everything works fine for the repository implementation and the remote data source implementation, but as you know the local data source doesn't use a file to represent the picture of a user, it uses an url string, so in the local data source the interface should be
updatePicture(userId: Int, picture: String)
but since the concept of repository makes local data source implement the same interface as remote data source i don't know how to solve this.
Thanks for the help
Upvotes: 0
Views: 1215
Reputation: 2542
Those are two distinct use cases. The methods accomplish different purposes and so should be different methods: picID = uploadPicture(picture:File) which uploads a picture and assigns it an ID, and updateUserPictureReference(userId:int, picID:int) which assigns that picture id to a user. This lets you more easily assign the same picture to multiple users (i.e. default profile pic), or revert back to a previously used pic.
BTW, I would not assign a URI directly to the user because that locks you into the current directory structure. Assign an Id and build a predictable URI at runtime using that ID. If you decide later to restructure the site because you got so successful you need to move them for performance, you can easily do so. With the URI in the DB, you would have to update appropriate data. It also makes it easier to debug since during development you can have all links point to one URL, and in production they point somewhere else.
Upvotes: 2
Reputation: 771
You could change the signature to use Uri
instead of File
:
// Instead of this:
updatePicture(userId: Int, picture: File)
// Use this:
updatePicture(userId: Int, picture: Uri)
This should work because a Uri
can represent resources from all sorts of places using different schemes. For example, you can represent a local file resource with a file://...
URI and a remote resource that can be fetched using HTTP with https://...
.
Upvotes: 0