diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/api/Api.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/api/Api.kt index 61da889..d764200 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/api/Api.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/api/Api.kt @@ -3,13 +3,13 @@ package tj.rsdevteam.inmuslim.data.api import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST -import tj.rsdevteam.inmuslim.data.models.network.GetRegionsResponse -import tj.rsdevteam.inmuslim.data.models.network.GetTimingBody -import tj.rsdevteam.inmuslim.data.models.network.GetTimingResponse -import tj.rsdevteam.inmuslim.data.models.network.RegisterUserBody -import tj.rsdevteam.inmuslim.data.models.network.RegisterUserResponse -import tj.rsdevteam.inmuslim.data.models.network.UpdateMessagingIdBody -import tj.rsdevteam.inmuslim.data.models.network.UpdateMessagingIdResponse +import tj.rsdevteam.inmuslim.data.models.api.GetRegionsDTO +import tj.rsdevteam.inmuslim.data.models.api.GetTimingBodyDTO +import tj.rsdevteam.inmuslim.data.models.api.GetTimingDTO +import tj.rsdevteam.inmuslim.data.models.api.RegisterUserBodyDTO +import tj.rsdevteam.inmuslim.data.models.api.RegisterUserDTO +import tj.rsdevteam.inmuslim.data.models.api.UpdateMessagingIdBodyDTO +import tj.rsdevteam.inmuslim.data.models.api.UpdateMessagingIdDTO /** * Created by Rustam Safarov on 8/13/23. @@ -19,14 +19,14 @@ import tj.rsdevteam.inmuslim.data.models.network.UpdateMessagingIdResponse interface Api { @GET("GetRegions") - suspend fun getRegions(): Result + suspend fun getRegions(): Result @POST("GetTiming") - suspend fun getTiming(@Body body: GetTimingBody): Result + suspend fun getTiming(@Body body: GetTimingBodyDTO): Result @POST("RegisterUser") - suspend fun registerUser(@Body body: RegisterUserBody): Result + suspend fun registerUser(@Body body: RegisterUserBodyDTO): Result @POST("UpdateMessagingId") - suspend fun updateMessagingId(@Body body: UpdateMessagingIdBody): Result + suspend fun updateMessagingId(@Body body: UpdateMessagingIdBodyDTO): Result } diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Message.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Message.kt new file mode 100644 index 0000000..7a97084 --- /dev/null +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Message.kt @@ -0,0 +1,10 @@ +package tj.rsdevteam.inmuslim.data.models + +/** + * Created by Rustam Safarov on 6/25/24. + * github.com/rustamsafarovrs + */ + +data class Message( + val message: String +) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Region.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Region.kt index 6fcd994..7af0eef 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Region.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Region.kt @@ -1,14 +1,12 @@ package tj.rsdevteam.inmuslim.data.models import androidx.compose.runtime.mutableStateOf -import com.squareup.moshi.JsonClass /** - * Created by Rustam Safarov on 14/08/23. + * Created by Rustam Safarov on 6/25/24. * github.com/rustamsafarovrs */ -@JsonClass(generateAdapter = true) data class Region( val id: Long, val name: String diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/Resource.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Resource.kt similarity index 88% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/Resource.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/Resource.kt index a0ff248..9dfd40c 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/Resource.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Resource.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models /** * Created by Rustam Safarov on 8/13/23. diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Timing.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Timing.kt index ff4cc47..c4f5f33 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Timing.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/Timing.kt @@ -1,13 +1,10 @@ package tj.rsdevteam.inmuslim.data.models -import com.squareup.moshi.JsonClass - /** - * Created by Rustam Safarov on 8/13/23. + * Created by Rustam Safarov on 6/25/24. * github.com/rustamsafarovrs */ -@JsonClass(generateAdapter = true) data class Timing( val fajr: String, val sunrise: String, diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/User.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/User.kt new file mode 100644 index 0000000..1ee7541 --- /dev/null +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/User.kt @@ -0,0 +1,10 @@ +package tj.rsdevteam.inmuslim.data.models + +/** + * Created by Rustam Safarov on 6/25/24. + * github.com/rustamsafarovrs + */ + +data class User( + val id: Long +) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetRegionsResponse.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetRegionsDTO.kt similarity index 55% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetRegionsResponse.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetRegionsDTO.kt index 9fa5442..dbae9cc 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetRegionsResponse.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetRegionsDTO.kt @@ -1,7 +1,6 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass -import tj.rsdevteam.inmuslim.data.models.Region /** * Created by Rustam Safarov on 14/08/23. @@ -9,8 +8,8 @@ import tj.rsdevteam.inmuslim.data.models.Region */ @JsonClass(generateAdapter = true) -data class GetRegionsResponse( +data class GetRegionsDTO( val result: Int, val msg: String, - val regions: List + val regions: List ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingBody.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingBodyDTO.kt similarity index 75% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingBody.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingBodyDTO.kt index 2f9e1f0..d94d77c 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingBody.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingBodyDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @@ -9,7 +9,7 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class GetTimingBody( +data class GetTimingBodyDTO( @Json(name = "region_id") val regionId: Long ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingResponse.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingDTO.kt similarity index 67% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingResponse.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingDTO.kt index 1feb981..83d3e4c 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/GetTimingResponse.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/GetTimingDTO.kt @@ -1,8 +1,7 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import tj.rsdevteam.inmuslim.data.models.Timing /** * Created by Rustam Safarov on 8/13/23. @@ -10,11 +9,11 @@ import tj.rsdevteam.inmuslim.data.models.Timing */ @JsonClass(generateAdapter = true) -data class GetTimingResponse( +data class GetTimingDTO( val result: Int, val msg: String, val region: String, @Json(name = "begin_date") val beginDate: String, - val timing: Timing + val timing: TimingDTO ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/MessageResponse.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/MessageDTO.kt similarity index 71% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/MessageResponse.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/MessageDTO.kt index 9066966..0854e64 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/MessageResponse.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/MessageDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass @@ -8,7 +8,7 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class MessageResponse( +data class MessageDTO( val result: Int, val msg: String ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegionDTO.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegionDTO.kt new file mode 100644 index 0000000..6af9075 --- /dev/null +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegionDTO.kt @@ -0,0 +1,14 @@ +package tj.rsdevteam.inmuslim.data.models.api + +import com.squareup.moshi.JsonClass + +/** + * Created by Rustam Safarov on 14/08/23. + * github.com/rustamsafarovrs + */ + +@JsonClass(generateAdapter = true) +data class RegionDTO( + val id: Long, + val name: String +) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserBody.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserBodyDTO.kt similarity index 69% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserBody.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserBodyDTO.kt index aff5cc4..dcebed5 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserBody.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserBodyDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass @@ -8,6 +8,6 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class RegisterUserBody( +data class RegisterUserBodyDTO( val name: String ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserResponse.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserDTO.kt similarity index 72% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserResponse.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserDTO.kt index 5216aa3..fdd1b69 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/RegisterUserResponse.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/RegisterUserDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass @@ -8,7 +8,7 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class RegisterUserResponse( +data class RegisterUserDTO( val result: Int, val msg: String, val id: Long diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/TimingDTO.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/TimingDTO.kt new file mode 100644 index 0000000..717e9dc --- /dev/null +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/TimingDTO.kt @@ -0,0 +1,19 @@ +package tj.rsdevteam.inmuslim.data.models.api + +import com.squareup.moshi.JsonClass + +/** + * Created by Rustam Safarov on 8/13/23. + * github.com/rustamsafarovrs + */ + +@JsonClass(generateAdapter = true) +data class TimingDTO( + val fajr: String, + val sunrise: String, + val zuhr: String, + val asr: String, + val sunset: String, + val maghrib: String, + val isha: String +) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdBody.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdBodyDTO.kt similarity index 70% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdBody.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdBodyDTO.kt index 7996eff..74710e4 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdBody.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdBodyDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass @@ -8,7 +8,7 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class UpdateMessagingIdBody( +data class UpdateMessagingIdBodyDTO( val id: Long, val msgid: String ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdResponse.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdDTO.kt similarity index 69% rename from app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdResponse.kt rename to app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdDTO.kt index 00a5d3d..9e5da54 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/UpdateMessagingIdResponse.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/api/UpdateMessagingIdDTO.kt @@ -1,4 +1,4 @@ -package tj.rsdevteam.inmuslim.data.models.network +package tj.rsdevteam.inmuslim.data.models.api import com.squareup.moshi.JsonClass @@ -8,7 +8,7 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) -data class UpdateMessagingIdResponse( +data class UpdateMessagingIdDTO( val result: Int, val msg: String ) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/ApiError.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/ApiError.kt deleted file mode 100644 index c7c3e8d..0000000 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/models/network/ApiError.kt +++ /dev/null @@ -1,11 +0,0 @@ -package tj.rsdevteam.inmuslim.data.models.network - -/** - * Created by Rustam Safarov on 8/13/23. - * github.com/rustamsafarovrs - */ - -data class ApiError( - val result: Int, - val msg: String -) diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/ErrorHandler.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/ErrorHandler.kt index 8661745..3c8fb60 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/ErrorHandler.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/ErrorHandler.kt @@ -4,8 +4,8 @@ import retrofit2.HttpException import tj.rsdevteam.inmuslim.data.exceptions.ApiException import tj.rsdevteam.inmuslim.data.exceptions.ConnectionTimeoutException import tj.rsdevteam.inmuslim.data.exceptions.UnknownException -import tj.rsdevteam.inmuslim.data.models.network.MessageResponse -import tj.rsdevteam.inmuslim.data.models.network.Resource +import tj.rsdevteam.inmuslim.data.models.Resource +import tj.rsdevteam.inmuslim.data.models.api.MessageDTO import java.io.IOException import java.net.UnknownHostException @@ -17,8 +17,8 @@ import java.net.UnknownHostException class ErrorHandler { fun getError(result: Result<*>): Resource { - return if (result.getOrNull() is MessageResponse) { - Resource.Error(error = ApiException((result.getOrThrow() as MessageResponse).msg)) + return if (result.getOrNull() is MessageDTO) { + Resource.Error(error = ApiException((result.getOrThrow() as MessageDTO).msg)) } else if (result.exceptionOrNull() is UnknownHostException) { Resource.Error(error = ConnectionTimeoutException()) } else if (result.exceptionOrNull() is HttpException) { diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/Mappers.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/Mappers.kt new file mode 100644 index 0000000..d58b70b --- /dev/null +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/Mappers.kt @@ -0,0 +1,53 @@ +package tj.rsdevteam.inmuslim.data.repositories + +import tj.rsdevteam.inmuslim.data.models.Message +import tj.rsdevteam.inmuslim.data.models.Region +import tj.rsdevteam.inmuslim.data.models.Timing +import tj.rsdevteam.inmuslim.data.models.User +import tj.rsdevteam.inmuslim.data.models.api.MessageDTO +import tj.rsdevteam.inmuslim.data.models.api.RegionDTO +import tj.rsdevteam.inmuslim.data.models.api.RegisterUserDTO +import tj.rsdevteam.inmuslim.data.models.api.TimingDTO +import tj.rsdevteam.inmuslim.data.models.api.UpdateMessagingIdDTO + +/** + * Created by Rustam Safarov on 6/25/24. + * github.com/rustamsafarovrs + */ + +fun RegionDTO.toRegion(): Region { + return Region( + id = this.id, + name = this.name + ) +} + +fun TimingDTO.toTiming(): Timing { + return Timing( + fajr = this.fajr, + sunrise = this.sunrise, + zuhr = this.zuhr, + asr = this.asr, + sunset = this.sunset, + maghrib = this.maghrib, + isha = this.isha + ) +} + +fun MessageDTO.toMessage(): Message { + return Message( + message = this.msg + ) +} + +fun RegisterUserDTO.toUser(): User { + return User( + id = this.id + ) +} + +fun UpdateMessagingIdDTO.toMessage(): Message { + return Message( + message = this.msg + ) +} diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/RegionRepository.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/RegionRepository.kt index 98f1b80..095654e 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/RegionRepository.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/RegionRepository.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.flow import tj.rsdevteam.inmuslim.data.api.Api import tj.rsdevteam.inmuslim.data.constants.Constants import tj.rsdevteam.inmuslim.data.models.Region -import tj.rsdevteam.inmuslim.data.models.network.Resource +import tj.rsdevteam.inmuslim.data.models.Resource import tj.rsdevteam.inmuslim.data.preferences.Preferences import javax.inject.Inject import javax.inject.Singleton @@ -34,7 +34,7 @@ class RegionRepository val result = api.getRegions() delay(Constants.MIDDLE_DELAY) if (result.isSuccess && result.getOrNull()?.result == 0) { - emit(Resource.Success(result.getOrThrow().regions)) + emit(Resource.Success(result.getOrThrow().regions.map { it.toRegion() })) } else { emit(errorHandler.getError(result)) } diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/TimingRepository.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/TimingRepository.kt index 8f8c8f6..8e491bb 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/TimingRepository.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/TimingRepository.kt @@ -5,9 +5,9 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import tj.rsdevteam.inmuslim.data.api.Api import tj.rsdevteam.inmuslim.data.constants.Constants -import tj.rsdevteam.inmuslim.data.models.network.GetTimingBody -import tj.rsdevteam.inmuslim.data.models.network.GetTimingResponse -import tj.rsdevteam.inmuslim.data.models.network.Resource +import tj.rsdevteam.inmuslim.data.models.Resource +import tj.rsdevteam.inmuslim.data.models.Timing +import tj.rsdevteam.inmuslim.data.models.api.GetTimingBodyDTO import tj.rsdevteam.inmuslim.data.preferences.Preferences import javax.inject.Inject import javax.inject.Singleton @@ -26,12 +26,12 @@ class TimingRepository private val errorHandler: ErrorHandler ) { - fun getTiming(): Flow> = flow { + fun getTiming(): Flow> = flow { emit(Resource.InProgress()) - val result = api.getTiming(GetTimingBody(regionId = preferences.getRegionId())) + val result = api.getTiming(GetTimingBodyDTO(regionId = preferences.getRegionId())) delay(Constants.MIDDLE_DELAY) if (result.isSuccess && result.getOrNull()?.result == 0) { - emit(Resource.Success(result.getOrThrow())) + emit(Resource.Success(result.getOrThrow().timing.toTiming())) } else { emit(errorHandler.getError(result)) } diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/UserRepository.kt b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/UserRepository.kt index c7e2b4c..7fe0bf0 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/UserRepository.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/data/repositories/UserRepository.kt @@ -6,11 +6,11 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.withContext import tj.rsdevteam.inmuslim.data.api.Api -import tj.rsdevteam.inmuslim.data.models.network.RegisterUserBody -import tj.rsdevteam.inmuslim.data.models.network.RegisterUserResponse -import tj.rsdevteam.inmuslim.data.models.network.Resource -import tj.rsdevteam.inmuslim.data.models.network.UpdateMessagingIdBody -import tj.rsdevteam.inmuslim.data.models.network.UpdateMessagingIdResponse +import tj.rsdevteam.inmuslim.data.models.Message +import tj.rsdevteam.inmuslim.data.models.Resource +import tj.rsdevteam.inmuslim.data.models.User +import tj.rsdevteam.inmuslim.data.models.api.RegisterUserBodyDTO +import tj.rsdevteam.inmuslim.data.models.api.UpdateMessagingIdBodyDTO import tj.rsdevteam.inmuslim.data.preferences.Preferences import javax.inject.Inject import javax.inject.Singleton @@ -29,18 +29,18 @@ class UserRepository private val errorHandler: ErrorHandler ) { - fun registerUser(body: RegisterUserBody): Flow> = flow { + fun registerUser(name: String): Flow> = flow { emit(Resource.InProgress()) - val result = api.registerUser(body) + val result = api.registerUser(RegisterUserBodyDTO(name = name)) if (result.isSuccess && result.getOrNull()?.result == 0) { preferences.saveUserId(result.getOrThrow().id) - emit(Resource.Success(result.getOrThrow())) + emit(Resource.Success(result.getOrThrow().toUser())) } else { emit(errorHandler.getError(result)) } } - fun updateMessagingId(): Flow> = flow { + fun updateMessagingId(): Flow> = flow { emit(Resource.InProgress()) var msgid = "" withContext(Dispatchers.IO) { @@ -48,10 +48,10 @@ class UserRepository msgid = token } } - val result = api.updateMessagingId(UpdateMessagingIdBody(id = preferences.getUserId(), msgid = msgid)) + val result = api.updateMessagingId(UpdateMessagingIdBodyDTO(id = preferences.getUserId(), msgid = msgid)) if (result.isSuccess && result.getOrNull()?.result == 0) { preferences.saveFirebaseToken(msgid) - emit(Resource.Success(result.getOrThrow())) + emit(Resource.Success(result.getOrThrow().toMessage())) } else { emit(errorHandler.getError(result)) } diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/ui/home/HomeViewModel.kt b/app/src/main/java/tj/rsdevteam/inmuslim/ui/home/HomeViewModel.kt index 91d22f6..8f1e279 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/ui/home/HomeViewModel.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/ui/home/HomeViewModel.kt @@ -6,9 +6,8 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import tj.rsdevteam.inmuslim.data.models.DialogState +import tj.rsdevteam.inmuslim.data.models.Resource import tj.rsdevteam.inmuslim.data.models.Timing -import tj.rsdevteam.inmuslim.data.models.network.RegisterUserBody -import tj.rsdevteam.inmuslim.data.models.network.Resource import tj.rsdevteam.inmuslim.data.repositories.TimingRepository import tj.rsdevteam.inmuslim.data.repositories.UserRepository import tj.rsdevteam.inmuslim.utils.Utils @@ -51,7 +50,7 @@ class HomeViewModel .collect { rs -> when (rs) { is Resource.InProgress -> Unit - is Resource.Success -> timing.value = rs.data.timing + is Resource.Success -> timing.value = rs.data is Resource.Error -> dialogState.value = DialogState(rs.error?.message) } showLoading.value = rs is Resource.InProgress @@ -61,7 +60,7 @@ class HomeViewModel private fun registerUser() { viewModelScope.launch { - userRepository.registerUser(RegisterUserBody(Utils.getDeviceInfo())) + userRepository.registerUser(Utils.getDeviceInfo()) .collect { rs -> when (rs) { is Resource.InProgress -> Unit diff --git a/app/src/main/java/tj/rsdevteam/inmuslim/ui/region/RegionViewModel.kt b/app/src/main/java/tj/rsdevteam/inmuslim/ui/region/RegionViewModel.kt index 07ecb74..e5db48f 100644 --- a/app/src/main/java/tj/rsdevteam/inmuslim/ui/region/RegionViewModel.kt +++ b/app/src/main/java/tj/rsdevteam/inmuslim/ui/region/RegionViewModel.kt @@ -7,7 +7,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import tj.rsdevteam.inmuslim.data.models.DialogState import tj.rsdevteam.inmuslim.data.models.Region -import tj.rsdevteam.inmuslim.data.models.network.Resource +import tj.rsdevteam.inmuslim.data.models.Resource import tj.rsdevteam.inmuslim.data.repositories.RegionRepository import javax.inject.Inject