-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🏗️ extract common data logic (#21)
create ComicLocalDataSource & ComicRemoteDataSource polymorphic on T refactor ComicRepository to use ComicLocalDataSource & ComicRemoteDataSource and polymorphic on T create specific datasources & repository for Suggestion create specific datasources & repository for Search reorganise packages to reflect data common feature. closes #15
- Loading branch information
1 parent
e4c9b4e
commit 3d3bdf0
Showing
23 changed files
with
413 additions
and
118 deletions.
There are no files selected for viewing
217 changes: 217 additions & 0 deletions
217
app/schemas/es.ffgiraldez.comicsearch.comics.data.storage.ComicDatabase/1.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "843b5908f7967726e53a210136b5cda2", | ||
"entities": [ | ||
{ | ||
"tableName": "queries", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query_identifier` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `search_term` TEXT NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "queryId", | ||
"columnName": "query_identifier", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "searchTerm", | ||
"columnName": "search_term", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"query_identifier" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "idx_query_identifier", | ||
"unique": false, | ||
"columnNames": [ | ||
"query_identifier" | ||
], | ||
"createSql": "CREATE INDEX `idx_query_identifier` ON `${TABLE_NAME}` (`query_identifier`)" | ||
}, | ||
{ | ||
"name": "idx_query_term", | ||
"unique": false, | ||
"columnNames": [ | ||
"search_term" | ||
], | ||
"createSql": "CREATE INDEX `idx_query_term` ON `${TABLE_NAME}` (`search_term`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "suggestions", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`suggestionId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `query_id` INTEGER NOT NULL, `title` TEXT NOT NULL, FOREIGN KEY(`query_id`) REFERENCES `queries`(`query_identifier`) ON UPDATE NO ACTION ON DELETE CASCADE )", | ||
"fields": [ | ||
{ | ||
"fieldPath": "suggestionId", | ||
"columnName": "suggestionId", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "queryId", | ||
"columnName": "query_id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"suggestionId" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "idx_suggestion_id", | ||
"unique": false, | ||
"columnNames": [ | ||
"query_id" | ||
], | ||
"createSql": "CREATE INDEX `idx_suggestion_id` ON `${TABLE_NAME}` (`query_id`)" | ||
} | ||
], | ||
"foreignKeys": [ | ||
{ | ||
"table": "queries", | ||
"onDelete": "CASCADE", | ||
"onUpdate": "NO ACTION", | ||
"columns": [ | ||
"query_id" | ||
], | ||
"referencedColumns": [ | ||
"query_identifier" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"tableName": "search", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`search_identifier` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `search_term` TEXT NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "queryId", | ||
"columnName": "search_identifier", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "searchTerm", | ||
"columnName": "search_term", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"search_identifier" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "idx_search_identifier", | ||
"unique": false, | ||
"columnNames": [ | ||
"search_identifier" | ||
], | ||
"createSql": "CREATE INDEX `idx_search_identifier` ON `${TABLE_NAME}` (`search_identifier`)" | ||
}, | ||
{ | ||
"name": "idx_search_term", | ||
"unique": false, | ||
"columnNames": [ | ||
"search_term" | ||
], | ||
"createSql": "CREATE INDEX `idx_search_term` ON `${TABLE_NAME}` (`search_term`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "volumes", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`suggestionId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `search_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `url` TEXT NOT NULL, FOREIGN KEY(`search_id`) REFERENCES `search`(`search_identifier`) ON UPDATE NO ACTION ON DELETE CASCADE )", | ||
"fields": [ | ||
{ | ||
"fieldPath": "suggestionId", | ||
"columnName": "suggestionId", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "queryId", | ||
"columnName": "search_id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "author", | ||
"columnName": "author", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"suggestionId" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "idx_search_id", | ||
"unique": false, | ||
"columnNames": [ | ||
"search_id" | ||
], | ||
"createSql": "CREATE INDEX `idx_search_id` ON `${TABLE_NAME}` (`search_id`)" | ||
} | ||
], | ||
"foreignKeys": [ | ||
{ | ||
"table": "search", | ||
"onDelete": "CASCADE", | ||
"onUpdate": "NO ACTION", | ||
"columns": [ | ||
"search_id" | ||
], | ||
"referencedColumns": [ | ||
"search_identifier" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"843b5908f7967726e53a210136b5cda2\")" | ||
] | ||
} | ||
} |
86 changes: 0 additions & 86 deletions
86
app/src/main/java/es/ffgiraldez/comicsearch/comics/ComicRepository.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
app/src/main/java/es/ffgiraldez/comicsearch/comics/data/ComicDataSources.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package es.ffgiraldez.comicsearch.comics.data | ||
|
||
import arrow.core.Option | ||
import es.ffgiraldez.comicsearch.comics.domain.Query | ||
import io.reactivex.Completable | ||
import io.reactivex.Flowable | ||
import io.reactivex.Single | ||
|
||
interface ComicLocalDataSource<T> { | ||
fun findQueryByTerm(searchTerm: String): Flowable<Option<Query>> | ||
fun findByQuery(query: Query): Flowable<List<T>> | ||
fun insert(query: String, titles: List<T>): Completable | ||
} | ||
|
||
interface ComicRemoteDataSource<T> { | ||
fun findByTerm(searchTerm: String): Single<List<T>> | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/es/ffgiraldez/comicsearch/comics/data/ComicRepository.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package es.ffgiraldez.comicsearch.comics.data | ||
|
||
import arrow.core.None | ||
import arrow.core.Some | ||
import io.reactivex.Flowable | ||
|
||
abstract class ComicRepository<T>( | ||
private val local: ComicLocalDataSource<T>, | ||
private val remote: ComicRemoteDataSource<T> | ||
) { | ||
fun findByTerm(term: String): Flowable<List<T>> = | ||
local.findQueryByTerm(term) | ||
.flatMap { | ||
when (it) { | ||
is None -> remote.findByTerm(term) | ||
.flatMapPublisher { local.insert(term, it).toFlowable<List<T>>() } | ||
is Some -> local.findByQuery(it.t) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...z/comicsearch/comics/data/ComicVineApi.kt → ...earch/comics/data/network/ComicVineApi.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...csearch/comics/data/ComicVineResponses.kt → ...comics/data/network/ComicVineResponses.kt
This file contains 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
4 changes: 2 additions & 2 deletions
4
...ldez/comicsearch/comics/store/ComicDao.kt → ...micsearch/comics/data/storage/ComicDao.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...comicsearch/comics/store/ComicDatabase.kt → ...arch/comics/data/storage/ComicDatabase.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...comicsearch/comics/store/ComicEntities.kt → ...arch/comics/data/storage/ComicEntities.kt
This file contains 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
Oops, something went wrong.