forked from gotson/komga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes gotson#63
- Loading branch information
Showing
10 changed files
with
263 additions
and
18 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
komga/src/flyway/resources/db/migration/sqlite/V20200812161631__thumbnails_series.sql
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,10 @@ | ||
CREATE TABLE THUMBNAIL_SERIES | ||
( | ||
ID varchar NOT NULL PRIMARY KEY, | ||
URL varchar NOT NULL, | ||
SELECTED boolean NOT NULL DEFAULT 0, | ||
CREATED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
LAST_MODIFIED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
SERIES_ID varchar NOT NULL, | ||
FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) | ||
); |
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
16 changes: 16 additions & 0 deletions
16
komga/src/main/kotlin/org/gotson/komga/domain/model/ThumbnailSeries.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,16 @@ | ||
package org.gotson.komga.domain.model | ||
|
||
import com.github.f4b6a3.tsid.TsidCreator | ||
import java.net.URL | ||
import java.time.LocalDateTime | ||
|
||
data class ThumbnailSeries( | ||
val url: URL, | ||
val selected: Boolean = false, | ||
|
||
val id: String = TsidCreator.getTsidString256(), | ||
val seriesId: String = "", | ||
|
||
override val createdDate: LocalDateTime = LocalDateTime.now(), | ||
override val lastModifiedDate: LocalDateTime = LocalDateTime.now() | ||
) : Auditable() |
15 changes: 15 additions & 0 deletions
15
komga/src/main/kotlin/org/gotson/komga/domain/persistence/ThumbnailSeriesRepository.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,15 @@ | ||
package org.gotson.komga.domain.persistence | ||
|
||
import org.gotson.komga.domain.model.ThumbnailSeries | ||
|
||
interface ThumbnailSeriesRepository { | ||
fun findBySeriesId(seriesId: String): Collection<ThumbnailSeries> | ||
fun findSelectedBySeriesId(seriesId: String): ThumbnailSeries? | ||
|
||
fun insert(thumbnail: ThumbnailSeries) | ||
fun markSelected(thumbnail: ThumbnailSeries) | ||
|
||
fun delete(thumbnailSeriesId: String) | ||
fun deleteBySeriesId(seriesId: String) | ||
fun deleteBySeriesIds(seriesIds: Collection<String>) | ||
} |
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
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
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
78 changes: 78 additions & 0 deletions
78
komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ThumbnailSeriesDao.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,78 @@ | ||
package org.gotson.komga.infrastructure.jooq | ||
|
||
import org.gotson.komga.domain.model.ThumbnailSeries | ||
import org.gotson.komga.domain.persistence.ThumbnailSeriesRepository | ||
import org.gotson.komga.jooq.Tables | ||
import org.gotson.komga.jooq.tables.records.ThumbnailSeriesRecord | ||
import org.jooq.DSLContext | ||
import org.springframework.stereotype.Component | ||
import java.net.URL | ||
|
||
@Component | ||
class ThumbnailSeriesDao( | ||
private val dsl: DSLContext | ||
) : ThumbnailSeriesRepository { | ||
private val ts = Tables.THUMBNAIL_SERIES | ||
|
||
override fun findBySeriesId(seriesId: String): Collection<ThumbnailSeries> = | ||
dsl.selectFrom(ts) | ||
.where(ts.SERIES_ID.eq(seriesId)) | ||
.fetchInto(ts) | ||
.map { it.toDomain() } | ||
|
||
override fun findSelectedBySeriesId(seriesId: String): ThumbnailSeries? = | ||
dsl.selectFrom(ts) | ||
.where(ts.SERIES_ID.eq(seriesId)) | ||
.and(ts.SELECTED.isTrue) | ||
.limit(1) | ||
.fetchInto(ts) | ||
.map { it.toDomain() } | ||
.firstOrNull() | ||
|
||
override fun insert(thumbnail: ThumbnailSeries) { | ||
dsl.insertInto(ts) | ||
.set(ts.ID, thumbnail.id) | ||
.set(ts.SERIES_ID, thumbnail.seriesId) | ||
.set(ts.URL, thumbnail.url.toString()) | ||
.set(ts.SELECTED, thumbnail.selected) | ||
.execute() | ||
} | ||
|
||
override fun markSelected(thumbnail: ThumbnailSeries) { | ||
dsl.transaction { config -> | ||
config.dsl().update(ts) | ||
.set(ts.SELECTED, false) | ||
.where(ts.SERIES_ID.eq(thumbnail.seriesId)) | ||
.and(ts.ID.ne(thumbnail.id)) | ||
.execute() | ||
|
||
config.dsl().update(ts) | ||
.set(ts.SELECTED, true) | ||
.where(ts.SERIES_ID.eq(thumbnail.seriesId)) | ||
.and(ts.ID.eq(thumbnail.id)) | ||
.execute() | ||
} | ||
} | ||
|
||
override fun delete(thumbnailSeriesId: String) { | ||
dsl.deleteFrom(ts).where(ts.ID.eq(thumbnailSeriesId)).execute() | ||
} | ||
|
||
override fun deleteBySeriesId(seriesId: String) { | ||
dsl.deleteFrom(ts).where(ts.SERIES_ID.eq(seriesId)).execute() | ||
} | ||
|
||
override fun deleteBySeriesIds(seriesIds: Collection<String>) { | ||
dsl.deleteFrom(ts).where(ts.SERIES_ID.`in`(seriesIds)).execute() | ||
} | ||
|
||
private fun ThumbnailSeriesRecord.toDomain() = | ||
ThumbnailSeries( | ||
url = URL(url), | ||
selected = selected, | ||
id = id, | ||
seriesId = seriesId, | ||
createdDate = createdDate, | ||
lastModifiedDate = lastModifiedDate | ||
) | ||
} |
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.