refactor: change max limit to 500 for all models
ci/woodpecker/push/govulncheck Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details

This commit is contained in:
Dawid Wysokiński 2024-03-11 08:16:29 +01:00
parent b2fa484902
commit fc5f531ce7
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
18 changed files with 61 additions and 38 deletions

View File

@ -36,12 +36,12 @@ generate: install-oapi-codegen
.PHONY: create-job-sync-data .PHONY: create-job-sync-data
create-job-sync-data: create-job-sync-data:
kubectl create job --from=cronjob/twhelp-job-sync-data-dev "twhelp-job-sync-data-$(shell openssl rand -hex 10)" @kubectl create job --from=cronjob/twhelp-job-sync-data-dev "twhelp-job-sync-data-$(shell openssl rand -hex 10)"
.PHONY: create-job-sync-ennoblements .PHONY: create-job-sync-ennoblements
create-job-sync-ennoblements: create-job-sync-ennoblements:
kubectl create job --from=cronjob/twhelp-job-sync-ennoblements-dev "twhelp-job-sync-ennoblements-$(shell openssl rand -hex 10)" @kubectl create job --from=cronjob/twhelp-job-sync-ennoblements-dev "twhelp-job-sync-ennoblements-$(shell openssl rand -hex 10)"
.PHONY: create-job-create-snapshots .PHONY: create-job-create-snapshots
create-job-create-snapshots: create-job-create-snapshots:
kubectl create job --from=cronjob/twhelp-job-create-snapshots-dev "twhelp-job-create-snapshots-$(shell openssl rand -hex 10)" @kubectl create job --from=cronjob/twhelp-job-create-snapshots-dev "twhelp-job-create-snapshots-$(shell openssl rand -hex 10)"

View File

@ -1328,6 +1328,8 @@ components:
schema: schema:
type: integer type: integer
minimum: 1 minimum: 1
default: 500
maximum: 500
required: false required: false
ServerOpenQueryParam: ServerOpenQueryParam:
name: open name: open

View File

@ -78,6 +78,25 @@ func (repo *EnnoblementBunRepository) ListWithRelations(
) (domain.ListEnnoblementsWithRelationsResult, error) { ) (domain.ListEnnoblementsWithRelationsResult, error) {
var ennoblements bunmodel.Ennoblements var ennoblements bunmodel.Ennoblements
fmt.Println(repo.db.NewSelect().
Model(&ennoblements).
Apply(listEnnoblementsParamsApplier{params: params}.apply).
Relation("Village", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column(bunmodel.VillageMetaColumns...)
}).
Relation("NewOwner", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column(bunmodel.PlayerMetaColumns...)
}).
Relation("NewTribe", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column(bunmodel.TribeMetaColumns...)
}).
Relation("OldOwner", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column(bunmodel.PlayerMetaColumns...)
}).
Relation("OldTribe", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column(bunmodel.TribeMetaColumns...)
}).String())
if err := repo.db.NewSelect(). if err := repo.db.NewSelect().
Model(&ennoblements). Model(&ennoblements).
Apply(listEnnoblementsParamsApplier{params: params}.apply). Apply(listEnnoblementsParamsApplier{params: params}.apply).

View File

@ -128,7 +128,7 @@ func testPlayerRepository(t *testing.T, newRepos func(t *testing.T) repositories
) )
})) }))
assert.False(t, res.Self().IsZero()) assert.False(t, res.Self().IsZero())
assert.False(t, res.Next().IsZero()) assert.True(t, res.Next().IsZero())
}, },
assertError: func(t *testing.T, err error) { assertError: func(t *testing.T, err error) {
t.Helper() t.Helper()

View File

@ -360,7 +360,7 @@ type ListEnnoblementsParams struct {
} }
const ( const (
EnnoblementListMaxLimit = 200 EnnoblementListMaxLimit = 500
listEnnoblementsParamsModelName = "ListEnnoblementsParams" listEnnoblementsParamsModelName = "ListEnnoblementsParams"
) )

View File

@ -830,7 +830,7 @@ type ListPlayersParams struct {
} }
const ( const (
PlayerListMaxLimit = 200 PlayerListMaxLimit = 500
listPlayersParamsModelName = "ListPlayersParams" listPlayersParamsModelName = "ListPlayersParams"
) )

View File

@ -228,7 +228,7 @@ func (s PlayerSnapshotSort) String() string {
} }
} }
const PlayerSnapshotListMaxLimit = 200 const PlayerSnapshotListMaxLimit = 500
type ListPlayerSnapshotsParams struct { type ListPlayerSnapshotsParams struct {
serverKeys []string serverKeys []string

View File

@ -749,7 +749,7 @@ type ListTribesParams struct {
} }
const ( const (
TribeListMaxLimit = 200 TribeListMaxLimit = 500
listTribesParamsModelName = "ListTribesParams" listTribesParamsModelName = "ListTribesParams"
) )

View File

@ -249,7 +249,7 @@ type ListTribeChangesParams struct {
} }
const ( const (
TribeChangeListMaxLimit = 200 TribeChangeListMaxLimit = 500
listTribeChangesParamsModelName = "ListTribeChangesParams" listTribeChangesParamsModelName = "ListTribeChangesParams"
) )

View File

@ -262,7 +262,7 @@ type ListTribeSnapshotsParams struct {
} }
const ( const (
TribeSnapshotListMaxLimit = 200 TribeSnapshotListMaxLimit = 500
listTribeSnapshotsParamsModelName = "ListTribeSnapshotsParams" listTribeSnapshotsParamsModelName = "ListTribeSnapshotsParams"
) )

View File

@ -189,7 +189,7 @@ type ListVersionsParams struct {
} }
const ( const (
VersionListMaxLimit = 200 VersionListMaxLimit = 500
listVersionsParamsModelName = "ListVersionsParams" listVersionsParamsModelName = "ListVersionsParams"
) )

View File

@ -1,6 +1,7 @@
package port package port
import ( import (
"fmt"
"net/http" "net/http"
"gitea.dwysokinski.me/twhelp/corev3/internal/domain" "gitea.dwysokinski.me/twhelp/corev3/internal/domain"
@ -42,6 +43,7 @@ func (h *apiHTTPHandler) ListEnnoblements(
res, err := h.ennoblementSvc.ListWithRelations(r.Context(), domainParams) res, err := h.ennoblementSvc.ListWithRelations(r.Context(), domainParams)
if err != nil { if err != nil {
fmt.Println(err)
h.errorRenderer.render(w, r, err) h.errorRenderer.render(w, r, err)
return return
} }

View File

@ -168,11 +168,11 @@ func TestListEnnoblements(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 200", name: fmt.Sprintf("ERR: limit > %d", domain.EnnoblementListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "201") q.Set("limit", strconv.Itoa(domain.EnnoblementListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -185,7 +185,7 @@ func TestListEnnoblements(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 200, Max: domain.EnnoblementListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{

View File

@ -321,11 +321,11 @@ func TestListPlayers(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 200", name: fmt.Sprintf("ERR: limit > %d", domain.PlayerListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "201") q.Set("limit", strconv.Itoa(domain.PlayerListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -338,7 +338,7 @@ func TestListPlayers(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 200, Max: domain.PlayerListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{
@ -980,11 +980,11 @@ func TestListTribeMembers(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 200", name: fmt.Sprintf("ERR: limit > %d", domain.PlayerListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "201") q.Set("limit", strconv.Itoa(domain.PlayerListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -997,7 +997,7 @@ func TestListTribeMembers(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 200, Max: domain.PlayerListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{

View File

@ -218,11 +218,11 @@ func TestListServers(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 500", name: fmt.Sprintf("ERR: limit > %d", domain.ServerListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "501") q.Set("limit", strconv.Itoa(domain.ServerListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -235,7 +235,7 @@ func TestListServers(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 500, Max: domain.ServerListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{

View File

@ -321,11 +321,11 @@ func TestListTribes(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 200", name: fmt.Sprintf("ERR: limit > %d", domain.TribeListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "201") q.Set("limit", strconv.Itoa(domain.TribeListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -338,7 +338,7 @@ func TestListTribes(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 200, Max: domain.TribeListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{

View File

@ -166,11 +166,11 @@ func TestListVersions(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 200", name: fmt.Sprintf("ERR: limit > %d", domain.VersionListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "201") q.Set("limit", strconv.Itoa(domain.VersionListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -183,7 +183,7 @@ func TestListVersions(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 200, Max: domain.VersionListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{

View File

@ -205,11 +205,11 @@ func TestListVillages(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 500", name: fmt.Sprintf("ERR: limit > %d", domain.VillageListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "501") q.Set("limit", strconv.Itoa(domain.VillageListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -222,7 +222,7 @@ func TestListVillages(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 500, Max: domain.VillageListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{
@ -649,11 +649,11 @@ func TestListPlayerVillages(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 500", name: fmt.Sprintf("ERR: limit > %d", domain.VillageListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "501") q.Set("limit", strconv.Itoa(domain.VillageListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -666,7 +666,7 @@ func TestListPlayerVillages(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 500, Max: domain.VillageListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{
@ -1062,11 +1062,11 @@ func TestListTribeVillages(t *testing.T) {
}, },
}, },
{ {
name: "ERR: limit > 500", name: fmt.Sprintf("ERR: limit > %d", domain.VillageListMaxLimit),
reqModifier: func(t *testing.T, req *http.Request) { reqModifier: func(t *testing.T, req *http.Request) {
t.Helper() t.Helper()
q := req.URL.Query() q := req.URL.Query()
q.Set("limit", "501") q.Set("limit", strconv.Itoa(domain.VillageListMaxLimit+1))
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
}, },
assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { assertResp: func(t *testing.T, req *http.Request, resp *http.Response) {
@ -1079,7 +1079,7 @@ func TestListTribeVillages(t *testing.T) {
limit, err := strconv.Atoi(req.URL.Query().Get("limit")) limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err) require.NoError(t, err)
domainErr := domain.MaxLessEqualError{ domainErr := domain.MaxLessEqualError{
Max: 500, Max: domain.VillageListMaxLimit,
Current: limit, Current: limit,
} }
assert.Equal(t, apimodel.ErrorResponse{ assert.Equal(t, apimodel.ErrorResponse{