Improve query to obtain the merchants information from the webservice. Move the Merchant model to the entities folder and annotate it so it can be used to create a Room table. Create the Teller entity to be used to fetch the Tellers info from the webservice and create the tellers Room table. Removed not needed classes Ambassador and AmbassadorLocation.
This commit is contained in:
parent
4c3822e8c1
commit
e043b83b36
8 changed files with 56 additions and 98 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.database.entities
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "merchants")
|
||||||
|
data class Merchant(
|
||||||
|
@PrimaryKey
|
||||||
|
@ColumnInfo(name = "id") val _id: String,
|
||||||
|
@ColumnInfo(name = "name") val name: String,
|
||||||
|
@ColumnInfo(name = "address") val address: String,
|
||||||
|
@ColumnInfo(name = "lat") val lat: Float,
|
||||||
|
@ColumnInfo(name = "lon") val lon: Float,
|
||||||
|
@ColumnInfo(name = "phone") val phone: String,
|
||||||
|
@ColumnInfo(name = "telegram") val telegram: String,
|
||||||
|
@ColumnInfo(name = "website") val website: String
|
||||||
|
)
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.database.entities
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "tellers")
|
||||||
|
data class Teller(
|
||||||
|
@PrimaryKey
|
||||||
|
@ColumnInfo(name = "id") val _id: String,
|
||||||
|
@ColumnInfo(name = "name") val gt_name: String,
|
||||||
|
@ColumnInfo(name = "address") val address: String,
|
||||||
|
@ColumnInfo(name = "lat") val lat: Float,
|
||||||
|
@ColumnInfo(name = "lon") val lon: Float,
|
||||||
|
@ColumnInfo(name = "phone") val phone: String,
|
||||||
|
@ColumnInfo(name = "telegram") val telegram: String,
|
||||||
|
@ColumnInfo(name = "website") val url: String
|
||||||
|
)
|
|
@ -15,8 +15,7 @@ import com.google.android.gms.maps.model.MarkerOptions
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
|
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.bitsybitshareswallet.models.Merchant
|
import cy.agorise.bitsybitshareswallet.network.MerchantsWebservice
|
||||||
import cy.agorise.bitsybitshareswallet.network.AmbassadorService
|
|
||||||
import cy.agorise.bitsybitshareswallet.network.FeathersResponse
|
import cy.agorise.bitsybitshareswallet.network.FeathersResponse
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
@ -27,6 +26,7 @@ import android.graphics.Bitmap
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptor
|
import com.google.android.gms.maps.model.BitmapDescriptor
|
||||||
|
import cy.agorise.bitsybitshareswallet.database.entities.Merchant
|
||||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,8 +53,6 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
|
||||||
mapFragment.getMapAsync(this)
|
mapFragment.getMapAsync(this)
|
||||||
|
|
||||||
merchantIcon = getMarkerIconFromDrawable(resources.getDrawable(R.drawable.ic_pin_merchants, null))
|
merchantIcon = getMarkerIconFromDrawable(resources.getDrawable(R.drawable.ic_pin_merchants, null))
|
||||||
|
|
||||||
// TODO https://github.com/Agorise/bitsy-wallet/blob/feat_merchants/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MapFragment.kt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,8 +75,8 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
|
||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val ambassadorService = retrofit.create<AmbassadorService>(AmbassadorService::class.java)
|
val ambassadorService = retrofit.create<MerchantsWebservice>(MerchantsWebservice::class.java)
|
||||||
val call = ambassadorService.allMerchants
|
val call = ambassadorService.getMerchants(0)
|
||||||
call.enqueue(this)
|
call.enqueue(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package cy.agorise.bitsybitshareswallet.models
|
|
||||||
|
|
||||||
class Ambassador(var id: String?, var account: String?, var country: String?, var city: String?) {
|
|
||||||
var cityId: String? = null
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package cy.agorise.bitsybitshareswallet.models
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull
|
|
||||||
|
|
||||||
class AmbassadorLocation(
|
|
||||||
var id: String?,
|
|
||||||
var name: String?,
|
|
||||||
var country: String?
|
|
||||||
) : Comparable<AmbassadorLocation> {
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return this.name!!
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
return other is AmbassadorLocation && id == other.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun compareTo(@NonNull other: AmbassadorLocation): Int {
|
|
||||||
return name!!.compareTo(other.name!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id?.hashCode() ?: 0
|
|
||||||
result = 31 * result + (name?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (country?.hashCode() ?: 0)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package cy.agorise.bitsybitshareswallet.models
|
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class Merchant {
|
|
||||||
|
|
||||||
var id: String? = null
|
|
||||||
var address: String? = null
|
|
||||||
var phone: String? = null
|
|
||||||
var name: String? = null
|
|
||||||
var lat: Float = 0F
|
|
||||||
var lon: Float = 0F
|
|
||||||
var city: String? = null
|
|
||||||
var country: String? = null
|
|
||||||
var createdAt: Date? = null
|
|
||||||
var updatedAt: Date? = null
|
|
||||||
var __v: Int = 0
|
|
||||||
|
|
||||||
constructor() {}
|
|
||||||
constructor(id: String) {
|
|
||||||
this.id = id
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(_id: String, address: String, phone: String, name: String, lat: Float, lon: Float, city: String, country: String, createdAt: Date, updatedAt: Date, __v: Int) {
|
|
||||||
this.id = _id
|
|
||||||
this.address = address
|
|
||||||
this.phone = phone
|
|
||||||
this.name = name
|
|
||||||
this.lat = lat
|
|
||||||
this.lon = lon
|
|
||||||
this.city = city
|
|
||||||
this.country = country
|
|
||||||
this.createdAt = createdAt
|
|
||||||
this.updatedAt = updatedAt
|
|
||||||
this.__v = __v
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package cy.agorise.bitsybitshareswallet.network
|
|
||||||
|
|
||||||
import cy.agorise.bitsybitshareswallet.models.Ambassador
|
|
||||||
import cy.agorise.bitsybitshareswallet.models.AmbassadorLocation
|
|
||||||
import cy.agorise.bitsybitshareswallet.models.Merchant
|
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
|
||||||
import retrofit2.http.Query
|
|
||||||
|
|
||||||
interface AmbassadorService {
|
|
||||||
|
|
||||||
//https://ambpay.palmpay.io/api/v1/merchants?%24sort%5Baccount%5D=1&%24limit=50&%24skip=0
|
|
||||||
@get:GET("/api/v1/merchants?%24sort%5Baccount%5D=1&%24limit=50&%24skip=0")
|
|
||||||
val allMerchants: Call<FeathersResponse<Merchant>>
|
|
||||||
|
|
||||||
@GET("/api/v1/ambassadors")
|
|
||||||
fun getAmbassadors(@Query("cityId") cityId: String): Call<FeathersResponse<Ambassador>>
|
|
||||||
|
|
||||||
@GET("/api/v1/cities")
|
|
||||||
fun getAllCitiesSync(@Query("\$skip") skip: Long): Call<FeathersResponse<AmbassadorLocation>>
|
|
||||||
}
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.network
|
||||||
|
|
||||||
|
import cy.agorise.bitsybitshareswallet.database.entities.Merchant
|
||||||
|
import cy.agorise.bitsybitshareswallet.database.entities.Teller
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
interface MerchantsWebservice {
|
||||||
|
|
||||||
|
@GET("/api/v1/merchants")
|
||||||
|
fun getMerchants(@Query(value = "\$skip") skip: Int): Call<FeathersResponse<Merchant>>
|
||||||
|
|
||||||
|
@GET("api/v2/tellers")
|
||||||
|
fun getTellers(@Query(value = "\$skip") skip: Int): Call<FeathersResponse<Teller>>
|
||||||
|
}
|
Loading…
Reference in a new issue