Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wangerekaharun committed Nov 25, 2019
2 parents dc81d22 + 6bbe7f8 commit 2338420
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 95 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import kotlinx.coroutines.withContext

suspend fun <T, R : Any> T.runCatching(
block: suspend T.() -> R
): Result<R> = withContext(Dispatchers.IO) {
): FirebaseResult<R> = withContext(Dispatchers.IO) {
return@withContext try {
Result.Success(block())
FirebaseResult.Success(block())
} catch (e: Exception) {
Result.Error(e.message)
FirebaseResult.Error(e.message)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.AboutDetailsModel
import com.android254.droidconke19.utils.await
Expand All @@ -9,13 +9,13 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.ktx.toObjects

interface AboutDetailsRepo {
suspend fun getAboutDetails(aboutType: String): Result<List<AboutDetailsModel>>
suspend fun getAboutDetails(aboutType: String): FirebaseResult<List<AboutDetailsModel>>
}


class AboutDetailsRepoImpl(val firestore: FirebaseFirestore) : AboutDetailsRepo {

override suspend fun getAboutDetails(aboutType: String): Result<List<AboutDetailsModel>> =
override suspend fun getAboutDetails(aboutType: String): FirebaseResult<List<AboutDetailsModel>> =
runCatching {
val snapshot = firestore.collection(aboutType)
.orderBy("id", Query.Direction.ASCENDING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.AgendaModel
import com.android254.droidconke19.utils.await
Expand All @@ -9,12 +9,12 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.ktx.toObjects

interface AgendaRepo {
suspend fun agendaData(): Result<List<AgendaModel>>
suspend fun agendaData(): FirebaseResult<List<AgendaModel>>
}

class AgendaRepoImpl(val firestore: FirebaseFirestore) : AgendaRepo {

override suspend fun agendaData(): Result<List<AgendaModel>> =
override suspend fun agendaData(): FirebaseResult<List<AgendaModel>> =
runCatching {
val snapshot = firestore
.collection("agenda_2019")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.Announcement
import com.android254.droidconke19.utils.await
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.toObjects

interface AnnouncementRepo {
suspend fun getAnnouncements(): Result<List<Announcement>>
suspend fun getAnnouncements(): FirebaseResult<List<Announcement>>
}

class AnnouncementRepoImpl(val firestore: FirebaseFirestore) : AnnouncementRepo {

override suspend fun getAnnouncements(): Result<List<Announcement>> =
override suspend fun getAnnouncements(): FirebaseResult<List<Announcement>> =
runCatching {
val snapshot = firestore.collection("announcements").get().await()
snapshot.toObjects<Announcement>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.UserEventFeedback
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await

interface EventFeedbackRepo {
suspend fun sendFeedBack(userEventFeedback: UserEventFeedback): Result<String>
suspend fun sendFeedBack(userEventFeedback: UserEventFeedback): FirebaseResult<String>
}

class EventFeedbackRepoImpl(val firestore: FirebaseFirestore) : EventFeedbackRepo {

override suspend fun sendFeedBack(userEventFeedback: UserEventFeedback): Result<String> =
override suspend fun sendFeedBack(userEventFeedback: UserEventFeedback): FirebaseResult<String> =
runCatching {
firestore.collection("event_feedback_2019").add(userEventFeedback).await()
"Thank you for your feedback"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.EventTypeModel
import com.android254.droidconke19.utils.await
Expand All @@ -9,12 +9,12 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.ktx.toObjects

interface EventTypeRepo {
suspend fun getSessionData(): Result<List<EventTypeModel>>
suspend fun getSessionData(): FirebaseResult<List<EventTypeModel>>
}

class EventTypeRepoImpl(val firestore: FirebaseFirestore) : EventTypeRepo {

override suspend fun getSessionData(): Result<List<EventTypeModel>> =
override suspend fun getSessionData(): FirebaseResult<List<EventTypeModel>> =
runCatching {
val snapshots = firestore.collection("event_types")
.orderBy("id", Query.Direction.ASCENDING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.models.ReserveSeatModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreException
import kotlinx.coroutines.tasks.await
import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching

interface ReserveSeatRepo {
suspend fun reserveSeat(reserveSeatModel: ReserveSeatModel): Result<String>
suspend fun reserveSeat(reserveSeatModel: ReserveSeatModel): FirebaseResult<String>

suspend fun unReserveSeat(reserveSeatModel: ReserveSeatModel): Result<String>
suspend fun unReserveSeat(reserveSeatModel: ReserveSeatModel): FirebaseResult<String>
}

class ReserveSeatRepoImpl(val firestore: FirebaseFirestore) : ReserveSeatRepo {


override suspend fun reserveSeat(reserveSeatModel: ReserveSeatModel): Result<String> {
override suspend fun reserveSeat(reserveSeatModel: ReserveSeatModel): FirebaseResult<String> {
return if (!isSeatReserved(reserveSeatModel)) {
runCatching {
firestore.collection("reserved_seats").add(reserveSeatModel).await()
"Seat successfully reserved"
}
} else {
return Result.Error("Seat already reserved")
return FirebaseResult.Error("Seat already reserved")
}
}

Expand All @@ -43,7 +42,7 @@ class ReserveSeatRepoImpl(val firestore: FirebaseFirestore) : ReserveSeatRepo {
}


override suspend fun unReserveSeat(reserveSeatModel: ReserveSeatModel): Result<String> {
override suspend fun unReserveSeat(reserveSeatModel: ReserveSeatModel): FirebaseResult<String> {
return runCatching {
val snapshot = firestore.collection("reserved_seats")
.whereEqualTo("day_number", reserveSeatModel.day_number)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.RoomModel
import com.android254.droidconke19.utils.await
import com.google.firebase.firestore.FirebaseFirestore

interface RoomRepo {
suspend fun getRoomDetails(roomId: Int): Result<RoomModel>
suspend fun getRoomDetails(roomId: Int): FirebaseResult<RoomModel>
}

class RoomRepoImpl(private val firestore: FirebaseFirestore) : RoomRepo {

override suspend fun getRoomDetails(roomId: Int): Result<RoomModel> {
override suspend fun getRoomDetails(roomId: Int): FirebaseResult<RoomModel> {
return runCatching {
val snapshot = firestore.collection("rooms")
.whereEqualTo("id", roomId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package com.android254.droidconke19.repository

import com.android254.droidconke19.database.AppDatabase
import com.android254.droidconke19.database.dao.SessionsDao
import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.SessionsModel
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreException
import kotlinx.coroutines.tasks.await

interface SessionDataRepo {
suspend fun getSessionData(dayNumber: String, sessionId: Int): Result<SessionsModel>
suspend fun getSessionData(dayNumber: String, sessionId: Int): FirebaseResult<SessionsModel>

suspend fun getStarredSessions(userId: String): Result<List<String>>
suspend fun getStarredSessions(userId: String): FirebaseResult<List<String>>

suspend fun starrSession(dayNumber: String, sessionId: Int, userId: String, slug: String): Result<String>
suspend fun starrSession(dayNumber: String, sessionId: Int, userId: String, slug: String): FirebaseResult<String>

suspend fun unstarrSession(dayNumber: String, sessionId: Int, userId: String): Result<String>
suspend fun unstarrSession(dayNumber: String, sessionId: Int, userId: String): FirebaseResult<String>

suspend fun clearStarredSessions(userId: String)
}
Expand All @@ -26,7 +26,7 @@ class SessionDataRepoImpl(db: AppDatabase, private val firestore: FirebaseFirest

private val starredSessionCollection = "starred_sessions"

override suspend fun getSessionData(dayNumber: String, sessionId: Int): Result<SessionsModel> =
override suspend fun getSessionData(dayNumber: String, sessionId: Int): FirebaseResult<SessionsModel> =
runCatching {
val snapshot = firestore.collection(dayNumber)
.whereEqualTo("id", sessionId)
Expand All @@ -53,7 +53,7 @@ class SessionDataRepoImpl(db: AppDatabase, private val firestore: FirebaseFirest
}
}

override suspend fun getStarredSessions(userId: String): Result<List<String>> =
override suspend fun getStarredSessions(userId: String): FirebaseResult<List<String>> =
runCatching {
val snapshot = firestore.collection(starredSessionCollection)
.whereEqualTo("user_id", userId)
Expand All @@ -77,7 +77,7 @@ class SessionDataRepoImpl(db: AppDatabase, private val firestore: FirebaseFirest
slugs
}

override suspend fun starrSession(dayNumber: String, sessionId: Int, userId: String, slug: String): Result<String> {
override suspend fun starrSession(dayNumber: String, sessionId: Int, userId: String, slug: String): FirebaseResult<String> {
return if(!isSessionStarred(dayNumber, sessionId, userId)) {
runCatching {
val data = hashMapOf(
Expand All @@ -93,11 +93,11 @@ class SessionDataRepoImpl(db: AppDatabase, private val firestore: FirebaseFirest
"Session added to favourites"
}
} else {
Result.Error("Session already starred")
FirebaseResult.Error("Session already starred")
}
}

override suspend fun unstarrSession(dayNumber: String, sessionId: Int, userId: String): Result<String> =
override suspend fun unstarrSession(dayNumber: String, sessionId: Int, userId: String): FirebaseResult<String> =
runCatching {
val snapshot = firestore.collection(starredSessionCollection)
.whereEqualTo("day", dayNumber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.SessionsUserFeedback
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await

interface SessionFeedbackRepo {
suspend fun sendFeedBack(userSessionFeedback: SessionsUserFeedback): Result<String>
suspend fun sendFeedBack(userSessionFeedback: SessionsUserFeedback): FirebaseResult<String>
}

class SessionFeedbackRepoImpl(private val firestore: FirebaseFirestore) : SessionFeedbackRepo {

override suspend fun sendFeedBack(userSessionFeedback: SessionsUserFeedback): Result<String> =
override suspend fun sendFeedBack(userSessionFeedback: SessionsUserFeedback): FirebaseResult<String> =
runCatching {
firestore.collection("session_feedback_2019")
.add(userSessionFeedback)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.database.AppDatabase
import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.SessionsModel
import com.android254.droidconke19.models.SpeakersModel
Expand All @@ -11,12 +11,12 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.ktx.toObjects

interface SessionsRepo {
suspend fun getSessions(sessionDay: String): Result<List<SessionsModel>>
suspend fun getSessions(sessionDay: String): FirebaseResult<List<SessionsModel>>
}

class SessionsRepoImpl(db: AppDatabase, private val firestore: FirebaseFirestore) : SessionsRepo {

override suspend fun getSessions(sessionDay: String): Result<List<SessionsModel>> =
override suspend fun getSessions(sessionDay: String): FirebaseResult<List<SessionsModel>> =
runCatching {
val snapshots = firestore.collection(sessionDay)
.orderBy("id", Query.Direction.ASCENDING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.android254.droidconke19.models.SpeakersModel
import com.android254.droidconke19.utils.await
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.toObjects

interface SpeakersRepo {
suspend fun getSpeakersInfo(speakerId: Int): Result<List<SpeakersModel>>
suspend fun getSpeakersInfo(speakerId: Int): FirebaseResult<List<SpeakersModel>>
}

class SpeakersRepoImpl(private val firestore: FirebaseFirestore) : SpeakersRepo {

override suspend fun getSpeakersInfo(speakerId: Int): Result<List<SpeakersModel>> =
override suspend fun getSpeakersInfo(speakerId: Int): FirebaseResult<List<SpeakersModel>> =
runCatching {
val snapshot = firestore.collection("speakers2019")
.whereEqualTo("id", speakerId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.android254.droidconke19.repository

import com.android254.droidconke19.datastates.Result
import com.android254.droidconke19.datastates.FirebaseResult
import com.android254.droidconke19.datastates.runCatching
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.coroutines.tasks.await

interface UpdateTokenRepo {
suspend fun updateToken(userId: String, refreshToken: String): Result<Boolean>
suspend fun updateToken(userId: String, refreshToken: String): FirebaseResult<Boolean>
}

class UpdateTokenRepoImpl(val firestore: FirebaseFirestore) : UpdateTokenRepo {

override suspend fun updateToken(userId: String, refreshToken: String): Result<Boolean> =
override suspend fun updateToken(userId: String, refreshToken: String): FirebaseResult<Boolean> =
runCatching {
firestore.collection("users")
.document(userId)
Expand Down
Loading

0 comments on commit 2338420

Please sign in to comment.