refactor: tribe - use score* and points fields instead of rank* fields for sorting (#64)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#64
This commit is contained in:
parent
4829bae6a2
commit
aa2b3a25d8
|
@ -182,14 +182,14 @@ func tribeSortByToColumn(sortBy domain.TribeSortBy) (string, error) {
|
|||
switch sortBy {
|
||||
case domain.TribeSortByID:
|
||||
return "id", nil
|
||||
case domain.TribeSortByRankAtt:
|
||||
return "rank_att", nil
|
||||
case domain.TribeSortByRankDef:
|
||||
return "rank_def", nil
|
||||
case domain.TribeSortByRankTotal:
|
||||
return "rank_total", nil
|
||||
case domain.TribeSortByRank:
|
||||
return "rank", nil
|
||||
case domain.TribeSortByScoreAtt:
|
||||
return "score_att", nil
|
||||
case domain.TribeSortByScoreDef:
|
||||
return "score_def", nil
|
||||
case domain.TribeSortByScoreTotal:
|
||||
return "score_total", nil
|
||||
case domain.TribeSortByPoints:
|
||||
return "points", nil
|
||||
case domain.TribeSortByDominance:
|
||||
return "dominance", nil
|
||||
case domain.TribeSortByDeletedAt:
|
||||
|
|
|
@ -368,7 +368,7 @@ func TestTribe_List(t *testing.T) {
|
|||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=Rank,Direction=DESC}],Limit=1,Count=true",
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=Points,Direction=ASC}],Limit=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
|
@ -377,7 +377,56 @@ func TestTribe_List(t *testing.T) {
|
|||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByRank,
|
||||
By: domain.TribeSortByPoints,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
},
|
||||
Count: true,
|
||||
},
|
||||
expectedTribes: []expectedTribe{
|
||||
{
|
||||
id: 1,
|
||||
serverKey: "pl169",
|
||||
},
|
||||
},
|
||||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreAtt,Direction=DESC}],Limit=1,Offset=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
Pagination: domain.Pagination{
|
||||
Limit: 1,
|
||||
Offset: 1,
|
||||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByScoreAtt,
|
||||
Direction: domain.SortDirectionDESC,
|
||||
},
|
||||
},
|
||||
Count: true,
|
||||
},
|
||||
expectedTribes: []expectedTribe{
|
||||
{
|
||||
id: 27,
|
||||
serverKey: "pl169",
|
||||
},
|
||||
},
|
||||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreDef,Direction=DESC}],Limit=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
Pagination: domain.Pagination{
|
||||
Limit: 1,
|
||||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByScoreDef,
|
||||
Direction: domain.SortDirectionDESC,
|
||||
},
|
||||
},
|
||||
|
@ -392,32 +441,7 @@ func TestTribe_List(t *testing.T) {
|
|||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=RankAtt,Direction=ASC}],Limit=1,Offset=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
Pagination: domain.Pagination{
|
||||
Limit: 1,
|
||||
Offset: 1,
|
||||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByRankAtt,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
},
|
||||
Count: true,
|
||||
},
|
||||
expectedTribes: []expectedTribe{
|
||||
{
|
||||
id: 27,
|
||||
serverKey: "pl169",
|
||||
},
|
||||
},
|
||||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=RankDef,Direction=ASC}],Limit=1,Count=true",
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreTotal,Direction=DESC}],Limit=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
|
@ -426,32 +450,8 @@ func TestTribe_List(t *testing.T) {
|
|||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByRankDef,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
},
|
||||
Count: true,
|
||||
},
|
||||
expectedTribes: []expectedTribe{
|
||||
{
|
||||
id: 1,
|
||||
serverKey: "pl169",
|
||||
},
|
||||
},
|
||||
expectedCount: 4,
|
||||
},
|
||||
{
|
||||
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=RankTotal,Direction=ASC}],Limit=1,Count=true",
|
||||
params: domain.ListTribesParams{
|
||||
ServerKeys: []string{"pl169"},
|
||||
IDs: []int64{1, 2, 27, 28},
|
||||
Pagination: domain.Pagination{
|
||||
Limit: 1,
|
||||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{
|
||||
By: domain.TribeSortByRankTotal,
|
||||
Direction: domain.SortDirectionASC,
|
||||
By: domain.TribeSortByScoreTotal,
|
||||
Direction: domain.SortDirectionDESC,
|
||||
},
|
||||
},
|
||||
Count: true,
|
||||
|
@ -530,7 +530,7 @@ func TestTribe_List(t *testing.T) {
|
|||
name: "ERR: unsupported sort direction",
|
||||
params: domain.ListTribesParams{
|
||||
Sort: []domain.TribeSort{
|
||||
{By: domain.TribeSortByRankAtt, Direction: 100},
|
||||
{By: domain.TribeSortByScoreAtt, Direction: 100},
|
||||
},
|
||||
},
|
||||
expectedTribes: nil,
|
||||
|
|
|
@ -42,10 +42,10 @@ type TribeSortBy uint8
|
|||
|
||||
const (
|
||||
TribeSortByID TribeSortBy = iota
|
||||
TribeSortByRankAtt
|
||||
TribeSortByRankDef
|
||||
TribeSortByRankTotal
|
||||
TribeSortByRank
|
||||
TribeSortByScoreAtt
|
||||
TribeSortByScoreDef
|
||||
TribeSortByScoreTotal
|
||||
TribeSortByPoints
|
||||
TribeSortByDominance
|
||||
TribeSortByDeletedAt
|
||||
)
|
||||
|
@ -54,14 +54,14 @@ func NewTribeSortBy(s string) (TribeSortBy, error) {
|
|||
switch s {
|
||||
case "id":
|
||||
return TribeSortByID, nil
|
||||
case "rankAtt":
|
||||
return TribeSortByRankAtt, nil
|
||||
case "rankDef":
|
||||
return TribeSortByRankDef, nil
|
||||
case "rankTotal":
|
||||
return TribeSortByRankTotal, nil
|
||||
case "rank":
|
||||
return TribeSortByRank, nil
|
||||
case "scoreAtt":
|
||||
return TribeSortByScoreAtt, nil
|
||||
case "scoreDef":
|
||||
return TribeSortByScoreDef, nil
|
||||
case "scoreTotal":
|
||||
return TribeSortByScoreTotal, nil
|
||||
case "points":
|
||||
return TribeSortByPoints, nil
|
||||
case "dominance":
|
||||
return TribeSortByDominance, nil
|
||||
case "deletedAt":
|
||||
|
|
|
@ -23,20 +23,20 @@ func TestNewTribeSortBy(t *testing.T) {
|
|||
output: domain.TribeSortByID,
|
||||
},
|
||||
{
|
||||
s: "rankAtt",
|
||||
output: domain.TribeSortByRankAtt,
|
||||
s: "scoreAtt",
|
||||
output: domain.TribeSortByScoreAtt,
|
||||
},
|
||||
{
|
||||
s: "rankDef",
|
||||
output: domain.TribeSortByRankDef,
|
||||
s: "scoreDef",
|
||||
output: domain.TribeSortByScoreDef,
|
||||
},
|
||||
{
|
||||
s: "rankTotal",
|
||||
output: domain.TribeSortByRankTotal,
|
||||
s: "scoreTotal",
|
||||
output: domain.TribeSortByScoreTotal,
|
||||
},
|
||||
{
|
||||
s: "rank",
|
||||
output: domain.TribeSortByRank,
|
||||
s: "points",
|
||||
output: domain.TribeSortByPoints,
|
||||
},
|
||||
{
|
||||
s: "dominance",
|
||||
|
|
|
@ -41,7 +41,7 @@ type tribe struct {
|
|||
// @Param deleted query boolean false "true=only deleted tribes, false=only existing tribes, by default both existing and deleted tribes are returned"
|
||||
// @Param offset query int false "specifies where to start a page" minimum(0) default(0)
|
||||
// @Param limit query int false "page size" minimum(1) maximum(2000) default(2000)
|
||||
// @Param sort query []string false "format: field:direction, default: [id:asc]" Enums(id:asc,id:desc,rankAtt:asc,rankAtt:desc,rankDef:asc,rankDef:desc,rankTotal:asc,rankTotal:desc,rank:asc,rank:desc,dominance:asc,dominance:desc,deletedAt:asc,deletedAt:desc)
|
||||
// @Param sort query []string false "format: field:direction, default: [id:asc]" Enums(id:asc,id:desc,scoreAtt:asc,scoreAtt:desc,scoreDef:asc,scoreDef:desc,scoreTotal:asc,scoreTotal:desc,points:asc,points:desc,dominance:asc,dominance:desc,deletedAt:asc,deletedAt:desc)
|
||||
// @Router /versions/{versionCode}/servers/{serverKey}/tribes [get]
|
||||
func (t *tribe) list(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
|
|
|
@ -188,7 +188,7 @@ func TestTribe_list(t *testing.T) {
|
|||
expectedTotalCount: "2",
|
||||
},
|
||||
{
|
||||
name: "OK: sort=[id:asc,rankDef:desc,rankTotal:asc]",
|
||||
name: "OK: sort=[id:asc,scoreDef:desc,scoreTotal:asc]",
|
||||
setup: func(versionSvc *mock.FakeVersionService, serverSvc *mock.FakeServerService, tribeSvc *mock.FakeTribeService) {
|
||||
versionSvc.GetByCodeReturns(version, nil)
|
||||
serverSvc.GetNormalByVersionCodeAndKeyReturns(server, nil)
|
||||
|
@ -209,11 +209,11 @@ func TestTribe_list(t *testing.T) {
|
|||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
{
|
||||
By: domain.TribeSortByRankDef,
|
||||
By: domain.TribeSortByScoreDef,
|
||||
Direction: domain.SortDirectionDESC,
|
||||
},
|
||||
{
|
||||
By: domain.TribeSortByRankTotal,
|
||||
By: domain.TribeSortByScoreTotal,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
},
|
||||
|
@ -283,7 +283,7 @@ func TestTribe_list(t *testing.T) {
|
|||
versionCode: version.Code,
|
||||
key: server.Key,
|
||||
queryParams: url.Values{
|
||||
"sort": []string{"id:asc", "rankDef:desc", "rankTotal:asc"},
|
||||
"sort": []string{"id:asc", "scoreDef:desc", "scoreTotal:asc"},
|
||||
},
|
||||
expectedStatus: 200,
|
||||
target: &model.ListTribesResp{},
|
||||
|
|
|
@ -46,6 +46,9 @@ func (p *Player) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
Valid: true,
|
||||
Bool: false,
|
||||
},
|
||||
Sort: []domain.PlayerSort{
|
||||
{By: domain.PlayerSortByID, Direction: domain.SortDirectionASC},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("PlayerRepository.List: %w", err)
|
||||
|
@ -74,6 +77,7 @@ func (p *Player) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
}
|
||||
playersToDelete = append(playersToDelete, existing.ID)
|
||||
}
|
||||
|
||||
err = p.repo.DeleteByID(ctx, playersToDelete...)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("PlayerRepository.DeleteByID: %w", err)
|
||||
|
|
|
@ -47,6 +47,9 @@ func (t *Tribe) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
Valid: true,
|
||||
Bool: false,
|
||||
},
|
||||
Sort: []domain.TribeSort{
|
||||
{By: domain.TribeSortByID, Direction: domain.SortDirectionASC},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("TribeRepository.List: %w", err)
|
||||
|
@ -75,6 +78,7 @@ func (t *Tribe) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
}
|
||||
tribesToDelete = append(tribesToDelete, existing.ID)
|
||||
}
|
||||
|
||||
err = t.repo.DeleteByID(ctx, tribesToDelete...)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("TribeRepository.DeleteByID: %w", err)
|
||||
|
|
|
@ -154,7 +154,7 @@ func TestTribe_List(t *testing.T) {
|
|||
name: "custom sort",
|
||||
limit: 0,
|
||||
sort: []domain.TribeSort{
|
||||
{By: domain.TribeSortByRank, Direction: domain.SortDirectionDESC},
|
||||
{By: domain.TribeSortByPoints, Direction: domain.SortDirectionDESC},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -270,15 +270,15 @@ func TestTribe_List(t *testing.T) {
|
|||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
{
|
||||
By: domain.TribeSortByRankDef,
|
||||
By: domain.TribeSortByScoreDef,
|
||||
Direction: domain.SortDirectionDESC,
|
||||
},
|
||||
{
|
||||
By: domain.TribeSortByRankTotal,
|
||||
By: domain.TribeSortByScoreTotal,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
{
|
||||
By: domain.TribeSortByRankAtt,
|
||||
By: domain.TribeSortByScoreAtt,
|
||||
Direction: domain.SortDirectionASC,
|
||||
},
|
||||
},
|
||||
|
|
Reference in New Issue
Block a user