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
|
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.ActuatorStatusResponse
|
||||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
||||||
|
import okhttp3.RequestBody
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.Body
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Header
|
import retrofit2.http.Header
|
||||||
|
import retrofit2.http.Multipart
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Part
|
||||||
|
|
||||||
interface ControlService {
|
interface ControlService {
|
||||||
|
// get all actuator status
|
||||||
@GET("api/actuators/status")
|
@GET("api/actuators/status")
|
||||||
suspend fun getActuatorStatus(
|
suspend fun getActuatorStatus(
|
||||||
@Header("Authorization") authHeader: String,
|
@Header("Authorization") authHeader: String,
|
||||||
): Response<ActuatorStatusResponse>
|
): Response<ActuatorStatusResponse>
|
||||||
|
|
||||||
|
// push control water valve
|
||||||
|
@Multipart
|
||||||
@POST("api/actuators/water-valve/control")
|
@POST("api/actuators/water-valve/control")
|
||||||
suspend fun controlWaterValve(
|
suspend fun controlWaterValve(
|
||||||
@Header("Authorization") authHeader: String,
|
@Header("Authorization") authHeader: String,
|
||||||
@Body action: String,
|
@Part("action") action: RequestBody
|
||||||
): Response<ControlLogResponse>
|
): Response<ControlLogResponse>
|
||||||
|
|
||||||
|
// push control nutrient valve
|
||||||
|
@Multipart
|
||||||
@POST("api/actuators/nutrient-valve/control")
|
@POST("api/actuators/nutrient-valve/control")
|
||||||
suspend fun controlNutrientValve(
|
suspend fun controlNutrientValve(
|
||||||
@Header("Authorization") authHeader: String,
|
@Header("Authorization") authHeader: String,
|
||||||
@Body action: String,
|
@Part("action") action: RequestBody
|
||||||
): Response<ControlLogResponse>
|
): Response<ControlLogResponse>
|
||||||
|
|
||||||
|
// push control pump
|
||||||
|
@Multipart
|
||||||
@POST("api/actuators/pump/control")
|
@POST("api/actuators/pump/control")
|
||||||
suspend fun controlPump(
|
suspend fun controlPump(
|
||||||
@Header("Authorization") authHeader: String,
|
@Header("Authorization") authHeader: String,
|
||||||
@Body action: String,
|
@Part("action") action: RequestBody
|
||||||
): Response<ControlLogResponse>
|
): 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
|
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.ActuatorStatusResponse
|
||||||
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
|
||||||
import com.syaroful.agrilinkvocpro.control_feature.data.network.ControlService
|
import com.syaroful.agrilinkvocpro.control_feature.data.network.ControlService
|
||||||
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
|
||||||
class ControlRepository(
|
class ControlRepository(
|
||||||
private val controlService: ControlService
|
private val controlService: ControlService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun controlWaterValve(authHeader: String, action: String): Response<ControlLogResponse>{
|
suspend fun controlWaterValve(
|
||||||
return controlService.controlWaterValve(authHeader, action)
|
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>{
|
suspend fun controlNutrientValve(
|
||||||
return controlService.controlNutrientValve(authHeader, action)
|
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>{
|
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> {
|
suspend fun getActuatorStatus(authHeader: String): Response<ActuatorStatusResponse> {
|
||||||
return controlService.getActuatorStatus(authHeader)
|
return controlService.getActuatorStatus(authHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getActuatorHistory(authHeader: String): Response<ActuatorHistoryResponse> {
|
||||||
|
return controlService.getActuatorsControlLog(authHeader)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user