public class Backend<T> {
private int code;
private List<T> data;
private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public List<T> getData() {
return data;
}
public void setData(List<T> data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
public interface HttpService {
@
GET("companies")
Call<Backend<Company>> getCompanies();
@
GET("schedules")
Call<Backend<Schedule>> getSchedules();
}
public class HttpClient {
private static HttpService httpService = new Retrofit.Builder()
.baseUrl("http://192.168.1.24:8088/api/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(HttpService.class);
public static List<Company> getCompanies() {
try {
return httpService.getCompanies().execute().body().getData();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static List<Schedule> getSchedules() {
try {
return httpService.getSchedules().execute().body().getData();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}