Functional demo
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user