Initial test, but meh
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package database
|
||||
|
||||
type Chapter struct {
|
||||
Id int `gorm:"primary_key;AUTO_INCREMENT"`
|
||||
Id int `gorm:"primary_key;autoIncrement;"`
|
||||
ChapterId int
|
||||
Url string
|
||||
Name string
|
||||
Number string
|
||||
@@ -11,7 +12,7 @@ type Chapter struct {
|
||||
|
||||
func NewChapter(id int, mangaId int, url string, name string, number string, timeStampUnix int64) Chapter {
|
||||
return Chapter{
|
||||
Id: id,
|
||||
ChapterId: id,
|
||||
Url: url,
|
||||
Name: name,
|
||||
Number: number,
|
||||
|
||||
@@ -54,6 +54,6 @@ func (dbMgr *Manager) Delete(mangaId int) {
|
||||
}
|
||||
|
||||
func (dbMgr *Manager) createDatabaseIfNotExists() error {
|
||||
err := dbMgr.Db.AutoMigrate(&Manga{}, &Chapter{}, &Setting{})
|
||||
err := dbMgr.Db.AutoMigrate(&MangaDefinition{}, &User{}, &Manga{}, &Chapter{}, &Setting{})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
package database
|
||||
|
||||
type Manga struct {
|
||||
type MangaDefinition struct {
|
||||
Id int `gorm:"primary_key;AUTO_INCREMENT"`
|
||||
Title string
|
||||
TimeStampUnix int64
|
||||
Thumbnail []byte
|
||||
LastChapterNum string
|
||||
Chapters []Chapter
|
||||
// Chapters []Chapter
|
||||
//`gorm:"foreignkey:MangaID"`
|
||||
}
|
||||
|
||||
func NewManga(id int, title string, timeStampUnix int64) Manga {
|
||||
return Manga{
|
||||
type Manga struct {
|
||||
Id int `gorm:"primary_key;AUTO_INCREMENT"`
|
||||
MangaDefinitionId int
|
||||
Definition MangaDefinition `gorm:"foreignKey:MangaDefinitionId"`
|
||||
UserId int
|
||||
TimeStampUnix int64
|
||||
Chapters []Chapter `gorm:"foreignKey:MangaId"`
|
||||
}
|
||||
|
||||
func NewMangaDefinition(id int, title string, timeStampUnix int64) MangaDefinition {
|
||||
return MangaDefinition{
|
||||
Id: id,
|
||||
Title: title,
|
||||
TimeStampUnix: timeStampUnix,
|
||||
@@ -21,20 +30,20 @@ func NewManga(id int, title string, timeStampUnix int64) Manga {
|
||||
|
||||
// GetLatestChapter TODO: Cache this somehow
|
||||
func (m *Manga) GetLatestChapter() (*Chapter, bool) {
|
||||
highest := int64(0)
|
||||
index := 0
|
||||
for i, chapter := range m.Chapters {
|
||||
if chapter.MangaId == m.Id && highest < chapter.TimeStampUnix {
|
||||
highest = chapter.TimeStampUnix
|
||||
index = i
|
||||
}
|
||||
}
|
||||
// highest := int64(0)
|
||||
// index := 0
|
||||
// for i, chapter := range m.Chapters {
|
||||
// if chapter.MangaId == m.Manga.Id && highest < chapter.TimeStampUnix {
|
||||
// highest = chapter.TimeStampUnix
|
||||
// index = i
|
||||
// }
|
||||
// }
|
||||
|
||||
if highest == 0 {
|
||||
return nil, false
|
||||
}
|
||||
// if highest == 0 {
|
||||
return nil, false
|
||||
// }
|
||||
|
||||
return &m.Chapters[index], true
|
||||
// return &m.Chapters[index], true
|
||||
|
||||
//result := db.Where("manga.id = ?", m.Id).Order("TimeStampUnix desc").Take(&chapter)
|
||||
//if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
|
||||
18
internal/database/user.go
Normal file
18
internal/database/user.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package database
|
||||
|
||||
type User struct {
|
||||
Id int `gorm:"primary_key;AUTO_INCREMENT"`
|
||||
DisplayName string
|
||||
LoginName string
|
||||
PwdHash []byte
|
||||
Salt []byte
|
||||
Mangas []Manga `gorm:"foreignKey:UserId"`
|
||||
}
|
||||
|
||||
// type UserManga struct {
|
||||
// Id int `gorm:"primary_key;AUTO_INCREMENT"`
|
||||
// DisplayName string
|
||||
// Manga Manga
|
||||
// User User
|
||||
// // Chapters []Chapter `gorm:"ForeignKey:ChapterId,UserId;References:Id,UserId"`
|
||||
// }
|
||||
Reference in New Issue
Block a user