Skip to content

Commit

Permalink
Merge pull request #646 from santiaago/refactorTeamRankingCtrl
Browse files Browse the repository at this point in the history
refactor team Ranking controller
  • Loading branch information
rjourde committed Jun 4, 2015
2 parents ece43eb + b726bfb commit 2ca437d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions controllers/teams/ranking.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,27 @@ func Ranking(w http.ResponseWriter, r *http.Request, u *mdl.User) error {

var t *mdl.Team
var err error
t, err = extract.Team()
if err != nil {
return err
if t, err = extract.Team(); err != nil {
return &helpers.InternalServerError{Err: err}
}

log.Infof(c, "%s ready to build a user array", desc)
users := t.RankingByUser(c, 50)

fieldsToKeep := []string{"Id", "Username", "Alias", "Score"}
usersJson := make([]mdl.UserJson, len(users))
helpers.TransformFromArrayOfPointers(&users, &usersJson, fieldsToKeep)
vm := buildTeamRankingViewModel(users)

data := struct {
Users []mdl.UserJson
}{
usersJson,
}
return templateshlp.RenderJson(w, c, vm)
}

type teamRankingViewModel struct {
Users []mdl.UserJson
}

func buildTeamRankingViewModel(users []*mdl.User) teamRankingViewModel {
fieldsToKeep := []string{"Id", "Username", "Alias", "Score"}
u := make([]mdl.UserJson, len(users))
helpers.TransformFromArrayOfPointers(&users, &u, fieldsToKeep)

return templateshlp.RenderJson(w, c, data)
return teamRankingViewModel{u}

}

0 comments on commit 2ca437d

Please sign in to comment.