Changed theme, added search, added pagination

This commit is contained in:
2022-11-27 09:27:49 +01:00
parent 7ab57f2ea0
commit bea96468d5
19 changed files with 370 additions and 137 deletions
+31 -5
View File
@@ -3,13 +3,14 @@ package app
import (
"fmt"
"net/http"
"net/url"
"github.com/diaid83/pokemongotemplates/internal/domain/pokemongotemplates"
"github.com/dadobos/pokemongotemplates/internal/domain/pokemongotemplates"
"github.com/gin-gonic/gin"
)
func (s *ApplicationServer) pokemonPageHandler() func(*gin.Context) {
data, err := pokemongotemplates.GetPokemons()
func (s *ApplicationServer) pageHandler() func(*gin.Context) {
data, err := pokemongotemplates.GetPokemons(pokemongotemplates.AllPokemonsURL)
if err != nil {
fmt.Println(err.Error())
}
@@ -20,10 +21,35 @@ func (s *ApplicationServer) pokemonPageHandler() func(*gin.Context) {
})
}
}
func (s *ApplicationServer) customPokemonPageHandler() func(*gin.Context) {
func (s *ApplicationServer) paginationPageHandler() func(*gin.Context) {
return func(c *gin.Context) {
c.HTML(http.StatusOK, "views/CustomPokemons.gohtml", pokemongotemplates.PageData{
requestURL := pokemongotemplates.PaginationURL
if newURL := c.Request.URL.Query(); newURL.Has("slug") {
requestURL = newURL["slug"][0]
}
data, err := pokemongotemplates.GetPokemons(requestURL)
if err != nil {
fmt.Println(err.Error())
}
c.HTML(http.StatusOK, "views/PaginationPokemons.gohtml", pokemongotemplates.PageData{
NavigationLinks: pokemongotemplates.NavigationLinks,
Data: data,
})
}
}
func (s *ApplicationServer) slugSendPaginationRequestHandler() func(*gin.Context) {
return func(c *gin.Context) {
var requestData pokemongotemplates.NextURL
if err := c.Bind(&requestData); err != nil {
c.Redirect(http.StatusFound, "/")
return
}
c.Redirect(http.StatusFound, fmt.Sprintf("/pagination/?slug=%s", url.QueryEscape(requestData.URL)))
}
}