diff --git a/client/index.html b/client/index.html index d6523e3..7703d58 100644 --- a/client/index.html +++ b/client/index.html @@ -151,7 +151,7 @@
- {{ len .PodcastItems }} episodes + {{ len .PodcastItems }} episodes
diff --git a/client/podcast.html b/client/podcast.html new file mode 100644 index 0000000..ccfebbb --- /dev/null +++ b/client/podcast.html @@ -0,0 +1,157 @@ + + + + + + + PodGrab + + + + +
+
+ +

{{ .title }}

+
+
+{{range .podcast.PodcastItems}} +
+
+ {{ .Title }} +
+
+

{{.Title}}

+ {{ formatDate .PubDate }} +

{{ .Summary }}

+ + Download + +
+
+ +
+ +
+
+{{end}} +
+ + \ No newline at end of file diff --git a/db/podcast.go b/db/podcast.go index 579af07..df40038 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -36,7 +36,8 @@ type PodcastItem struct { FileURL string - GUID string + GUID string + Image string DownloadDate time.Time DownloadPath string diff --git a/main.go b/main.go index 075225c..27a5762 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,12 @@ package main import ( "fmt" + "html/template" "log" "net/http" "os" "strconv" + "time" "github.com/akhilrex/podgrab/controllers" "github.com/akhilrex/podgrab/db" @@ -23,14 +25,22 @@ func main() { db.DB, err = db.Init() if err != nil { fmt.Println("statuse: ", err) - }else{ + } else { db.Migrate() } r := gin.Default() dataPath := os.Getenv("DATA") //r.Static("/assets", "./assets") r.Static("/assets", dataPath) - r.LoadHTMLGlob("client/*") + funcMap := template.FuncMap{ + "formatDate": func(raw time.Time) string { + return raw.Format("Jan 2 2006") + }, + } + tmpl := template.Must(template.New("main").Funcs(funcMap).ParseGlob("client/*")) + + //r.LoadHTMLGlob("client/*") + r.SetHTMLTemplate(tmpl) r.GET("/podcasts", controllers.AddPodcast) r.POST("/podcasts", controllers.GetAllPodcasts) @@ -45,6 +55,22 @@ func main() { podcasts := service.GetAllPodcasts() c.HTML(http.StatusOK, "index.html", gin.H{"title": "Podgrab", "podcasts": podcasts}) }) + r.GET("/podcasts/:id/view", func(c *gin.Context) { + var searchByIdQuery controllers.SearchByIdQuery + if c.ShouldBindUri(&searchByIdQuery) == nil { + + var podcast db.Podcast + + if err := db.GetPodcastById(searchByIdQuery.Id, &podcast); err == nil { + c.HTML(http.StatusOK, "podcast.html", gin.H{"title": podcast.Title, "podcast": podcast}) + } else { + c.JSON(http.StatusBadRequest, err) + } + } else { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) + } + + }) r.POST( "/", func(c *gin.Context) { var addPodcastData controllers.AddPodcastData diff --git a/service/podcastService.go b/service/podcastService.go index 2e8061c..3040405 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -80,6 +80,7 @@ func AddPodcastItems(podcast *db.Podcast) error { PubDate: pubDate, FileURL: obj.Enclosure.URL, GUID: obj.Guid.Text, + Image: obj.Image.Href, } db.CreatePodcastItem(&podcastItem) }