movemeet/movemeet

View on GitHub
app/src/main/java/com/sdp/movemeet/backend/firebase/firestore/FirestoreUserManager.java

Summary

Maintainability
A
0 mins
Test Coverage
D
60%
package com.sdp.movemeet.backend.firebase.firestore;

import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.DocumentSnapshot;
import com.sdp.movemeet.backend.serialization.BackendSerializer;
import com.sdp.movemeet.models.User;
import com.sdp.movemeet.utility.ImageHandler;

/**
 * A class capable of handling User storage operations with a Firebase Firestore backend
 */
public class FirestoreUserManager extends FirestoreManager<User> {

    // The name of the Firestore collection containing Activities
    public final static String USERS_COLLECTION = "users";

    private final String collection;

    /**
     * Creates a new FirestoreManager capable of performing backend storage operations
     * on the User class.
     *
     * @param collection the Firestore collection in which to operate
     * @param serializer a BackendSerializer capable of (de)serializing Users
     */
    public FirestoreUserManager(String collection, BackendSerializer<User> serializer) {
        super(collection, serializer);
        this.collection = collection;
    }

    /**
     * Retrieve a User from the backend using their uid
     *
     * @param uid the uid of the User
     * @return a Task<DocumentSnapshot> whose result can be deserialized into a User object
     */
    public Task<DocumentSnapshot> getUserFromUid(String uid) {
        String path = USERS_COLLECTION + ImageHandler.PATH_SEPARATOR + uid;
        return super.get(path);
    }
}