|
|
|
@ -645,3 +645,33 @@ func UpdateSetting(c *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetStats(c *gin.Context) {
|
|
|
|
|
var items []db.PodcastItem
|
|
|
|
|
|
|
|
|
|
if err := db.GetAllPodcastItems(&items); err != nil {
|
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var podcasts []db.Podcast
|
|
|
|
|
if err := db.GetAllPodcasts(&podcasts, ""); err != nil {
|
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downloadedCount := 0
|
|
|
|
|
listenedCount := 0
|
|
|
|
|
podcastCount := len(podcasts)
|
|
|
|
|
for _, i := range items {
|
|
|
|
|
if i.DownloadStatus == db.Downloaded {
|
|
|
|
|
downloadedCount++
|
|
|
|
|
}
|
|
|
|
|
if i.IsPlayed {
|
|
|
|
|
listenedCount++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(200, gin.H{"downloaded": downloadedCount, "listened": listenedCount, "podcasts": podcastCount})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|