get all tutors

This commit is contained in:
Mieszko Wrzeszczyński 2018-10-26 14:04:52 +02:00
parent aa6810a633
commit 31f7408ea6
3 changed files with 15 additions and 9 deletions

View File

@ -12,7 +12,9 @@ import android.view.View;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors; import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.Tutor; import com.uam.wmi.findmytutor.model.Tutor;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
@ -33,7 +35,7 @@ public class UsersListActivity extends AppCompatActivity {
private UserService apiService; private UserService apiService;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private TutorsAdapter mAdapter; private TutorsAdapter mAdapter;
private List<Tutor> tutorsList = new ArrayList<>(); private List<User> tutorsList = new ArrayList<>();
@BindView(R.id.coordinator_layout) @BindView(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -62,18 +64,18 @@ public class UsersListActivity extends AppCompatActivity {
private void fetchAllTutors() { private void fetchAllTutors() {
disposable.add( disposable.add(
apiService.getPagedTutors(1) apiService.apiUsersGet()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver <PagedResultReturnedTutors>() { .subscribeWith(new DisposableSingleObserver <ReturnedTutors>() {
@Override @Override
public void onSuccess(PagedResultReturnedTutors pagedResult) { public void onSuccess(ReturnedTutors pagedResult) {
tutorsList.clear(); tutorsList.clear();
tutorsList.addAll(pagedResult.getResults().getTutors()); tutorsList.addAll(pagedResult.getTutors());
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
Log.e("TUTORS", String.valueOf(pagedResult.getResults().getTutors())); Log.e("TUTORS", String.valueOf(pagedResult.getTutors()));
} }

View File

@ -2,6 +2,7 @@ package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.IsUsingListBool; import com.uam.wmi.findmytutor.model.IsUsingListBool;
import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors; import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.StudentIdModel; import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
@ -23,6 +24,9 @@ public interface UserService {
@GET("api/users") @GET("api/users")
Single <List<User>> getAllUsers(); Single <List<User>> getAllUsers();
@GET("api/users")
Single<ReturnedTutors> apiUsersGet();
@POST("api/users") @POST("api/users")
Completable createUser(@Body User user); Completable createUser(@Body User user);

View File

@ -23,9 +23,9 @@ import butterknife.ButterKnife;
public class TutorsAdapter extends RecyclerView.Adapter<TutorsAdapter.MyViewHolder> { public class TutorsAdapter extends RecyclerView.Adapter<TutorsAdapter.MyViewHolder> {
private Context context; private Context context;
private List<Tutor> tutorsList; private List<User> tutorsList;
public TutorsAdapter(Context context, List<Tutor> tutors) { public TutorsAdapter(Context context, List<User> tutors) {
this.context = context; this.context = context;
this.tutorsList = tutors; this.tutorsList = tutors;
@ -63,7 +63,7 @@ public class TutorsAdapter extends RecyclerView.Adapter<TutorsAdapter.MyViewHold
@Override @Override
public void onBindViewHolder(MyViewHolder holder, int position) { public void onBindViewHolder(MyViewHolder holder, int position) {
Tutor tutor = tutorsList.get(position); User tutor = tutorsList.get(position);
Log.e("tutor", tutor.toString()); Log.e("tutor", tutor.toString());
holder.firstName.setText(tutor.getFirstName()); holder.firstName.setText(tutor.getFirstName());