working on tags

pull/53/head
Akhil Gupta 4 years ago
parent 3ed9a8422f
commit 3eb8e61b19

@ -35,7 +35,7 @@ func Init() (*gorm.DB, error) {
//Migrate Database //Migrate Database
func Migrate() { func Migrate() {
DB.AutoMigrate(&Podcast{}, &PodcastItem{}, &Setting{}, &Migration{}, &JobLock{}) DB.AutoMigrate(&Podcast{}, &PodcastItem{}, &Setting{}, &Migration{}, &JobLock{}, &Tag{})
RunMigrations() RunMigrations()
} }

@ -236,3 +236,29 @@ func UnlockMissedJobs() {
} }
} }
} }
func GetAllTags(sorting string) (*[]Tag, error) {
var tags []Tag
if sorting == "" {
sorting = "created_at"
}
result := DB.Debug().Order(sorting).Find(&tags)
return &tags, result.Error
}
func GetTagById(id string) (*Tag, error) {
var tag Tag
result := DB.Preload(clause.Associations).
First(&tag, "id=?", id)
return &tag, result.Error
}
func CreateTag(tag *Tag) error {
tx := DB.Omit("Podcasts").Create(&tag)
return tx.Error
}
func UpdateTag(tag *Tag) error {
tx := DB.Omit("Podcast").Save(&tag)
return tx.Error
}

@ -21,6 +21,8 @@ type Podcast struct {
PodcastItems []PodcastItem PodcastItems []PodcastItem
Tag []*Tag `gorm:"many2many:podcast_tags;"`
DownloadedEpisodesCount int `gorm:"-"` DownloadedEpisodesCount int `gorm:"-"`
DownloadingEpisodesCount int `gorm:"-"` DownloadingEpisodesCount int `gorm:"-"`
AllEpisodesCount int `gorm:"-"` AllEpisodesCount int `gorm:"-"`
@ -85,6 +87,13 @@ type JobLock struct {
Duration int Duration int
} }
type Tag struct {
Base
Label string
Description string `gorm:"type:text"`
Podcasts []*Podcast `gorm:"many2many:podcast_tags;"`
}
func (lock *JobLock) IsLocked() bool { func (lock *JobLock) IsLocked() bool {
return lock != nil && lock.Date != time.Time{} return lock != nil && lock.Date != time.Time{}
} }

Loading…
Cancel
Save