diff --git a/client/episodes.html b/client/episodes.html new file mode 100644 index 0000000..b2facbd --- /dev/null +++ b/client/episodes.html @@ -0,0 +1,182 @@ + + + + + + + PodGrab + + + + +
+
+ +

{{ .title }}

+
+
+{{range .podcastItems}} +
+
+ {{ .Title }} +
+
+

{{.Title}} // {{ .Podcast.Title}}

+ {{ formatDate .PubDate }} +

{{ .Summary }}

+ + Download + +
+
+ +
+ +
+
+{{end}} +
+ + \ No newline at end of file diff --git a/client/index.html b/client/index.html index 7703d58..d6b8b8e 100644 --- a/client/index.html +++ b/client/index.html @@ -157,6 +157,11 @@
{{end}} +
+
+ All Episodes +
+
\ No newline at end of file diff --git a/controllers/podcast.go b/controllers/podcast.go index f0d3a64..eabb6ea 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -19,6 +19,11 @@ type SearchByIdQuery struct { Id string `binding:"required" uri:"id" json:"id" form:"id"` } +type Pagination struct { + Page int `uri:"page" query:"page" json:"page" form:"page"` + Count int `uri:"count" query:"count" json:"count" form:"count"` +} + type AddPodcastData struct { Url string `binding:"required" form:"url" json:"url"` } diff --git a/db/dbfunctions.go b/db/dbfunctions.go index 9150b97..19a7186 100644 --- a/db/dbfunctions.go +++ b/db/dbfunctions.go @@ -17,7 +17,11 @@ func GetAllPodcasts(podcasts *[]Podcast) error { } func GetAllPodcastItems(podcasts *[]PodcastItem) error { - result := DB.Preload("Podcast").Find(&podcasts) + result := DB.Preload("Podcast").Order("pub_date desc").Find(&podcasts) + return result.Error +} +func GetPaginatedPodcastItems(page int, count int, podcasts *[]PodcastItem) error { + result := DB.Debug().Preload("Podcast").Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts) return result.Error } func GetPodcastById(id string, podcast *Podcast) error { diff --git a/main.go b/main.go index 27a5762..ec18564 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,28 @@ func main() { c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) } + }) + r.GET("/episodes", func(c *gin.Context) { + var pagination controllers.Pagination + if c.ShouldBindQuery(&pagination) == nil { + var page, count int + if page = pagination.Page; page == 0 { + page = 1 + } + if count = pagination.Count; count == 0 { + count = 10 + } + var podcastItems []db.PodcastItem + + if err := db.GetPaginatedPodcastItems(page, count, &podcastItems); err == nil { + c.HTML(http.StatusOK, "episodes.html", gin.H{"title": "All Episodes", "podcastItems": podcastItems}) + } else { + c.JSON(http.StatusBadRequest, err) + } + } else { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) + } + }) r.POST( "/", func(c *gin.Context) {