Skip to content

Commit

Permalink
save hoster to database
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 21, 2023
1 parent 14c4ef3 commit b2a8158
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ class SeriesScreenComponent(
progress = 0L,
seriesHref = commonHref.value
)

episode.hosters.forEach { hoster ->
database.burningSeriesQueries.insertHoster(
href = hoster.href,
title = hoster.title,
episodeHref = episode.href
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ CREATE TABLE IF NOT EXISTS Episode(
length INTEGER NOT NULL,
progress INTEGER NOT NULL,
seriesHref TEXT NOT NULL,
FOREIGN KEY (seriesHref) REFERENCES Series(hrefPrimary) ON DELETE NO ACTION
FOREIGN KEY (seriesHref) REFERENCES Series(hrefPrimary) ON DELETE NO ACTION
);

CREATE TABLE IF NOT EXISTS Hoster(
href TEXT NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
episodeHref TEXT NOT NULL,
FOREIGN KEY (episodeHref) REFERENCES Episode(href) ON DELETE CASCADE
);

insertSeries:
Expand Down Expand Up @@ -53,4 +60,10 @@ selectEpisodeByHref:
SELECT * FROM Episode WHERE href = :href OR href LIKE :href;

selectEpisodesBySeriesHref:
SELECT * FROM Episode WHERE seriesHref = :href OR seriesHref LIKE :href;
SELECT * FROM Episode WHERE seriesHref = :href OR seriesHref LIKE :href;

insertHoster:
INSERT OR IGNORE INTO Hoster (href, title, episodeHref) VALUES (?, ?, ?);

selectHosterByEpisodeHref:
SELECT * FROM Hoster WHERE episodeHref = :href OR episodeHref LIKE :href;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.datlag.burningseries.database.common

import dev.datlag.burningseries.database.Hoster
import dev.datlag.burningseries.model.Series.Episode.Hoster as ModelHoster
import dev.datlag.burningseries.database.Episode
import dev.datlag.burningseries.model.Series.Episode as ModelEpisode
import dev.datlag.burningseries.database.Series
import dev.datlag.burningseries.model.Series as ModelSeries

fun Series.toModelSeries(episodes: List<Episode>): ModelSeries {
fun Series.toModelSeries(episodes: List<Episode>, hosters: List<Hoster>): ModelSeries {
return ModelSeries(
title = this.title,
description = "",
Expand All @@ -15,15 +17,22 @@ fun Series.toModelSeries(episodes: List<Episode>): ModelSeries {
selectedLanguage = null,
seasons = emptyList(),
languages = emptyList(),
episodes = episodes.map { it.toModelEpisode() }
episodes = episodes.map { it.toModelEpisode(hosters) }
)
}

fun Episode.toModelEpisode(): ModelEpisode {
fun Episode.toModelEpisode(hosters: List<Hoster>): ModelEpisode {
return ModelEpisode(
number = this.number,
title = this.title,
href = this.href,
hosters = emptyList()
hosters = hosters.map { it.toModelHoster() }
)
}

fun Hoster.toModelHoster(): ModelHoster {
return ModelHoster(
title = this.title,
href = this.href
)
}

0 comments on commit b2a8158

Please sign in to comment.