Skip to content

Commit

Permalink
Merge branch 'dev' into feature/mobile-463-map-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alperenDagi authored Nov 27, 2023
2 parents 217d8ca + 048b39d commit 34b7787
Show file tree
Hide file tree
Showing 13 changed files with 785 additions and 584 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun NavGraph(
RequestScreen(navController, appContext)
}
composable(NavigationItem.Resource.route) {
ResourceScreen(navController)
ResourceScreen(navController, appContext)
}
composable(NavigationItem.OngoingTasks.route) {
OngoingTasksScreen(navController)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cmpe451.resq.data.models

data class CategoryTreeNode(
val id: Int,
val data: String,
val children: List<CategoryTreeNode>
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.cmpe451.resq.data.models

data class CategoryNode(
val id: Int,
val data: String,
val children: List<CategoryNode>
)

data class CreateNeedRequestBody(
val description: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cmpe451.resq.data.models

data class CreateResourceRequestBody(
var senderId: Int?,
val categoryTreeId: String,
val quantity: Int,
val latitude: Double,
val longitude: Double,
val gender: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import android.os.Build
import androidx.annotation.RequiresApi
import com.cmpe451.resq.data.Constants
import com.cmpe451.resq.data.manager.UserSessionManager
import com.cmpe451.resq.data.models.CategoryNode
import com.cmpe451.resq.data.models.CategoryTreeNode
import com.cmpe451.resq.data.models.CreateNeedRequestBody
import com.cmpe451.resq.data.models.CreateResourceRequestBody
import com.cmpe451.resq.data.models.LoginRequestBody
import com.cmpe451.resq.data.models.LoginResponse
import com.cmpe451.resq.data.models.Need
Expand All @@ -27,9 +28,17 @@ interface CategoryTreeNodeService {
suspend fun getMainCategories(
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
): Response<List<CategoryNode>>
): Response<List<CategoryTreeNode>>
}

interface ResourceService {
@POST("resource/createResource")
suspend fun createResource(
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
@Body requestBody: CreateResourceRequestBody
): Response<Int>
}
interface NeedService {
@POST("need/createNeed")
suspend fun createNeed(
Expand Down Expand Up @@ -65,8 +74,15 @@ interface ProfileService {
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
): Response<UserInfo>
): Response<UserInfoResponse>

@POST("user/requestRole")
suspend fun selectRole(
@Query("userId") userId: Int,
@Query("role") requestedRole: String,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
): Response<String>


@POST("profile/updateProfile")
Expand All @@ -76,6 +92,7 @@ interface ProfileService {
@Header("X-Selected-Role") role: String,
@Body request: UserInfoRequest
): Response<ResponseBody>

}

class ResqService(appContext: Context) {
Expand All @@ -85,14 +102,15 @@ class ResqService(appContext: Context) {
.build()

private val categoryTreeNodeService: CategoryTreeNodeService = retrofit.create(CategoryTreeNodeService::class.java)
private val resourceService: ResourceService = retrofit.create(ResourceService::class.java)
private val needService: NeedService = retrofit.create(NeedService::class.java)
private val authService: AuthService = retrofit.create(AuthService::class.java)
private val profileService: ProfileService = retrofit.create(ProfileService::class.java)

private val userSessionManager: UserSessionManager = UserSessionManager.getInstance(appContext)

// Category Tree Node methods
suspend fun getMainCategories(): Response<List<CategoryNode>> {
suspend fun getMainCategories(): Response<List<CategoryTreeNode>> {
val token = userSessionManager.getUserToken() ?: ""
val selectedRole = userSessionManager.getSelectedRole() ?: ""

Expand All @@ -102,16 +120,31 @@ class ResqService(appContext: Context) {
)
}

// Resource methods
suspend fun createResource(request: CreateResourceRequestBody): Response<Int> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
// val selectedRole = userSessionManager.getSelectedRole() ?: ""

request.senderId = userId

return resourceService.createResource(
jwtToken = "Bearer $token",
role = "RESPONDER",
requestBody = request
)
}

// Need methods
suspend fun createNeed(request: CreateNeedRequestBody): Response<Int> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
val selectedRole = userSessionManager.getSelectedRole() ?: ""
// val selectedRole = userSessionManager.getSelectedRole() ?: ""

return needService.createNeed(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
role = "VICTIM",
requestBody = request
)
}
Expand Down Expand Up @@ -218,5 +251,18 @@ class ResqService(appContext: Context) {

}

suspend fun selectRole(requestedRole: String): Response<String> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
val role = userSessionManager.getSelectedRole() ?: ""

val response = profileService.selectRole(
userId = userId,
requestedRole = requestedRole,
jwtToken = "Bearer $token",
role = requestedRole
)

return response
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.cmpe451.resq.ui.views.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun <T> DropdownMenuComponent(
label: String,
items: List<T>,
selectedItem: T,
itemToString: (T) -> String,
onItemSelected: (T) -> Unit
) {
var expandState by remember { mutableStateOf(false) }
Box(modifier = Modifier
.fillMaxWidth()
.wrapContentWidth(Alignment.Start)
) {
OutlinedTextField(
value = itemToString(selectedItem),
onValueChange = {},
label = { Text(label) },
readOnly = true,
modifier = Modifier
.fillMaxWidth()
.clickable { expandState = true },
trailingIcon = {
Icon(
imageVector = if (expandState) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
contentDescription = "Dropdown Icon",
modifier = Modifier.clickable { expandState = !expandState }
)
}
)
DropdownMenu(
expanded = expandState,
onDismissRequest = { expandState = false },
modifier = Modifier
.fillMaxWidth()
) {
items.forEach { item ->
DropdownMenuItem(onClick = {
onItemSelected(item)
expandState = false
}) {
Text(text = itemToString(item))
}
}
}
}
}
Loading

0 comments on commit 34b7787

Please sign in to comment.