Skip to content

Commit

Permalink
Merge pull request #601 from bounswe/feature/mobile-390-create-task-s…
Browse files Browse the repository at this point in the history
…creen

Feature/mobile 390 create task screen
  • Loading branch information
GulbeycanCagri authored Dec 23, 2023
2 parents 27c0604 + a0a648e commit 654081f
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.cmpe451.resq.ui.views.screens.RegistrationScreen
import com.cmpe451.resq.ui.views.screens.RequestScreen
import com.cmpe451.resq.ui.views.screens.ResourceScreen
import com.cmpe451.resq.ui.views.screens.SettingsScreen
import com.cmpe451.resq.ui.views.screens.TasksScreen
import com.cmpe451.resq.utils.BottomNavigationItem
import com.cmpe451.resq.utils.NavigationItem
import com.cmpe451.resq.viewmodels.MapViewModel
Expand Down Expand Up @@ -137,6 +138,9 @@ fun NavGraph(
composable(NavigationItem.Resource.route) {
ResourceScreen(navController, appContext)
}
composable(NavigationItem.Task.route) {
TasksScreen(navController)
}
composable(NavigationItem.OngoingTasks.route) {
OngoingTasksScreen(navController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class Need(
val quantity: Int,
val latitude: Double,
val longitude: Double,
val requestId: Int,
val requestId: Int?,
val status: String,
val createdDate: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ data class CreateResourceRequestBody(
val longitude: Double,
val gender: String
)

data class Resource(
var id: Int?,
val senderId: Int,
val receiverId: Int,
val categoryTreeId: String,
val gender: String,
val quantity: Int,
val latitude: Double,
var longitude: Double,
val createdDate: String,
val size: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import com.cmpe451.resq.data.models.Need
import com.cmpe451.resq.data.models.NotificationItem
import com.cmpe451.resq.data.models.ProfileData
import com.cmpe451.resq.data.models.RegisterRequestBody
import com.cmpe451.resq.data.models.Resource
import com.cmpe451.resq.data.models.UserInfoRequest
import com.google.gson.GsonBuilder
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand All @@ -29,37 +32,41 @@ import java.time.format.DateTimeParseException
interface CategoryTreeNodeService {
@GET("categorytreenode/getMainCategories")
suspend fun getMainCategories(
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
@Header("Authorization") jwtToken: String
): 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>

@GET("resource/filterByDistance")
fun filterResourceByDistance(
@Query("latitude") latitude: Double,
@Query("longitude") longitude: Double,
@Query("distance") distance: Double,
@Header("Authorization") jwtToken: String
): Call<List<Resource>>
}
interface NeedService {
@POST("need/createNeed")
suspend fun createNeed(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
@Body requestBody: CreateNeedRequestBody
): Response<Int>


@GET("need/filterByDistance")
fun filterNeedByDistance(
@Query("latitude") latitude: Double,
@Query("longitude") longitude: Double,
@Query("distance") distance: Double,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
): Response<List<Need>>
@Header("Authorization") jwtToken: String
): Call<List<Need>>


}

Expand All @@ -75,24 +82,21 @@ interface ProfileService {
@GET("profile/getProfileInfo")
suspend fun getUserInfo(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
@Header("Authorization") jwtToken: String
): Response<ProfileData>

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


@POST("profile/updateProfile")
suspend fun updateProfile(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
@Body request: UserInfoRequest
): Response<String>

Expand Down Expand Up @@ -129,25 +133,21 @@ class ResqService(appContext: Context) {
// Category Tree Node methods
suspend fun getMainCategories(): Response<List<CategoryTreeNode>> {
val token = userSessionManager.getUserToken() ?: ""
val selectedRole = userSessionManager.getSelectedRole() ?: ""

return categoryTreeNodeService.getMainCategories(
jwtToken = "Bearer $token",
role = selectedRole
jwtToken = "Bearer $token"
)
}

// 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
)
}
Expand All @@ -156,30 +156,58 @@ class ResqService(appContext: Context) {
suspend fun createNeed(request: CreateNeedRequestBody): Response<Int> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
// val selectedRole = userSessionManager.getSelectedRole() ?: ""

return needService.createNeed(
userId = userId,
jwtToken = "Bearer $token",
role = "ROLE_VICTIM",
requestBody = request
)
}

suspend fun filterNeedByDistance(
fun filterNeedByDistance(
latitude: Double,
longitude: Double,
distance: Double
): Response<List<Need>> {
val selectedRole = userSessionManager.getSelectedRole() ?: ""
distance: Double,
onSuccess: (List<Need>) -> Unit,
onError: (Throwable) -> Unit
) {
val token = userSessionManager.getUserToken() ?: ""
return needService.filterNeedByDistance(
latitude = latitude,
longitude = longitude,
distance = distance,
role = selectedRole,
jwtToken = "Bearer $token"
)
needService.filterNeedByDistance(latitude, longitude, distance, "Bearer $token").enqueue(object :
Callback<List<Need>> {
override fun onResponse(call: Call<List<Need>>, response: Response<List<Need>>) {
if (response.isSuccessful) {
response.body()?.let { onSuccess(it) }
} else {
onError(RuntimeException("Response not successful"))
}
}
override fun onFailure(call: Call<List<Need>>, t: Throwable) {
onError(t)
}
})
}

fun filterResourceByDistance(
latitude: Double,
longitude: Double,
distance: Double,
onSuccess: (List<Resource>) -> Unit,
onError: (Throwable) -> Unit
) {
val token = userSessionManager.getUserToken() ?: ""
resourceService.filterResourceByDistance(latitude, longitude, distance, "Bearer $token").enqueue(object :
Callback<List<Resource>> {
override fun onResponse(call: Call<List<Resource>>, response: Response<List<Resource>>) {
if (response.isSuccessful) {
response.body()?.let { onSuccess(it) }
} else {
onError(RuntimeException("Response not successful"))
}
}
override fun onFailure(call: Call<List<Resource>>, t: Throwable) {
onError(t)
}
})
}

// Auth methods
Expand Down Expand Up @@ -210,13 +238,10 @@ class ResqService(appContext: Context) {
suspend fun getUserInfo(): ProfileData {
val token = userSessionManager.getUserToken() ?: ""
val userId = userSessionManager.getUserId()
val selectedRole = userSessionManager.getSelectedRole() ?: ""


val response = profileService.getUserInfo(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole
jwtToken = "Bearer $token"
)

return ProfileData(
Expand All @@ -239,7 +264,6 @@ class ResqService(appContext: Context) {
suspend fun updateUserData(profileData: ProfileData): Response<String> {
val token = userSessionManager.getUserToken() ?: ""
val userId = userSessionManager.getUserId()
val selectedRole = userSessionManager.getSelectedRole() ?: ""

val request = UserInfoRequest(
name = profileData.name ?: "",
Expand All @@ -259,21 +283,18 @@ class ResqService(appContext: Context) {
return profileService.updateProfile(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
request = request
)
}

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 = role
jwtToken = "Bearer $token"
)

return response
Expand Down
Loading

0 comments on commit 654081f

Please sign in to comment.