53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"templ-tests/app/data"
|
|
"templ-tests/app/templates"
|
|
"templ-tests/app/types"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var pcInteractive templates.PageContext = templates.PageContext{
|
|
Title: "Welcome to the demo",
|
|
ActivePage: "interactive",
|
|
}
|
|
|
|
func Interactive(c *gin.Context) {
|
|
templates.Interactive(pcInteractive, data.CatBreeds).Render(c, c.Writer)
|
|
}
|
|
|
|
func InteractiveSwapContent(c *gin.Context) {
|
|
contentIndexStr := c.Query("content")
|
|
contentIndex, err := strconv.Atoi(contentIndexStr)
|
|
if err != nil {
|
|
contentIndex = 0
|
|
}
|
|
templates.InteractiveSwapContent(pcInteractive, contentIndex).Render(c, c.Writer)
|
|
}
|
|
|
|
func FilterCatBreeds(c *gin.Context) {
|
|
breedQuery := strings.ToLower(c.Query("breed"))
|
|
countryQuery := c.Query("country")
|
|
|
|
var catBreeds []types.CatBreed = []types.CatBreed{}
|
|
|
|
for _, cb := range data.CatBreeds {
|
|
appendToList :=
|
|
(len(breedQuery) > 0 &&
|
|
strings.Contains(strings.ToLower(cb.Breed), breedQuery) ||
|
|
len(breedQuery) == 0) &&
|
|
((len(countryQuery) > 0 &&
|
|
cb.Country == countryQuery) ||
|
|
len(countryQuery) == 0)
|
|
|
|
if appendToList {
|
|
catBreeds = append(catBreeds, cb)
|
|
}
|
|
}
|
|
|
|
templates.RenderCatBreedsTable(catBreeds).Render(c, c.Writer)
|
|
}
|