Skip to content

Commit

Permalink
feat : PvP leaderboard (#5)
Browse files Browse the repository at this point in the history
* feat : PvP leaderboard

* fix : commit bugs

* fix : commit bugs
  • Loading branch information
MughilSrinivasan authored Feb 2, 2024
1 parent 7d1234a commit 44054a9
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 0 deletions.
175 changes: 175 additions & 0 deletions docs/spec/CodeCharacter-API.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,150 @@ paths:
description: Get leaderboard
parameters: []

/pvpleaderboard:
get:
summary: Get PvP leaderboard
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PvPLeaderBoardResponse'
examples:
Example:
value:
- user:
username: testUser
name: >-
Test User1
asdfdsfasdfasdfadsfasdfadsdfasdfasdfasfasdfsfsdfsfadsfasfa
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 500
wins: 6
losses: 0
- user:
username: testUser2
name: >-
Test User2
asdfdsfasdfasdfadsfasdfadsdfasdfasdfasfasdfsfsdfsfadsfasfa
country: IN
college: NIT Trichy
avatarId: 1
stats:
rating: 50
wins: 3
losses: 3
- user:
username: testUser3
name: >-
Test User3
asdfdsfasdfasdfadsfasdfadsdfasdfasdfasfasdfsfsdfsfadsfasfa
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 80
wins: 1
losses: 0
- user:
username: testUser4
name: Test User4
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 230
wins: 0
losses: 0
- user:
username: testUser5
name: Test User5 Test Test
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 850
wins: 0
losses: 0
- user:
username: testUser6
name: >-
Test User6
asdfdsfasdfasdfadsfasdfadsdfasdfasdfasfasdfsfsdfsfadsfasfa
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 600
wins: 0
losses: 0
- user:
username: testUser7
name: >-
Test User7
asdfdsfasdfasdfadsfasdfadsdfasdfasdfasfasdfsfsdfsfadsfasfa
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 57
wins: 20
losses: 70
- user:
username: testUser8
name: Test User8
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 850
wins: 0
losses: 0
- user:
username: testUser9
name: Test User9
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 78
wins: 0
losses: 0
- user:
username: testUser10
name: Test User10
country: IN
college: NIT Trichy
avatarId: 0
stats:
rating: 10
wins: 0
losses: 0
'401':
description: Unauthorized
operationId: getPvPLeaderboard
tags:
- pvpLeaderboard
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
description: Get PvP leaderboard
parameters: [ ]

/top-matches:
get:
summary: Get top matches
Expand Down Expand Up @@ -1568,6 +1712,25 @@ components:
- wins
- losses
- ties
PvPUserStats:
title: PvPUserStats
type: object
description: PvP User stats model
properties:
rating:
type: number
example: 1000
wins:
type: integer
default: 0
example: 1
losses:
type: integer
example: 1
required:
- rating
- wins
- losses
Code:
title: Code
type: object
Expand Down Expand Up @@ -2134,6 +2297,18 @@ components:
- user
- stats
description: Leaderboard entry model
PvPLeaderBoardResponse:
title: PvPLeaderboardResponse
description: Response model for PvP leaderboard
type: object
properties:
user:
$ref: '#/components/schemas/PublicUser'
stats:
$ref: '#/components/schemas/PvPUserStats'
required:
- user
- stats

DailyChallengeGetRequest:
title: Get daily challenge
Expand Down
3 changes: 3 additions & 0 deletions library/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ src/main/kotlin/delta/codecharacter/core/MapApi.kt
src/main/kotlin/delta/codecharacter/core/MatchApi.kt
src/main/kotlin/delta/codecharacter/core/NotificationApi.kt
src/main/kotlin/delta/codecharacter/core/PvpGameApi.kt
src/main/kotlin/delta/codecharacter/core/PvpLeaderboardApi.kt
src/main/kotlin/delta/codecharacter/core/UserApi.kt
src/main/kotlin/delta/codecharacter/dtos/ActivateUserRequestDto.kt
src/main/kotlin/delta/codecharacter/dtos/AuthStatusResponseDto.kt
Expand Down Expand Up @@ -43,7 +44,9 @@ src/main/kotlin/delta/codecharacter/dtos/PasswordLoginResponseDto.kt
src/main/kotlin/delta/codecharacter/dtos/PublicUserDto.kt
src/main/kotlin/delta/codecharacter/dtos/PvPGameDto.kt
src/main/kotlin/delta/codecharacter/dtos/PvPGameStatusDto.kt
src/main/kotlin/delta/codecharacter/dtos/PvPLeaderBoardResponseDto.kt
src/main/kotlin/delta/codecharacter/dtos/PvPMatchDto.kt
src/main/kotlin/delta/codecharacter/dtos/PvPUserStatsDto.kt
src/main/kotlin/delta/codecharacter/dtos/RatingHistoryDto.kt
src/main/kotlin/delta/codecharacter/dtos/RegisterUserRequestDto.kt
src/main/kotlin/delta/codecharacter/dtos/ResetPasswordRequestDto.kt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.1.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package delta.codecharacter.core

import delta.codecharacter.dtos.PvPLeaderBoardResponseDto
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
import io.swagger.v3.oas.annotations.responses.*
import io.swagger.v3.oas.annotations.security.*
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity

import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired

import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid

import kotlin.collections.List
import kotlin.collections.Map

@Validated
@RequestMapping("\${api.base-path:}")
interface PvpLeaderboardApi {

@Operation(
summary = "Get PvP leaderboard",
operationId = "getPvPLeaderboard",
description = """Get PvP leaderboard""",
responses = [
ApiResponse(responseCode = "200", description = "OK", content = [Content(array = ArraySchema(schema = Schema(implementation = PvPLeaderBoardResponseDto::class)))]),
ApiResponse(responseCode = "401", description = "Unauthorized")
],
security = [ SecurityRequirement(name = "http-bearer") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/pvpleaderboard"],
produces = ["application/json"]
)
fun getPvPLeaderboard(@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<PvPLeaderBoardResponseDto>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package delta.codecharacter.dtos

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import delta.codecharacter.dtos.PublicUserDto
import delta.codecharacter.dtos.PvPUserStatsDto
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema

/**
* Response model for PvP leaderboard
* @param user
* @param stats
*/
data class PvPLeaderBoardResponseDto(

@field:Valid
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("user", required = true) val user: PublicUserDto,

@field:Valid
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("stats", required = true) val stats: PvPUserStatsDto
) {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package delta.codecharacter.dtos

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema

/**
* PvP User stats model
* @param rating
* @param wins
* @param losses
*/
data class PvPUserStatsDto(

@Schema(example = "1000", required = true, description = "")
@get:JsonProperty("rating", required = true) val rating: java.math.BigDecimal,

@Schema(example = "1", required = true, description = "")
@get:JsonProperty("wins", required = true) val wins: kotlin.Int = 0,

@Schema(example = "1", required = true, description = "")
@get:JsonProperty("losses", required = true) val losses: kotlin.Int
) {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package delta.codecharacter.server.leaderboard

import delta.codecharacter.core.PvpLeaderboardApi
import delta.codecharacter.dtos.PvPLeaderBoardResponseDto
import delta.codecharacter.server.user.public_user.PublicUserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RestController
import org.springframework.http.ResponseEntity

@RestController
class PvPLeaderBoardController (@Autowired private val publicUserService: PublicUserService) :
PvpLeaderboardApi {
override fun getPvPLeaderboard(
page: Int?,
size: Int?,
): ResponseEntity<List<PvPLeaderBoardResponseDto>> {
return ResponseEntity.ok(publicUserService.getPvPLeaderboard(page, size))
}
}
Loading

0 comments on commit 44054a9

Please sign in to comment.