Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/validation/highscore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
var (
// validHighscoreCategories stores all valid highscore categories
validHighscoreCategories = func() *cimap.CaseInsensitiveMap[bool] {
m := cimap.New[bool](38)
for _, v := range []string{"achievements", "achievement", "axe", "axefighting", "charm", "charms", "charmpoints", "charmspoints", "club", "clubfighting", "distance", "distancefighting", "fishing", "fist", "fistfighting", "goshnar", "goshnars", "goshnarstaint", "loyalty", "loyaltypoints", "magic", "mlvl", "magiclevel", "shielding", "shield", "sword", "swordfighting", "drome", "dromescore", "experience", "boss", "bosses", "bosspoints", "bountypoints", "bountypoint", "bountypointsearned", "weeklytasks", "weeklytask", "weeklytaskscompleted"} {
m := cimap.New[bool](41)
for _, v := range []string{"achievements", "achievement", "axe", "axefighting", "charm", "charms", "charmpoints", "charmspoints", "club", "clubfighting", "distance", "distancefighting", "fishing", "fist", "fistfighting", "goshnar", "goshnars", "goshnarstaint", "loyalty", "loyaltypoints", "magic", "mlvl", "magiclevel", "shielding", "shield", "sword", "swordfighting", "drome", "dromescore", "experience", "boss", "bosses", "bosspoints", "bountypoints", "bountypoint", "bountypointsearned", "weeklytasks", "weeklytask", "weeklytaskscompleted", "phosphorusrecord", "phosphorus", "phosphorusrecords"} {
m.Add(v, true)
}
return m
Expand Down Expand Up @@ -48,11 +48,12 @@ const (
HighScoreBosspoints
HighScoreBountypoints
HighScoreWeeklytasks
HighScorePhosphorusrecord
)

func (hc HighscoreCategory) String() (string, error) {
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints", "bountypoints", "weeklytasks"}
if hc < HighScoreAchievements || hc > HighScoreWeeklytasks {
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints", "bountypoints", "weeklytasks", "phosphorusrecord"}
if hc < HighScoreAchievements || hc > HighScorePhosphorusrecord {
return "", errors.New("invalid HighscoreCategory value")
}
return seasons[hc-1], nil
Expand Down Expand Up @@ -94,6 +95,8 @@ func HighscoreCategoryFromString(input string) HighscoreCategory {
return HighScoreBountypoints
case "weeklytasks", "weeklytask", "weeklytaskscompleted":
return HighScoreWeeklytasks
case "phosphorusrecord", "phosphorus", "phosphorusrecords":
return HighScorePhosphorusrecord
default:
return HighScoreExperience
}
Expand Down
14 changes: 14 additions & 0 deletions src/validation/highscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func TestHighscoreCategoryWeeklytasksString(t *testing.T) {
assert.Equal(HighscoreCategory(17), highscoreCategory)
}

func TestHighscoreCategoryPhosphorusrecordString(t *testing.T) {
assert := assert.New(t)
highscoreCategory := HighScorePhosphorusrecord
stringValue, err := highscoreCategory.String()

assert.Nil(err)
assert.Equal("phosphorusrecord", stringValue)
assert.Equal(HighscoreCategory(18), highscoreCategory)
}

func TestHighscoreCategoryInvalidValueString(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -153,6 +163,10 @@ func TestHighscoreCategoryFromString(t *testing.T) {
inputs: []string{"weeklytasks", "weeklytask", "weeklytaskscompleted"},
expected: HighScoreWeeklytasks,
},
"Phosphorusrecord": {
inputs: []string{"phosphorusrecord", "phosphorus", "phosphorusrecords"},
expected: HighScorePhosphorusrecord,
},
}

for category, data := range categoryTests {
Expand Down
2 changes: 1 addition & 1 deletion src/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func tibiaGuildsOverview(c *gin.Context) {
// @Accept json
// @Produce json
// @Param world path string true "The world" default(all) extensions(x-example=Antica)
// @Param category path string true "The category" default(experience) Enums(achievements, axefighting, charmpoints, clubfighting, distancefighting, experience, fishing, fistfighting, goshnarstaint, loyaltypoints, magiclevel, shielding, swordfighting, dromescore, bosspoints, bountypoints, weeklytasks) extensions(x-example=fishing)
// @Param category path string true "The category" default(experience) Enums(achievements, axefighting, charmpoints, clubfighting, distancefighting, experience, fishing, fistfighting, goshnarstaint, loyaltypoints, magiclevel, shielding, swordfighting, dromescore, bosspoints, bountypoints, weeklytasks, phosphorusrecord) extensions(x-example=fishing)
// @Param vocation path string true "The vocation" default(all) Enums(all, knights, paladins, sorcerers, druids, monks) extensions(x-example=all)
// @Param page path int true "The current page" default(1) minimum(1) extensions(x-example=1)
// @Success 200 {object} HighscoresResponse
Expand Down