Merge pull request #2 from apollo1220/stats-request

Add stats request
pull/298/head
apollo1220 1 year ago committed by GitHub
commit 499ba797d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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})
}

@ -181,6 +181,8 @@ func main() {
router.POST("/podcasts/:id/tags/:tagId", controllers.AddTagToPodcast)
router.DELETE("/podcasts/:id/tags/:tagId", controllers.RemoveTagFromPodcast)
router.GET("/stats", controllers.GetStats)
router.GET("/add", controllers.AddPage)
router.GET("/search", controllers.Search)
router.GET("/", controllers.HomePage)

Loading…
Cancel
Save