Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:7.3.3-jdk17 as base
FROM gradle:7.6-jdk17 as base
WORKDIR /server
COPY build.gradle.kts settings.gradle.kts gradlew ./
COPY library/build.gradle.kts library/settings.gradle.kts ./library/
Expand Down
23 changes: 21 additions & 2 deletions docs/spec/CodeCharacter-API.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,18 @@ paths:
description: Forbidden
'404':
description: Not Found
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:
PasswordLoginRequest:
Expand Down Expand Up @@ -1833,8 +1845,15 @@ components:
type: string
example: TestUser
score:
type: string
example: 1500.0
type: number
example: 1500.00
avatarId:
type: integer
example: 1
required:
- userName
- score
- avatarId
TutorialLevelResponse:
title: TutorialLevelResponse
description: Get the tutorial level of the current user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ interface DailyChallengesApi {
value = ["/dc/leaderboard"],
produces = ["application/json"]
)
fun getDailyChallengeLeaderBoard(): ResponseEntity<List<DailyChallengeLeaderBoardResponseDto>> {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import io.swagger.v3.oas.annotations.media.Schema
* Response model for daily challenge leaderboard
* @param userName
* @param score
* @param avatarId
*/
data class DailyChallengeLeaderBoardResponseDto(

@Schema(example = "TestUser", description = "")
@field:JsonProperty("userName") val userName: kotlin.String? = null,
@Schema(example = "TestUser", required = true, description = "")
@field:JsonProperty("userName", required = true) val userName: kotlin.String,

@Schema(example = "1500.0", description = "")
@field:JsonProperty("score") val score: kotlin.String? = null
@Schema(example = "1500.0", required = true, description = "")
@field:JsonProperty("score", required = true) val score: java.math.BigDecimal,

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

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package delta.codecharacter.server.leaderboard

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

@RestController
class DailyChallengeLeaderboardController(
@Autowired private val publicUserService: PublicUserService
) : DailyChallengesApi {
override fun getDailyChallengeLeaderBoard(
page: Int?,
size: Int?
): ResponseEntity<List<DailyChallengeLeaderBoardResponseDto>> {
return ResponseEntity.ok(publicUserService.getDailyChallengeLeaderboard(page, size))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ data class PublicUserEntity(
val losses: Int,
val ties: Int,
val isActivated: Boolean = true,
val score: Double,
val challengesCompleted: Array<String>?
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package delta.codecharacter.server.user.public_user

import delta.codecharacter.dtos.CurrentUserProfileDto
import delta.codecharacter.dtos.DailyChallengeLeaderBoardResponseDto
import delta.codecharacter.dtos.LeaderboardEntryDto
import delta.codecharacter.dtos.PublicUserDto
import delta.codecharacter.dtos.UpdateCurrentUserProfileDto
Expand Down Expand Up @@ -38,6 +39,8 @@ class PublicUserService(@Autowired private val publicUserRepository: PublicUserR
wins = 0,
losses = 0,
ties = 0,
score = 0.0,
challengesCompleted = null,
)
publicUserRepository.save(publicUser)
}
Expand Down Expand Up @@ -65,6 +68,18 @@ class PublicUserService(@Autowired private val publicUserRepository: PublicUserR
}
}

fun getDailyChallengeLeaderboard(
page: Int?,
size: Int?
): List<DailyChallengeLeaderBoardResponseDto> {
val pageRequest = PageRequest.of(page ?: 0, size ?: 10, Sort.by(Sort.Direction.DESC, "score"))
return publicUserRepository.findAll(pageRequest).content.map {
DailyChallengeLeaderBoardResponseDto(
userName = it.username, score = BigDecimal(it.score), avatarId = it.avatarId
)
}
}

fun getUserProfile(userId: UUID, email: String): CurrentUserProfileDto {
val user = publicUserRepository.findById(userId).get()
return CurrentUserProfileDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TestAttributes {
wins = 4,
losses = 2,
ties = 1,
score = 0.0,
challengesCompleted = null
)
}
}
Expand Down