Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add tutorial completion check
  • Loading branch information
Valliammai-SM committed Jan 16, 2023
commit 124d7dad5948050937f031579156ecdaeec5d0c9
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface CurrentUserApi {
value = ["/user/tutorial/level"],
produces = ["application/json"]
)
fun getTutorialLevel(): ResponseEntity<TutorialLevelResponseDto> {
fun getTutorialLevel(@Parameter(description = "", required = true) @Valid @RequestBody tutorialLevelResponseDto: TutorialLevelResponseDto): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ data class UserStatsDto(
@Schema(example = "1000", required = true, description = "")
@field:JsonProperty("rating", required = true) val rating: java.math.BigDecimal,

@Schema(example = "1", required = true, description = "")
@field:JsonProperty("tier", required = true) val tier: Int,

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,46 @@ class MatchService(
gameService.sendGameRequest(game2, opponentCode, opponentLanguage, userMap)
}

fun createTierMatch(userId: UUID) {
val publicUser = publicUserService.getPublicUser(userId)
val userTier = publicUser.tier
val opponentList = publicUserService.getLeaderboardByTier(userTier)
val opponentUser = opponentList[(0..opponentList.size).random()].user.username
val publicOpponent = publicUserService.getPublicUserByUsername(opponentUser)
val opponentId = publicOpponent.userId

if (userId == opponentId) {
throw CustomException(HttpStatus.BAD_REQUEST, "You cannot play against yourself")
}

val (userLanguage, userCode) = lockedCodeService.getLockedCode(userId)
val userMap = lockedMapService.getLockedMap(userId)

val (opponentLanguage, opponentCode) = lockedCodeService.getLockedCode(opponentId)
val opponentMap = lockedMapService.getLockedMap(opponentId)

val matchId = UUID.randomUUID()

val game1 = gameService.createGame(matchId)
val game2 = gameService.createGame(matchId)

val match =
MatchEntity(
id = matchId,
games = listOf(game1, game2),
mode = MatchModeEnum.MANUAL,
verdict = MatchVerdictEnum.TIE,
createdAt = Instant.now(),
totalPoints = 0,
player1 = publicUser,
player2 = publicOpponent,
)
matchRepository.save(match)

gameService.sendGameRequest(game1, userCode, userLanguage, opponentMap)
gameService.sendGameRequest(game2, opponentCode, opponentLanguage, userMap)
}

fun createMatch(userId: UUID, createMatchRequestDto: CreateMatchRequestDto) {
when (createMatchRequestDto.mode) {
MatchModeDto.SELF -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package delta.codecharacter.server.user
import delta.codecharacter.core.CurrentUserApi
import delta.codecharacter.dtos.CompleteProfileRequestDto
import delta.codecharacter.dtos.CurrentUserProfileDto
import delta.codecharacter.dtos.TutorialLevelResponseDto
import delta.codecharacter.dtos.UpdateCurrentUserProfileDto
import delta.codecharacter.dtos.UpdatePasswordRequestDto
import delta.codecharacter.server.user.public_user.PublicUserService
Expand Down Expand Up @@ -49,4 +50,13 @@ class CurrentUserController(
userService.updatePassword(user.id, updatePasswordRequestDto)
return ResponseEntity.ok().build()
}

@Secured(value = ["ROLE_USER"])
override fun getTutorialLevel(
tutorialLevelResponseDto: TutorialLevelResponseDto
): ResponseEntity<Unit> {
val user = SecurityContextHolder.getContext().authentication.principal as UserEntity
userService.updateTutorialLevel(user.id, tutorialLevelResponseDto)
return ResponseEntity.ok().build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data class UserEntity(
val loginType: LoginType,
private val password: String,
val isProfileComplete: Boolean,
val tutorialLevel: Int?,
private val isEnabled: Boolean = false,
private val isCredentialsNonExpired: Boolean = true,
private val isAccountNonExpired: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package delta.codecharacter.server.user

import delta.codecharacter.dtos.CompleteProfileRequestDto
import delta.codecharacter.dtos.RegisterUserRequestDto
import delta.codecharacter.dtos.TutorialLevelResponseDto
import delta.codecharacter.dtos.UpdatePasswordRequestDto
import delta.codecharacter.server.exception.CustomException
import delta.codecharacter.server.user.activate_user.ActivateUserService
Expand Down Expand Up @@ -53,6 +54,7 @@ class UserService(
email = email,
loginType = LoginType.PASSWORD,
isProfileComplete = true,
tutorialLevel = 0,
isEnabled = false,
isAccountNonExpired = true,
isAccountNonLocked = true,
Expand All @@ -71,6 +73,7 @@ class UserService(
email = email,
loginType = oauthProvider,
isProfileComplete = false,
tutorialLevel = 0,
isEnabled = true,
isAccountNonExpired = true,
isAccountNonLocked = true,
Expand Down Expand Up @@ -109,7 +112,17 @@ class UserService(
}

fun registerUser(registerUserRequestDto: RegisterUserRequestDto) {
val (username, name, email, password, passwordConfirmation, country, college, avatarId) =
val (
username,
name,
email,
password,
passwordConfirmation,
country,
college,
avatarId,
recaptchaCode
) =
registerUserRequestDto

if (password != passwordConfirmation) {
Expand Down Expand Up @@ -151,4 +164,10 @@ class UserService(
)
)
}

fun updateTutorialLevel(userId: UUID, tutorialLevelResponseDto: TutorialLevelResponseDto) {
val (level) = tutorialLevelResponseDto
val user = userRepository.findById(userId).get()
userRepository.save(user.copy(tutorialLevel = level))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class PublicUserEntity(
val country: String,
val college: String,
val avatarId: Int,
val tier: Int,
val rating: Double,
val wins: Int,
val losses: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PublicUserService(@Autowired private val publicUserRepository: PublicUserR
stats =
UserStatsDto(
rating = BigDecimal(it.rating),
tier = it.tier,
wins = it.wins,
losses = it.losses,
ties = it.ties,
Expand Down