feat: add actuator history functionality and refactor API calls
This commit is contained in:
parent
66b7159bf6
commit
eed504f04e
|
|
@ -1,34 +1,50 @@
|
|||
package com.syaroful.agrilinkvocpro.control_feature.data.network
|
||||
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorHistoryResponse
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorStatusResponse
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Part
|
||||
|
||||
interface ControlService {
|
||||
// get all actuator status
|
||||
@GET("api/actuators/status")
|
||||
suspend fun getActuatorStatus(
|
||||
@Header("Authorization") authHeader: String,
|
||||
): Response<ActuatorStatusResponse>
|
||||
|
||||
// push control water valve
|
||||
@Multipart
|
||||
@POST("api/actuators/water-valve/control")
|
||||
suspend fun controlWaterValve(
|
||||
@Header("Authorization") authHeader: String,
|
||||
@Body action: String,
|
||||
@Part("action") action: RequestBody
|
||||
): Response<ControlLogResponse>
|
||||
|
||||
// push control nutrient valve
|
||||
@Multipart
|
||||
@POST("api/actuators/nutrient-valve/control")
|
||||
suspend fun controlNutrientValve(
|
||||
@Header("Authorization") authHeader: String,
|
||||
@Body action: String,
|
||||
@Part("action") action: RequestBody
|
||||
): Response<ControlLogResponse>
|
||||
|
||||
// push control pump
|
||||
@Multipart
|
||||
@POST("api/actuators/pump/control")
|
||||
suspend fun controlPump(
|
||||
@Header("Authorization") authHeader: String,
|
||||
@Body action: String,
|
||||
@Part("action") action: RequestBody
|
||||
): Response<ControlLogResponse>
|
||||
|
||||
// get controls log
|
||||
@GET("api//actuator-control-logs")
|
||||
suspend fun getActuatorsControlLog(
|
||||
@Header("Authorization") authHeader: String,
|
||||
): Response<ActuatorHistoryResponse>
|
||||
}
|
||||
|
|
@ -1,28 +1,44 @@
|
|||
package com.syaroful.agrilinkvocpro.control_feature.data.repository
|
||||
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorHistoryResponse
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorStatusResponse
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
||||
import com.syaroful.agrilinkvocpro.control_feature.data.network.ControlService
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import retrofit2.Response
|
||||
|
||||
class ControlRepository(
|
||||
private val controlService: ControlService
|
||||
) {
|
||||
|
||||
suspend fun controlWaterValve(authHeader: String, action: String): Response<ControlLogResponse>{
|
||||
return controlService.controlWaterValve(authHeader, action)
|
||||
suspend fun controlWaterValve(
|
||||
authHeader: String,
|
||||
action: String
|
||||
): Response<ControlLogResponse> {
|
||||
val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
return controlService.controlWaterValve(authHeader, actionPart)
|
||||
}
|
||||
|
||||
suspend fun controlNutrientValve(authHeader: String, action: String): Response<ControlLogResponse>{
|
||||
return controlService.controlNutrientValve(authHeader, action)
|
||||
suspend fun controlNutrientValve(
|
||||
authHeader: String,
|
||||
action: String
|
||||
): Response<ControlLogResponse> {
|
||||
val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
return controlService.controlNutrientValve(authHeader, actionPart)
|
||||
}
|
||||
|
||||
suspend fun controlPump(authHeader: String, action: String): Response<ControlLogResponse> {
|
||||
return controlService.controlPump(authHeader, action)
|
||||
val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
|
||||
return controlService.controlPump(authHeader, actionPart)
|
||||
}
|
||||
|
||||
suspend fun getActuatorStatus(authHeader: String): Response<ActuatorStatusResponse> {
|
||||
return controlService.getActuatorStatus(authHeader)
|
||||
}
|
||||
|
||||
suspend fun getActuatorHistory(authHeader: String): Response<ActuatorHistoryResponse> {
|
||||
return controlService.getActuatorsControlLog(authHeader)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user