Skip to content

Commit

Permalink
Adding stubs for extra controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Nov 2, 2024
1 parent bfc65d7 commit a27fb63
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ hs_err_pid*
replay_pid*

.DS_Store

/backend/build/
/frontend/build/
/common/build/
build/
.idea/
.gradle/
.kotlin
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ru.posidata.backend.controller
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import ru.posidata.backend.entity.UserEntityFromDb
import ru.posidata.backend.service.UserService
import ru.posidata.common.RoundResult
import ru.posidata.common.UserDataFromTelegram
Expand Down Expand Up @@ -41,6 +42,29 @@ class TestController(
"blabla",
)
)
println("${a?.map { RoundResult(it.roundNumber, it.result) }}")
return ResponseEntity.status(HttpStatus.OK).body(a?.map { RoundResult(it.roundNumber, it.result) })
}

@GetMapping("/test3")
fun nextRound(): ResponseEntity<Any> {
val a = userService.getResultsByUser(
UserDataFromTelegram(
1234567,
"a",
"a",
"",
123,
"",
"blabla",
)
)
println("======")
return ResponseEntity.status(HttpStatus.OK).body(a?.map { RoundResult(it.roundNumber, it.result) })
}

@GetMapping("/test4")
fun randomUser(): String? {
return userService.getRandomUser().username
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import ru.posidata.backend.service.TelegramAuthService
import ru.posidata.backend.service.UserService
import ru.posidata.common.ResourceType
import ru.posidata.common.Resources
import ru.posidata.common.QuestionAndAnswer
import ru.posidata.common.UserDataFromTelegram


Expand All @@ -17,7 +16,7 @@ class UserController(
private val userService: UserService
) {
@GetMapping("/get")
fun getResults(
fun createAndReturnUser(
userDataFromTelegram: UserDataFromTelegram,
): ResponseEntity<Any> {

Expand All @@ -34,9 +33,16 @@ class UserController(
return ResponseEntity.status(HttpStatus.OK).body(responseUser.toDTO())
}

@GetMapping("/again")
fun tryAgainNextRound(): ResponseEntity<Any> {
// TODO: add logic for incrementing to next round
return ResponseEntity.status(HttpStatus.OK).body("")
}

@GetMapping("/update")
fun submitAnswer(
userDataFromTelegram: UserDataFromTelegram,
questionAndAnswer: QuestionAndAnswer
): ResponseEntity<Any> {

println("Received a request to get results from $userDataFromTelegram. " +
Expand All @@ -46,6 +52,9 @@ class UserController(
return ResponseEntity(HttpStatus.FORBIDDEN)
}

// TODO: add logic for checking questionAndAnswer
// and incrementing result

return ResponseEntity.status(HttpStatus.OK).body("")
}
}
9 changes: 9 additions & 0 deletions common/src/commonMain/kotlin/ru/posidata/common/Answer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.posidata.common

import kotlinx.serialization.Serializable

@Serializable
data class QuestionAndAnswer(
val answer: ResourceType,
val question: Resource
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum class ResourceType {
BIG_DATA,
}

enum class Resources(
enum class Resource(
val id: Int,
val description: String,
val type: ResourceType,
Expand Down Expand Up @@ -75,8 +75,8 @@ enum class Resources(
;

companion object {
fun getById(i: Int): Resources = Resources.entries.find { it.id == i }!!
fun getByName(name: String): Resources? = Resources.entries.find { it.name.uppercase() == name }
fun getById(i: Int): Resource = Resource.entries.find { it.id == i }!!
fun getByName(name: String): Resource? = Resource.entries.find { it.name.uppercase() == name }
}

fun getName(): String {
Expand Down
Binary file modified frontend/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import react.dom.html.ReactHTML.img
import react.useState
import ru.posidata.common.ResourceType.BIG_DATA
import ru.posidata.common.ResourceType.POKEMON
import ru.posidata.common.Resources
import ru.posidata.common.Resource
import ru.posidata.common.Answer
import ru.posidata.common.Selection
import ru.posidata.common.Selection.QUESTION
Expand All @@ -22,7 +22,7 @@ import web.cssom.*
val answerCard = FC<AnswerProps> { props ->
var (loading, setLoading) = useState(true)

val pokemon = Resources.getById(props.pokemonId)
val pokemon = Resource.getById(props.pokemonId)
div {
style = jso {
display = (if (loading) "none" else "block").unsafeCast<Display>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import kotlin.random.Random

val questionCard = FC<QuestionCard> { props ->
useEffectOnce {
var randomNumber = Random.nextInt(0, Resources.entries.size)
var randomNumber = Random.nextInt(0, Resource.entries.size)
while (true) {
if (!props.uniqueRandom.contains(randomNumber)) {
props.setUniqueRandom(props.uniqueRandom + randomNumber)
props.setPokemonId(randomNumber)
break
}
randomNumber = Random.nextInt(0, Resources.entries.size)
randomNumber = Random.nextInt(0, Resource.entries.size)
}
}
val pokemon = Resources.getById(props.pokemonId)
val pokemon = Resource.getById(props.pokemonId)

val updateResult = useDeferredRequest {
if (props.tgUser != null) {
Expand Down

0 comments on commit a27fb63

Please sign in to comment.