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
12 changes: 9 additions & 3 deletions src/validation/highscore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var (
// validHighscoreCatregories stores all valid highscore categories
validHighscoreCategories = []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"}
validHighscoreCategories = []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"}
)

// IsHighscoreCategoryValid reports wheter the provided string represents a valid highscore category
Expand Down Expand Up @@ -40,11 +40,13 @@ const (
HighScoreSwordfighting
HighScoreDromescore
HighScoreBosspoints
HighScoreBountypoints
HighScoreWeeklytasks
)

func (hc HighscoreCategory) String() (string, error) {
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints"}
if hc < HighScoreAchievements || hc > HighScoreBosspoints {
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints", "bountypoints", "weeklytasks"}
if hc < HighScoreAchievements || hc > HighScoreWeeklytasks {
return "", errors.New("invalid HighscoreCategory value")
}
return seasons[hc-1], nil
Expand Down Expand Up @@ -82,6 +84,10 @@ func HighscoreCategoryFromString(input string) HighscoreCategory {
return HighScoreDromescore
case "boss", "bosses", "bosspoints":
return HighScoreBosspoints
case "bountypoints", "bountypoint", "bountypointsearned":
return HighScoreBountypoints
case "weeklytasks", "weeklytask", "weeklytaskscompleted":
return HighScoreWeeklytasks
default:
return HighScoreExperience
}
Expand Down
28 changes: 28 additions & 0 deletions src/validation/highscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ func TestHighscoreCategoryBosspointsString(t *testing.T) {
assert.Equal(HighscoreCategory(15), highscoreCategory)
}

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

assert.Nil(err)
assert.Equal("bountypoints", stringValue)
assert.Equal(HighscoreCategory(16), highscoreCategory)
}

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

assert.Nil(err)
assert.Equal("weeklytasks", stringValue)
assert.Equal(HighscoreCategory(17), highscoreCategory)
}

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

Expand Down Expand Up @@ -125,6 +145,14 @@ func TestHighscoreCategoryFromString(t *testing.T) {
inputs: []string{"boss", "bosses", "bosspoints"},
expected: HighScoreBosspoints,
},
"Bountypoints": {
inputs: []string{"bountypoints", "bountypoint", "bountypointsearned"},
expected: HighscoreBountypoints,
},
"Weeklytasks": {
inputs: []string{"weeklytasks", "weeklytask", "weeklytaskscompleted"},
expected: HighscoreWeeklytasks,
},
}

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 @@ -499,7 +499,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) 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) 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