@@ -47,26 +47,19 @@ func TibiaSpellsOverviewV3(c *gin.Context) {
4747 Information Information `json:"information"`
4848 }
4949
50- // Sanatize of vocation value
51- vocation = strings .ToLower (vocation )
52- if len (vocation ) > 0 {
53- if strings .EqualFold (vocation , "knight" ) || strings .EqualFold (vocation , "knights" ) {
54- vocation = strings .Title ("knight" )
55- } else if strings .EqualFold (vocation , "paladin" ) || strings .EqualFold (vocation , "paladins" ) {
56- vocation = strings .Title ("paladin" )
57- } else if strings .EqualFold (vocation , "sorcerer" ) || strings .EqualFold (vocation , "sorcerers" ) {
58- vocation = strings .Title ("sorcerer" )
59- } else if strings .EqualFold (vocation , "druid" ) || strings .EqualFold (vocation , "druids" ) {
60- vocation = strings .Title ("druid" )
61- } else {
62- vocation = ""
63- }
50+ // Sanitize of vocation input
51+ vocationName , _ := TibiaDataVocationValidator (vocation )
52+ if vocationName == "all" || vocationName == "none" {
53+ vocationName = ""
6454 } else {
65- vocation = ""
55+ // removes the last letter (s) from the string (required for spells page)
56+ vocationName = strings .TrimSuffix (vocationName , "s" )
57+ // setting string to first upper case
58+ vocationName = strings .Title (vocationName )
6659 }
6760
6861 // Getting data with TibiadataHTMLDataCollectorV3
69- BoxContentHTML := TibiadataHTMLDataCollectorV3 ("https://www.tibia.com/library/?subtopic=spells&vocation=" + TibiadataQueryEscapeStringV3 (vocation ))
62+ BoxContentHTML := TibiadataHTMLDataCollectorV3 ("https://www.tibia.com/library/?subtopic=spells&vocation=" + TibiadataQueryEscapeStringV3 (vocationName ))
7063
7164 // Loading HTML data into ReaderHTML for goquery with NewReader
7265 ReaderHTML , err := goquery .NewDocumentFromReader (strings .NewReader (BoxContentHTML ))
@@ -143,15 +136,15 @@ func TibiaSpellsOverviewV3(c *gin.Context) {
143136 })
144137
145138 // adding readable SpellsVocationFilter field
146- if vocation == "" {
147- vocation = "none "
139+ if vocationName == "" {
140+ vocationName = "all "
148141 }
149142
150143 //
151144 // Build the data-blob
152145 jsonData := JSONData {
153146 Spells {
154- SpellsVocationFilter : vocation ,
147+ SpellsVocationFilter : vocationName ,
155148 Spells : SpellsData ,
156149 },
157150 Information {
0 commit comments