Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Game Server Go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Akamu
Game Server Go
Commits
14a2d51f
Commit
14a2d51f
authored
Dec 31, 2020
by
Julien Schröter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit finished duels when querying all of an users duels
parent
11129889
Pipeline
#2280
passed with stage
in 1 minute and 43 seconds
Changes
5
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
11 deletions
+26
-11
appapi.yaml
appapi.yaml
+9
-0
endpoint/duel/endpoint.go
endpoint/duel/endpoint.go
+8
-7
endpoint/duel/request.go
endpoint/duel/request.go
+5
-0
test/duel_test.go
test/duel_test.go
+1
-1
test/e2e/duelendpoint_test.go
test/e2e/duelendpoint_test.go
+3
-3
No files found.
appapi.yaml
View file @
14a2d51f
...
...
@@ -497,6 +497,13 @@ paths:
schema
:
type
:
integer
format
:
uint32
-
name
:
c
description
:
Only works if querying all of an user's duels. Specifies the maximum count of finished duels to fetch. Defaults to 0, maximum is 30.
in
:
query
required
:
false
schema
:
type
:
integer
format
:
uint32
responses
:
'
200'
:
description
:
duel array of all the current user\'s running duels. If an id is specified, return that duel\'s full information.
...
...
@@ -506,6 +513,8 @@ paths:
type
:
array
items
:
$ref
:
'
#/components/schemas/duel'
'
400'
:
description
:
Mistake in request. May have tried to query more than the limit of non-running duels.
'
401'
:
description
:
Authentication failure.
content
:
...
...
endpoint/duel/endpoint.go
View file @
14a2d51f
...
...
@@ -52,19 +52,20 @@ func SetupDuelRoutes(group *gin.RouterGroup, repository DuelQuery, titleReposito
func
getDuel
(
repository
DuelQuery
)
gin
.
HandlerFunc
{
return
func
(
ctx
*
gin
.
Context
)
{
var
idStruct
struct
{
ID
uint32
`form:"id" binding:"required"`
}
var
requestParams
getDuelsParameters
userID
,
err
:=
endpoint
.
GetUserID
(
ctx
)
if
err
!=
nil
{
return
}
e
:=
ctx
.
ShouldBindQuery
(
&
idStruct
)
if
e
==
nil
{
if
err
=
ctx
.
BindQuery
(
&
requestParams
);
err
!=
nil
{
return
}
if
requestParams
.
ID
>
0
{
// duel specified, return if from user
result
,
errDB
:=
repository
.
GetDuel
(
idStruct
.
ID
,
userID
)
result
,
errDB
:=
repository
.
GetDuel
(
requestParams
.
ID
,
userID
)
if
errDB
!=
nil
{
if
errDB
==
ErrNotPermitted
{
ctx
.
Status
(
http
.
StatusForbidden
)
...
...
@@ -82,7 +83,7 @@ func getDuel(repository DuelQuery) gin.HandlerFunc {
}
else
{
// No duel specified
// return all current duels of that user
result
,
errDB
:=
repository
.
GetAllDuels
(
userID
,
0
)
result
,
errDB
:=
repository
.
GetAllDuels
(
userID
,
requestParams
.
Count
)
if
errDB
!=
nil
{
raven
.
CaptureError
(
errDB
,
nil
)
ctx
.
Status
(
http
.
StatusInternalServerError
)
...
...
endpoint/duel/request.go
View file @
14a2d51f
...
...
@@ -6,6 +6,11 @@ import (
"gitlab.akamu.de/akamu/game-server-go/schemas"
)
type
getDuelsParameters
struct
{
ID
uint32
`form:"id"`
Count
uint32
`form:"c" binding:"min=0,max=10"`
}
type
postDuelAnswerParameters
struct
{
RoundID
uint32
`form:"round" binding:"required"`
QuestionID
uint32
`form:"question" binding:"required"`
...
...
test/duel_test.go
View file @
14a2d51f
...
...
@@ -315,7 +315,7 @@ func Test_getAllDuels200(t *testing.T) {
env1
.
Login
(
"user1"
,
"password1"
,
t
)
res1
:=
httptest
.
NewRecorder
()
req1
,
_
:=
env1
.
NewRequest
(
"GET"
,
"/duel"
,
nil
)
req1
,
_
:=
env1
.
NewRequest
(
"GET"
,
"/duel
?c=10
"
,
nil
)
router
.
ServeHTTP
(
res1
,
req1
)
...
...
test/e2e/duelendpoint_test.go
View file @
14a2d51f
...
...
@@ -106,7 +106,7 @@ func testGetUser1_200(router *gin.Engine) func(t *testing.T) {
env
.
Login
(
"user1"
,
"Password1"
,
t
)
res
:=
httptest
.
NewRecorder
()
req
,
_
:=
env
.
New
Request
(
"GET"
,
"/duel"
,
nil
)
req
,
_
:=
env
.
New
ParameterRequest
(
"GET"
,
"/duel"
,
map
[
string
]
string
{
"c"
:
"10"
}
,
nil
)
router
.
ServeHTTP
(
res
,
req
)
...
...
@@ -128,7 +128,7 @@ func testGetUser2_200(router *gin.Engine) func(t *testing.T) {
env
.
Login
(
"user2"
,
"Password2"
,
t
)
res
:=
httptest
.
NewRecorder
()
req
,
_
:=
env
.
New
Request
(
"GET"
,
"/duel"
,
nil
)
req
,
_
:=
env
.
New
ParameterRequest
(
"GET"
,
"/duel"
,
map
[
string
]
string
{
"c"
:
"10"
}
,
nil
)
router
.
ServeHTTP
(
res
,
req
)
...
...
@@ -150,7 +150,7 @@ func testGetUser3_200(router *gin.Engine) func(t *testing.T) {
env
.
Login
(
"user3"
,
"Password3"
,
t
)
responseFile
:=
"duel/getUser3_200.json.template"
req
,
_
:=
env
.
New
Request
(
"GET"
,
"/duel"
,
nil
)
req
,
_
:=
env
.
New
ParameterRequest
(
"GET"
,
"/duel"
,
map
[
string
]
string
{
"c"
:
"10"
}
,
nil
)
executeAndAssertJSONOk
(
t
,
router
,
req
,
responseFile
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment