This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Startup { | |
var dictionary: Module = module(override = true) { | |
single { ... } | |
} | |
init { | |
injectDependencies() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictionaryController : KoinComponent { | |
private val repository: RepositoryInterface by inject() | |
fun getNumberOfPagesInDictionary(): Any { | |
return try { | |
repository.getNumberOfPagesInDictionary() | |
} catch (e: PageRetrievalException) { | |
ErrorMesssage(message = e.errorMessage, type = ErrorType.PAGE_RETRIVAL_ERROR) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictionaryHandlerTest { | |
@Test | |
fun testGetTotalPagesInDictionary() { | |
val handler = DictionaryTotalPageHandler() | |
val gson = Gson() | |
loadKoinModules(module(override = true) { | |
single { MockRepository() as RepositoryInterface } | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Startup { | |
var dictionary: Module = module(override = true) { | |
single { api.data.repository.DictionaryRepository() as api.data.repository.RepositoryInterface } | |
single { | |
com.microsoft.azure.documentdb.DocumentClient(java.lang.System.getenv("HOST"), | |
System.getenv("MASTER_KEY"), | |
com.microsoft.azure.documentdb.ConnectionPolicy.GetDefault(), | |
com.microsoft.azure.documentdb.ConsistencyLevel.Session) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictionaryRepository : RepositoryInterface, KoinComponent { | |
companion object { | |
val RECORDS_PER_PAGE = 20 | |
} | |
val client: DocumentClient by inject() | |
override fun getNumberOfPagesInDictionary(): Page { | |
var page: Page | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val findSpec = SqlQuerySpec().apply { | |
queryText = "SELECT Dictionary.word AS word, Dictionary.meaning AS meaning FROM Dictionary WHERE Dictionary.partition = @tag AND contains(Dictionary.search, @query) OFFSET @offset LIMIT @records_per_page" | |
parameters = SqlParameterCollection().apply { | |
add(SqlParameter("@tag", query.first().toUpperCase().toString())) | |
add(SqlParameter("@query", query.toLowerCase())) | |
add(SqlParameter("@offset", offset)) | |
add(SqlParameter("@records_per_page", RECORDS_PER_PAGE)) | |
} | |
} | |
val countSpec = SqlQuerySpec().apply { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Maven | |
# Build your Java project and run tests with Apache Maven. | |
# Add steps that analyze code, save build artifacts, deploy, and more: | |
# https://docs.microsoft.com/azure/devops/pipelines/languages/java | |
trigger: | |
- master | |
pool: | |
vmImage: 'ubuntu-latest' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val BASE_URL = "https://dictionary-sample.azurewebsites.net/" | |
const val PAGE_SIZE = 20 | |
val dictionaryModule = module { | |
single { createApiClient() } | |
single { DictionaryRepository(get()) as Repository } | |
single { PagedList.Config.Builder().setPageSize(PAGE_SIZE).setEnablePlaceholders(false).build() } | |
single { MutableLiveData<Event<NetworkState>>() } | |
factory { DictionaryAllWordsDataSourceFactory(get(), get()) } | |
factory { DictionarySearchWordsDataSourceFactory(get(), get()) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface DictionaryApi { | |
@GET("/api/v1/dictionary/pages") | |
fun getNumberOfPagesInDictionary(): Call<Page> | |
@GET("/api/v1/dictionary/page/{pageNo}") | |
fun getWordsInDictionaryPage(@Path("pageNo") pageNo: Int): Call<Dictionary> | |
@GET("/api/v1/dictionary") | |
fun searchForWordsInDictionary(@Query("pageNo") pageNo: Int, @Query("word") word: String): Call<SearchResult> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MeaningAdapter : PagedListAdapter<Meaning, RecyclerView.ViewHolder>(REPO_COMPARATOR) { | |
//.. | |
override fun onCreateViewHolder( | |
parent: ViewGroup, | |
viewType: Int | |
): RecyclerView.ViewHolder { | |
val view = LayoutInflater.from(parent.context) | |
.inflate(R.layout.fragment_meaning, parent, false) | |
return DictionaryViewHolder(view) | |
} |