Functional demo

This commit is contained in:
Eden Kirin
2024-01-21 18:09:02 +01:00
parent 728d37faba
commit 412c520bf9
5 changed files with 375 additions and 168 deletions

View File

@ -2,8 +2,10 @@ package handlers
import (
"strconv"
"strings"
"templ-tests/app/data"
"templ-tests/app/templates"
"templ-tests/app/types"
"github.com/gin-gonic/gin"
)
@ -25,3 +27,26 @@ func InteractiveSwapContent(c *gin.Context) {
}
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)
}