Skip to content

Instantly share code, notes, and snippets.

@esabook
Created May 15, 2019 15:11
Show Gist options
  • Save esabook/a5d7b8ac674acb446c9ec6f381d6f9e9 to your computer and use it in GitHub Desktop.
Save esabook/a5d7b8ac674acb446c9ec6f381d6f9e9 to your computer and use it in GitHub Desktop.
retrofit with filterable query
interface __IReportService {
@GET("ticket/list")
fun getReports(@QueryMap(encoded = true) queries: ReportQuery): Call<__ResponseDTO<Array<__ReportDTO>>>
@POST("ticket/create")
fun postReport(@Body body: __ReportDTO): Call<__ResponseDTO<__ReportDTO>>
@POST("ticket/{ticketId}/update")
fun postUpdateReport(@Path("ticketId") ticketiId: String, @Body body: __ReportDTO): Call<__ResponseDTO<__ReportDTO>>
@POST("ticket/upload/image")
fun postImage(@Body form: RequestBody, @Header("fileUri") fileUri: String): Call<__ReportImageDTO>
@GET("comment/list/{ticketId}/ASC")
fun getComments(@Path("ticketId") ticketId: String): Call<__ResponseDTO<Array<__ReportMessageDTO>>>
@GET("comment/list/{ticketId}/{order}")
fun getComments(@Path("ticketId") ticketId: String, @Path("order") order: String = "ASC"): Call<__ResponseDTO<Array<__ReportMessageDTO>>>
@POST("comment/create")
fun postComment(@Body body: __ReportMessageDTO): Call<__ResponseDTO<__ReportMessageDTO>>
class ReportQuery(var uid: Int = -1) : LinkedHashMap<String, Any?>() {
var assignedToId: String? = null
var verificationStatus: String? = null
var customerId: String? = null
var assetNumber: String? = null
var ownerId: String? = null
var continuationToken: String? = null
var limit = 10
var ticketStatus = -1
var assetType = -1
/**
* we add Build function for manual exposing/excluding property
*/
fun Build(): ReportQuery {
this.clear()
this.Put("assignedToId", assignedToId)
this.Put("verificationStatus", verificationStatus)
this.Put("customerId", customerId)
this.Put("assetNumber", assetNumber)
this.Put("ownerId", ownerId)
this.Put("continuationToken", continuationToken)
this.Put("uid", uid, uid != -1)
this.Put("limit", limit)
this.Put("status", ticketStatus, ticketStatus != -1)
this.Put("type", assetType, assetType != -1)
return this
}
/**
* excluding null or -1 value
*
* @param key
* @param val
*/
internal fun Put(key: String, `val`: Any?) {
this.Put(key, `val`, `val` != null)
}
/**
* excluding expected value
*
* @param key
* @param val
* @param putIf
*/
internal fun Put(key: String, `val`: Any?, putIf: Boolean) {
if (putIf) this[key] = `val`
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment