-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseRead.kt
More file actions
45 lines (38 loc) · 1.45 KB
/
DatabaseRead.kt
File metadata and controls
45 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
object DatabaseRead {
fun group(groupId: String): Observable<Group?> {
return DatabaseQuery().apply { path = "groups/$groupId" }
.observe()
.toObjectObservable(Group::class.java)
}
fun user(userId: String?): Observable<User?> {
return DatabaseQuery().apply { path = "users/$userId" }
.observe()
.toObjectObservable(User::class.java)
}
fun permissions(groupId: String): Observable<List<Permission>?> {
return DatabaseQuery().apply { path = "permissions/$groupId" }
.observe()
.toListObservable(Permission::class.java)
}
fun groupLinkEnabled(groupId: String): Observable<Boolean?> {
return DatabaseQuery().apply { path = "groups/$groupId/inviteLinkActive" }
.observe()
.toPrimitiveObservable(Boolean::class.java)
}
fun groupColor(groupId: String): Observable<String?> {
return DatabaseQuery().apply { path = "userGroups/${Auth.getUserId()}/$groupId/color" }
.observe()
.toPrimitiveObservable(String::class.java)
}
}
class DatabaseQuery {
lateinit var path: String
var orderByChild: String? = null
fun build(): Query {
var query: Query = Database.get().reference.child(path)
if (orderByChild != null) {
query = query.orderByChild(orderByChild)
}
return query
}
}