Fixed various Bugs

This commit is contained in:
Pablu23
2024-04-03 16:12:44 +02:00
parent cb592c7109
commit 58344d4def
9 changed files with 62 additions and 57 deletions

View File

@@ -9,11 +9,11 @@ type Chapter struct {
MangaId int
Url string
Name string
Number int
Number string
TimeStampUnix int64
}
func NewChapter(id int, mangaId int, url string, name string, number int, timeStampUnix int64) Chapter {
func NewChapter(id int, mangaId int, url string, name string, number string, timeStampUnix int64) Chapter {
return Chapter{
Id: id,
MangaId: mangaId,
@@ -52,6 +52,6 @@ func loadChapters(db *sql.DB) (map[int]Chapter, error) {
}
func deleteChapter(db *sql.DB, key int) error {
_, err := db.Exec("DELETE from Manga where ID = ?", key)
_, err := db.Exec("DELETE from Chapter where ID = ?", key)
return err
}

View File

@@ -2,8 +2,8 @@ create table if not exists Manga (
ID integer not null primary key,
Title text,
TimeStampUnixEpoch integer not null,
Thumbnail blob,
LatestAvailableChapter integer not null
Thumbnail blob null,
LatestAvailableChapter text
);
create table if not exists Chapter (
@@ -11,7 +11,7 @@ create table if not exists Chapter (
MangaID integer not null,
Url text not null,
Name text null,
Number integer not null,
Number text null,
TimeStampUnixEpoch integer not null,
foreign key(MangaID) references Manga(ID)
);

View File

@@ -10,14 +10,15 @@ type Manga struct {
Title string
TimeStampUnix int64
Thumbnail *bytes.Buffer
LastChapterNum int
LastChapterNum string
}
func NewManga(id int, title string, timeStampUnix int64) Manga {
return Manga{
Id: id,
Title: title,
TimeStampUnix: timeStampUnix,
Id: id,
Title: title,
TimeStampUnix: timeStampUnix,
LastChapterNum: "",
}
}
@@ -43,13 +44,25 @@ func (m *Manga) GetLatestChapter(chapters *DbTable[int, Chapter]) (*Chapter, boo
func updateManga(db *sql.DB, m *Manga) error {
const cmd = "UPDATE Manga set Title = ?, TimeStampUnixEpoch = ?, Thumbnail = ?, LatestAvailableChapter = ? WHERE ID = ?"
_, err := db.Exec(cmd, m.Title, m.TimeStampUnix, m.Thumbnail.Bytes(), m.LastChapterNum, m.Id)
var err error
if m.Thumbnail == nil {
_, err = db.Exec(cmd, m.Title, m.TimeStampUnix, nil, m.LastChapterNum, m.Id)
} else {
_, err = db.Exec(cmd, m.Title, m.TimeStampUnix, m.Thumbnail.Bytes(), m.LastChapterNum, m.Id)
}
return err
}
func insertManga(db *sql.DB, manga *Manga) error {
const cmd = "INSERT INTO Manga(ID, Title, TimeStampUnixEpoch, Thumbnail, LatestAvailableChapter) values(?, ?, ?, ?, ?)"
_, err := db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, manga.Thumbnail.Bytes(), manga.LastChapterNum)
var err error
if manga.Thumbnail == nil {
_, err = db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, nil, manga.LastChapterNum)
} else {
_, err = db.Exec(cmd, manga.Id, manga.Title, manga.TimeStampUnix, manga.Thumbnail.Bytes(), manga.LastChapterNum)
}
return err
}
@@ -78,6 +91,6 @@ func loadMangas(db *sql.DB) (map[int]Manga, error) {
}
func deleteManga(db *sql.DB, key int) error {
_, err := db.Exec("DELETE from Chapter where ID = ?", key)
_, err := db.Exec("DELETE from Manga where ID = ?", key)
return err
}