feat: reimplementd GetTVShow handler

This commit is contained in:
2024-11-06 02:19:26 +01:00
parent cba9dd3ffc
commit dd3853af7b
9 changed files with 28 additions and 128 deletions
+14 -40
View File
@@ -1,46 +1,20 @@
package handlers
//func (hq *Handlers) GetAllChapters(c *fiber.Ctx) error {
// tvShow := models.TvShow{}
import (
"log/slog"
"net/http"
// ttShowID := c.Query("id")
"github.com/gin-gonic/gin"
"github.com/zepyrshut/rating-orama/internal/scraper"
)
// if ttShowID[0:2] == "tt" {
// ttShowID = ttShowID[2:]
// }
func (hq *Handlers) GetTVShow(c *gin.Context) {
ttShowID := c.Query("ttid")
slog.Info("GetTVShow", "ttid", ttShowID)
// exist := hq.DB.CheckIfTvShowExists(ttShowID)
seasons := scraper.ScrapeSeasons(ttShowID)
// if !exist {
// url := fmt.Sprintf(hq.App.Environment.HarvesterApi, ttShowID)
// response, _ := http.Get(url)
// body, _ := io.ReadAll(response.Body)
// err := json.Unmarshal(body, &tvShow)
// if err != nil {
// hq.App.Error(err.Error())
// return c.Status(http.StatusInternalServerError).JSON(err)
// }
// err = hq.DB.InsertTvShow(tvShow)
// if err != nil {
// hq.App.Error(err.Error())
// return c.Status(http.StatusInternalServerError).JSON(err)
// }
// }
// tvShow, err := hq.DB.FetchTvShow(ttShowID)
// if err != nil {
// hq.App.Error(err.Error())
// return c.Status(http.StatusInternalServerError).JSON(err)
// }
// tvShowJSON, err := json.Marshal(tvShow)
// if err != nil {
// hq.App.Error(err.Error())
// return c.Status(http.StatusInternalServerError).JSON(err)
// }
// return c.Render("charts", fiber.Map{
// "TvShow": tvShow,
// "TvShowJSON": string(tvShowJSON),
// })
//}
c.JSON(http.StatusOK, gin.H{
"seasons": seasons,
})
}