This commit is contained in:
Niktia 2025-02-20 14:59:48 +03:00
parent 30127c6fc0
commit 78e5ed4494
5 changed files with 25 additions and 7 deletions

View File

@ -0,0 +1,11 @@
package ru.myitschool.work.data.user
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable;
@Serializable
data class CodeDto(
@SerialName("value")
val value : String
)

View File

@ -5,6 +5,7 @@ import io.ktor.client.call.body
import io.ktor.client.request.get import io.ktor.client.request.get
import io.ktor.client.request.header import io.ktor.client.request.header
import io.ktor.client.request.patch import io.ktor.client.request.patch
import io.ktor.client.request.setBody
import io.ktor.client.statement.bodyAsText import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpHeaders import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@ -50,9 +51,10 @@ class UserNetworkDataSource {
} }
suspend fun enter(value : String, login : String): Result<Boolean> = withContext(Dispatchers.IO) { suspend fun enter(value : String, login : String): Result<Boolean> = withContext(Dispatchers.IO) {
runCatching { runCatching {
val result = client.patch("$SERVER_ADDRESS/api/open") { val result = client.patch("$SERVER_ADDRESS/api/$login/open") {
header(HttpHeaders.Authorization, token) header(HttpHeaders.Authorization, token)
header(HttpHeaders.ContentType, "application/json")
setBody(CodeDto(value))
} }
Log.d("result", "${result.status}") Log.d("result", "${result.status}")
if (result.status != HttpStatusCode.OK) { if (result.status != HttpStatusCode.OK) {

View File

@ -36,6 +36,8 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
} }
viewBinding.qrScan.setOnClickListener{ viewBinding.qrScan.setOnClickListener{
findNavController().navigate(R.id.action_fragment_profile_to_fragment_qr) findNavController().navigate(R.id.action_fragment_profile_to_fragment_qr)
} }
val adapter = EntranceAdapter() val adapter = EntranceAdapter()
viewBinding.recyclerView.adapter = adapter viewBinding.recyclerView.adapter = adapter

View File

@ -20,10 +20,10 @@ class QrResultFragment : Fragment(R.layout.fragment_qr_result) {
private val viewModel by viewModels<QrResultViewModel> { QrResultViewModel.Factory } private val viewModel by viewModels<QrResultViewModel> { QrResultViewModel.Factory }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
_viewBinding = FragmentQrResultBinding.bind(view) _viewBinding = FragmentQrResultBinding.bind(view)
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
parentFragmentManager.setFragmentResultListener( parentFragmentManager.setFragmentResultListener(
QrScanDestination.REQUEST_KEY, viewLifecycleOwner QrScanDestination.REQUEST_KEY, viewLifecycleOwner
) { ) {

View File

@ -122,10 +122,13 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
QrScanDestination.REQUEST_KEY, QrScanDestination.REQUEST_KEY,
bundle bundle
) )
findNavControllerOrNull() if (!bundle.isEmpty) {
?.previousBackStackEntry findNavController().navigate(R.id.action_fragment_qr_to_fragment_qr_result)
?.savedStateHandle }
?.set(QrScanDestination.REQUEST_KEY, bundle) // findNavControllerOrNull()
// ?.previousBackStackEntry
// ?.savedStateHandle
// ?.set(QrScanDestination.REQUEST_KEY, bundle)
} }
private fun findNavControllerOrNull(): NavController? { private fun findNavControllerOrNull(): NavController? {