Skip to content

Commit

Permalink
update: pagination for get user-matches
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoopesh369 committed Feb 2, 2024
1 parent fb38e43 commit 7d1234a
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 63 deletions.
121 changes: 117 additions & 4 deletions docs/spec/CodeCharacter-API.yml
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ paths:
schema:
type: array
items:
type: object
$ref: '#/components/schemas/Match'
examples:
Example:
value:
Expand All @@ -1016,8 +1016,19 @@ paths:
avatarId: 0
'401':
description: Unauthorized
operationId: getUserMatches
description: Get matches played by authenticated user
operationId: getUserNormalMatches
description: Get normal matches played by authenticated user
parameters:
- schema:
type: integer
in: query
name: page
description: Index of the page
- schema:
type: integer
in: query
name: size
description: Size of the page
parameters: []
post:
summary: Create match
Expand Down Expand Up @@ -1054,6 +1065,60 @@ paths:
opponentId: 0a4b34b0-6057-4b82-ae27-a59c36eab667
mapRevisionId: f52ddf9e-e933-471a-9250-41078cc39f80
codeRevisionId: d9eb9923-651b-4ec4-b6f1-b7625b2a9392
/user/pvpmatches:
get:
summary: Get user pvp matches
tags:
- match
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PvPMatch'
examples:
Example:
value:
- id: 497f6eca-6276-4993-bfeb-53cbbbba6f08
- game:
- id: 497f6eca-6276-4993-bfeb-53cbbbba6f08
scorePlayer1: 100
scorePlayer2: 45
status: IDLE
- matchMode: PVPSELF
- matchVerdict: PLAYER1
- createdAt: '2019-08-24T14:15:22Z'
- user1:
username: testUser
name: Test User
country: IN
college: NIT Trichy
avatarId: 0
- user2:
username: testUser
name: Test User
country: IN
college: NIT Trichy
avatarId: 0
'401':
description: Unauthorized
operationId: getUserPvPMatches
description: Get pvp matches played by authenticated user
parameters:
- schema:
type: integer
in: query
name: page
description: Index of the page
- schema:
type: integer
in: query
name: size
description: Size of the page
parameters: []
/user/notifications:
get:
summary: Get all notifications
Expand Down Expand Up @@ -1311,7 +1376,55 @@ paths:
value: "[[0,0,0]]"
tags:
- Daily Challenges

/dc/matches:
get:
summary: Get user daily challenge matches
tags:
- Daily Challenges
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Match'
examples:
Example:
value:
- id: 497f6eca-6276-4993-bfeb-53cbbbba6f08
games:
- id: 497f6eca-6276-4993-bfeb-53cbbbba6f08
coinsUsed: 100
destruction: 45
status: IDLE
matchMode: SELF
matchVerdict: SUCCESS
createdAt: '2019-08-24T14:15:22Z'
user1:
username: testUser
name: Test User
country: IN
college: NIT Trichy
avatarId: 0
user2: null
'401':
description: Unauthorized
operationId: getUserDCMatches
description: Get daily-challenge matches played by authenticated user
parameters:
- schema:
type: integer
in: query
name: page
description: Index of the page
- schema:
type: integer
in: query
name: size
description: Size of the page
parameters: []

components:
schemas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import delta.codecharacter.dtos.DailyChallengeGetRequestDto
import delta.codecharacter.dtos.DailyChallengeLeaderBoardResponseDto
import delta.codecharacter.dtos.DailyChallengeMatchRequestDto
import delta.codecharacter.dtos.GenericErrorDto
import delta.codecharacter.dtos.MatchDto
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
Expand Down Expand Up @@ -102,4 +103,23 @@ interface DailyChallengesApi {
fun getDailyChallengeLeaderBoard(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?): ResponseEntity<List<DailyChallengeLeaderBoardResponseDto>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

@Operation(
summary = "Get user daily challenge matches",
operationId = "getUserDCMatches",
description = """Get daily-challenge matches played by authenticated user""",
responses = [
ApiResponse(responseCode = "200", description = "OK", content = [Content(array = ArraySchema(schema = Schema(implementation = MatchDto::class)))]),
ApiResponse(responseCode = "401", description = "Unauthorized")
],
security = [ SecurityRequirement(name = "http-bearer") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/dc/matches"],
produces = ["application/json"]
)
fun getUserDCMatches(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?): ResponseEntity<List<MatchDto>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}
29 changes: 25 additions & 4 deletions library/src/main/kotlin/delta/codecharacter/core/MatchApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package delta.codecharacter.core

import delta.codecharacter.dtos.CreateMatchRequestDto
import delta.codecharacter.dtos.GenericErrorDto
import delta.codecharacter.dtos.MatchDto
import delta.codecharacter.dtos.PvPMatchDto
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
Expand Down Expand Up @@ -80,10 +82,10 @@ interface MatchApi {

@Operation(
summary = "Get user matches",
operationId = "getUserMatches",
description = """Get matches played by authenticated user""",
operationId = "getUserNormalMatches",
description = """Get normal matches played by authenticated user""",
responses = [
ApiResponse(responseCode = "200", description = "OK", content = [Content(array = ArraySchema(schema = Schema(implementation = kotlin.Any::class)))]),
ApiResponse(responseCode = "200", description = "OK", content = [Content(array = ArraySchema(schema = Schema(implementation = MatchDto::class)))]),
ApiResponse(responseCode = "401", description = "Unauthorized")
],
security = [ SecurityRequirement(name = "http-bearer") ]
Expand All @@ -93,7 +95,26 @@ interface MatchApi {
value = ["/user/matches"],
produces = ["application/json"]
)
fun getUserMatches(): ResponseEntity<List<kotlin.Any>> {
fun getUserNormalMatches(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?): ResponseEntity<List<MatchDto>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

@Operation(
summary = "Get user pvp matches",
operationId = "getUserPvPMatches",
description = """Get pvp matches played by authenticated user""",
responses = [
ApiResponse(responseCode = "200", description = "OK", content = [Content(array = ArraySchema(schema = Schema(implementation = PvPMatchDto::class)))]),
ApiResponse(responseCode = "401", description = "Unauthorized")
],
security = [ SecurityRequirement(name = "http-bearer") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/user/pvpmatches"],
produces = ["application/json"]
)
fun getUserPvPMatches(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?): ResponseEntity<List<PvPMatchDto>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import delta.codecharacter.core.DailyChallengesApi
import delta.codecharacter.dtos.DailyChallengeGetRequestDto
import delta.codecharacter.dtos.DailyChallengeLeaderBoardResponseDto
import delta.codecharacter.dtos.DailyChallengeMatchRequestDto
import delta.codecharacter.dtos.MatchDto
import delta.codecharacter.server.match.MatchService
import delta.codecharacter.server.user.UserEntity
import delta.codecharacter.server.user.public_user.PublicUserService
Expand Down Expand Up @@ -38,4 +39,10 @@ class DailyChallengeController(
val user = SecurityContextHolder.getContext().authentication.principal as UserEntity
return ResponseEntity.ok(matchService.createDCMatch(user.id, dailyChallengeMatchRequestDto))
}

@Secured(value = ["ROLE_USER"])
override fun getUserDCMatches(page: Int?, size: Int?): ResponseEntity<List<MatchDto>> {
val user = SecurityContextHolder.getContext().authentication.principal as UserEntity
return ResponseEntity.ok(matchService.getUserDCMatches(user.id, page, size))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import delta.codecharacter.core.MatchApi
import delta.codecharacter.dtos.CreateMatchRequestDto
import delta.codecharacter.dtos.MatchDto
import delta.codecharacter.dtos.MatchModeDto
import delta.codecharacter.dtos.PvPMatchDto
import delta.codecharacter.server.exception.CustomException
import delta.codecharacter.server.user.UserEntity
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -32,8 +33,20 @@ class MatchController(@Autowired private val matchService: MatchService) : Match
}

@Secured("ROLE_USER")
override fun getUserMatches(): ResponseEntity<List<Any>> {
override fun getUserNormalMatches(
page: Int?,
size: Int?,
): ResponseEntity<List<MatchDto>> {
val user = SecurityContextHolder.getContext().authentication.principal as UserEntity
return ResponseEntity.ok(matchService.getUserMatches(user.id))
return ResponseEntity.ok(matchService.getUserNormalMatches(user.id, page, size))
}

@Secured("ROLE_USER")
override fun getUserPvPMatches(
page: Int?,
size: Int?,
): ResponseEntity<List<PvPMatchDto>> {
val user = SecurityContextHolder.getContext().authentication.principal as UserEntity
return ResponseEntity.ok(matchService.getUserPvPMatches(user.id, page, size))
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package delta.codecharacter.server.match

import delta.codecharacter.server.user.public_user.PublicUserEntity
import org.springframework.data.domain.PageRequest
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.stereotype.Repository
import java.util.UUID

@Repository
interface MatchRepository : MongoRepository<MatchEntity, UUID> {
fun findTop10ByOrderByTotalPointsDesc(): List<MatchEntity>
fun findByPlayer1OrderByCreatedAtDesc(player1: PublicUserEntity): List<MatchEntity>
fun findByPlayer1OrderByCreatedAtDesc(player1: PublicUserEntity, pageRequest: PageRequest): List<MatchEntity>
fun findByIdIn(matchIds: List<UUID>): List<MatchEntity>
}
Loading

0 comments on commit 7d1234a

Please sign in to comment.