I am working with an application using Firebase as a data store. I just reorganize my entire application to implement Clean Architecture and RxJava. Performing everything in this way, I discovered a problem with managing model objects.
Here is my problem: I have Post.class with the same fields and values ββthat I can extract from the Firebase database link:
public Post(Author author, String full_url, String full_storage_uri, String thumb_url, String thumb_storage_uri, String text, Object timestamp) { this.author = author; this.full_url = full_url; this.text = text; this.timestamp = timestamp; this.thumb_storage_uri = thumb_storage_uri; this.thumb_url = thumb_url; this.full_storage_uri = full_storage_uri; }
All perfectly. My problem arises when I retrieve data from my observer in my repository class:
@Override public Observable<List<Post>> getPosts(final String groupId){ return Observable.fromAsync(new Action1<AsyncEmitter<List<Post>>>() { @Override public void call(final AsyncEmitter<List<Post>> listAsyncEmitter) { final ValueEventListener PostListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { final List<Post> postList = new ArrayList<>(); Log.e("Count ", "" + snapshot.getChildrenCount());
With this observer, I already manage all the listeners and data calls, my only problem is the following lines:
//Set the databaseReference to the object, which is needed later post.setRef(postSnapshot.getKey());
I think it is not a good practice to set the link as a new field in the Post model, which should match my Json Tree base. So my question is: is it good practice to create two different models? One is like "dbPost" and "PostEntity". One with firebase values ββand the other with a builder from dbPost and new fields that I want to save (dbReference and possibly a Listener value)?
Hope someone can give me a hand! I am trying to improve as much as possible in architecture and best practices to create better and more flexible applications, so I ask such questions!
Have a nice day!