Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.16 KB | None | 0 0
  1. package com.example.e_commerce.presenter
  2.  
  3. import com.example.e_commerce.api.ApiService
  4. import com.example.e_commerce.model.AddWishlist
  5. import com.example.e_commerce.model.Wishlist
  6. import com.example.e_commerce.view.AddWishtlistView
  7. import retrofit2.Call
  8. import retrofit2.Callback
  9. import retrofit2.Response
  10.  
  11.  
  12. class AddWishlistPresenter (
  13.     private val mainVIew : AddWishtlistView
  14. ){
  15.     fun postCart(cus_id: String, qty : String, pro_id:String) {
  16.         ApiService.create()
  17.             .postChart(cus_id, qty, pro_id)
  18.             .enqueue(object : Callback<AddWishlist> {
  19.                 override fun onFailure(call: Call<AddWishlist>, t: Throwable) {
  20.  
  21.                 }
  22.  
  23.                 override fun onResponse(call: Call<AddWishlist>, response: Response<AddWishlist>) {
  24.                     mainVIew.onSucces(response.body() as AddWishlist)
  25.                 }
  26.  
  27.             })
  28.     }
  29.  
  30.     fun postWishlist(cus_id:String,pro_id:String){
  31.         ApiService.create()
  32.             .postwishlist(cus_id,pro_id)
  33.             .enqueue(object : Callback<Wishlist>{
  34.                 override fun onFailure(call: Call<Wishlist>, t: Throwable) {
  35.  
  36.                 }
  37.  
  38.                 override fun onResponse(call: Call<Wishlist>, response: Response<Wishlist>) {
  39.                     if (response.body() != null){
  40.                         mainVIew.postWishlist(response.body() as Wishlist)
  41.                     }else{
  42.                         mainVIew.onFailedPost()
  43.                     }
  44.  
  45.                 }
  46.  
  47.             })
  48.     }
  49.  
  50.     fun getWishlist(cus_id:String){
  51.         ApiService.create()
  52.             .getWishlist(cus_id)
  53.             .enqueue(object : Callback<List<Wishlist>> {
  54.                 override fun onFailure(call: Call<List<Wishlist>>, t: Throwable) {
  55.  
  56.                 }
  57.  
  58.                 override fun onResponse(call: Call<List<Wishlist>>, response: Response<List<Wishlist>>) {
  59.                     if (response.body() != null){
  60.                         mainVIew.getWishlist(response.body() as List<Wishlist>)
  61.                     }else{
  62.                         mainVIew.onFailedGet()
  63.                     }
  64.                 }
  65.  
  66.             })
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement