Skip to content

Commit

Permalink
Migration to clean arch done
Browse files Browse the repository at this point in the history
  • Loading branch information
arrazyfathan committed Mar 19, 2023
1 parent a9a5291 commit 04226b7
Show file tree
Hide file tree
Showing 27 changed files with 200 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ class WordRepository(
override fun checkIfWordIsSaved(word: String): Flow<Boolean> {
return localDataSource.checkWordIsExist(word)
}

override fun getBookmarks(): Flow<List<ListWordEntity>> {
return localDataSource.getAllWords()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.kbbikamusbesarbahasaindonesia.core.data.source.local

class KosaKata : ArrayList<String>()
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.room

import androidx.room.TypeConverter
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.ListWordEntity
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.MeaningEntity
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.WordEntity
import com.example.kbbikamusbesarbahasaindonesia.model.Arti
import com.example.kbbikamusbesarbahasaindonesia.model.Data
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

Expand All @@ -14,10 +13,10 @@ class Converters {

@JvmStatic
@TypeConverter
fun toListData(string: String?): List<Data>? {
val listType = object : TypeToken<List<Data>>() {}.type
fun toWordList(string: String?): List<ListWordEntity>? {
val listType = object : TypeToken<List<ListWordEntity>>() {}.type
return if (string != null) {
Gson().fromJson<List<Data>>(string, listType)
Gson().fromJson<List<ListWordEntity>>(string, listType)
} else {
null
}
Expand All @@ -26,25 +25,14 @@ class Converters {
@JvmStatic
@TypeConverter
fun toListWord(string: String?): List<WordEntity>? {
val listType = object : TypeToken<List<Data>>() {}.type
val listType = object : TypeToken<List<WordEntity>>() {}.type
return if (string != null) {
Gson().fromJson<List<WordEntity>>(string, listType)
} else {
null
}
}

@JvmStatic
@TypeConverter
fun fromListData(list: List<Data>?): String? {
val type = object : TypeToken<List<Data>>() {}.type
return if (list != null) {
Gson().toJson(list, type)
} else {
null
}
}

@JvmStatic
@TypeConverter
fun fromListWord(list: List<WordEntity>?): String? {
Expand All @@ -58,10 +46,10 @@ class Converters {

@JvmStatic
@TypeConverter
fun toListArti(string: String?): List<Arti>? {
val listType = object : TypeToken<List<Arti>>() {}.type
return if (string != null) {
Gson().fromJson<List<Arti>>(string, listType)
fun fromWordList(list: List<ListWordEntity>?): String? {
val type = object : TypeToken<List<ListWordEntity>>() {}.type
return if (list != null) {
Gson().toJson(list, type)
} else {
null
}
Expand All @@ -78,17 +66,6 @@ class Converters {
}
}

@JvmStatic
@TypeConverter
fun fromListArti(list: List<Arti>?): String? {
val type = object : TypeToken<List<Arti>>() {}.type
return if (list != null) {
Gson().toJson(list, type)
} else {
null
}
}

@JvmStatic
@TypeConverter
fun fromListMeanings(list: List<MeaningEntity>?): String? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package com.example.kbbikamusbesarbahasaindonesia.core.data.source.remote.network

import com.example.kbbikamusbesarbahasaindonesia.core.data.source.remote.response.ListWordResponse
import com.example.kbbikamusbesarbahasaindonesia.model.Kata
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path

interface ApiService {

@GET("/cari/{kata}")
fun getArtiKata(
@Path("kata") kata: String,
): Call<Kata>

@GET("/cari/{word}")
suspend fun getMeaningWord(@Path("word") word: String): ListWordResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.example.kbbikamusbesarbahasaindonesia.core.data.source.remote.RemoteD
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.remote.network.ApiService
import com.example.kbbikamusbesarbahasaindonesia.core.domain.repository.IWordRepository
import com.example.kbbikamusbesarbahasaindonesia.core.utils.AppExecutors
import com.example.kbbikamusbesarbahasaindonesia.repository.KataRepository
import com.example.kbbikamusbesarbahasaindonesia.utils.Constant
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -53,7 +52,6 @@ val networkModule = module {
}

val repositoryModule = module {
single { KataRepository(get()) }
single { RemoteDataSource(get()) }
single { LocalDataSource(get()) }
factory { AppExecutors() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.kbbikamusbesarbahasaindonesia.core.domain.repository

import com.example.kbbikamusbesarbahasaindonesia.core.data.Resource
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.HistoryEntity
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.ListWordEntity
import com.example.kbbikamusbesarbahasaindonesia.core.domain.model.WordModel
import kotlinx.coroutines.flow.Flow

Expand All @@ -15,4 +16,5 @@ interface IWordRepository {
fun getAllHistories(): Flow<List<HistoryEntity>>
suspend fun deleteWord(word: String)
fun checkIfWordIsSaved(word: String): Flow<Boolean>
fun getBookmarks(): Flow<List<ListWordEntity>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.kbbikamusbesarbahasaindonesia.core.domain.usecase

import com.example.kbbikamusbesarbahasaindonesia.core.data.Resource
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.HistoryEntity
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.ListWordEntity
import com.example.kbbikamusbesarbahasaindonesia.core.domain.model.WordModel
import com.example.kbbikamusbesarbahasaindonesia.core.domain.repository.IWordRepository
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -34,4 +35,8 @@ class WordInteractor(private val wordRepository: IWordRepository) : WordUseCase
override fun checkIfWordIsSaved(word: String): Flow<Boolean> {
return wordRepository.checkIfWordIsSaved(word)
}

override fun getBookmarks(): Flow<List<ListWordEntity>> {
return wordRepository.getBookmarks()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.kbbikamusbesarbahasaindonesia.core.domain.usecase

import com.example.kbbikamusbesarbahasaindonesia.core.data.Resource
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.HistoryEntity
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.entity.ListWordEntity
import com.example.kbbikamusbesarbahasaindonesia.core.domain.model.WordModel
import kotlinx.coroutines.flow.Flow

Expand All @@ -15,4 +16,5 @@ interface WordUseCase {
fun getAllHistories(): Flow<List<HistoryEntity>>
suspend fun deleteWord(word: String)
fun checkIfWordIsSaved(word: String): Flow<Boolean>
fun getBookmarks(): Flow<List<ListWordEntity>>
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 04226b7

Please sign in to comment.