You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.7KB

  1. import 'package:dio/dio.dart';
  2. import 'package:farm_tpf/custom_model/CropPlot.dart';
  3. import 'package:farm_tpf/custom_model/Device.dart';
  4. import 'package:farm_tpf/custom_model/EnvironmentParameter.dart';
  5. import 'package:farm_tpf/custom_model/Harvest.dart';
  6. import 'package:farm_tpf/custom_model/LocationUnit.dart';
  7. import 'package:farm_tpf/custom_model/Supply.dart';
  8. import 'package:farm_tpf/custom_model/UpdateNoti.dart';
  9. import 'package:farm_tpf/custom_model/WaterType.dart';
  10. import 'package:farm_tpf/custom_model/account.dart';
  11. import 'package:farm_tpf/custom_model/password.dart';
  12. import 'package:farm_tpf/custom_model/user.dart';
  13. import 'package:farm_tpf/custom_model/user_request.dart';
  14. import 'package:farm_tpf/models/index.dart';
  15. import 'package:farm_tpf/utils/const_common.dart';
  16. import 'package:retrofit/retrofit.dart';
  17. part 'rest_client.g.dart';
  18. @RestApi(baseUrl: ConstCommon.baseUrl)
  19. abstract class RestClient {
  20. factory RestClient(Dio dio, {String baseUrl}) = _RestClient;
  21. @POST("/api/authenticate")
  22. Future<User> login(@Body() UserRequest userRequest);
  23. @GET("/api/account")
  24. Future<Account> getMe();
  25. @POST("/api/account/reset-password/init")
  26. Future<void> forgotPassword(@Body() String email);
  27. @POST("/api/account/reset-password/finish")
  28. Future<void> resetPassword(@Body() Password password);
  29. @POST("/api/account/change-password")
  30. Future<void> changePassword(@Body() Password password);
  31. @PUT("/api/update-my-profile")
  32. Future<Account> updateProfile(@Body() Account account);
  33. @GET("/api/list-supplies-in-warehouses/{type}?q={query}")
  34. Future<List<Supply>> getSupplies(@Path() String type,
  35. {@DioOptions() Options options, @Path() String query = ""});
  36. //Common
  37. @PUT("/api/update-fcmToken")
  38. Future<void> updateFcmToken(@Body() String token);
  39. @PUT("/api/delete-fcmToken")
  40. Future<void> deleteFcmToken(@Body() String token);
  41. //Plot
  42. @GET(
  43. "/api/_search/tb-crops?page={page}&size={size}&sort=id,asc&query={query}")
  44. Future<List<Crop>> getPlots(
  45. {@Path() int page = 0, @Path() int size = 20, @Path() String query = ""});
  46. @GET("/api/listActivityTypesOther")
  47. Future<List<ActionType>> getActionTypes({@DioOptions() Options options});
  48. @GET("/api/water-types")
  49. Future<List<WaterType>> getWaterTypes({@DioOptions() Options options});
  50. @GET("/api/tb-harvests")
  51. Future<List<Harvest>> getHarvests({@DioOptions() Options options});
  52. @GET("/api/listDeviceForActivity")
  53. Future<List<Device>> getDeviceForActivity({@DioOptions() Options options});
  54. @PUT("/api/notifications/update-all")
  55. Future<void> updateAllNotification(@Body() String status);
  56. @PUT("/api/notifications/update")
  57. Future<void> updateNoti(@Body() UpdateNoti updateNoti);
  58. @GET("/api/tb-countries?page={page}&size={size}&query={query}&&sort=name,ASC")
  59. Future<List<LocationUnit>> getCountries(
  60. {@Path() int page = 0,
  61. @Path() int size = 400,
  62. @Path() String query = '',
  63. @DioOptions() Options options});
  64. @GET(
  65. "/api/tb-cities-by-country/{countryId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  66. Future<List<LocationUnit>> getProvinces(@Path() int countryId,
  67. {@Path() int page = 0,
  68. @Path() int size = 20,
  69. @Path() String query = '',
  70. @DioOptions() Options options});
  71. @GET(
  72. "/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  73. Future<List<LocationUnit>> getDistricts(@Path() int provinceId,
  74. {@Path() int page = 0,
  75. @Path() int size = 20,
  76. @Path() String query = '',
  77. @DioOptions() Options options});
  78. @GET(
  79. "/api/tb-wards-by-district/{districtId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  80. Future<List<LocationUnit>> getWards(@Path() int districtId,
  81. {@Path() int page = 0,
  82. @Path() int size = 20,
  83. @Path() String query = '',
  84. @DioOptions() Options options});
  85. //Crop
  86. @GET(
  87. "/api/tb-crops-detail-for-app/{cropId}?page={page}&size={size}&sort=executeDate,DESC")
  88. Future<CropPlot> getCropDetail(@Path() int cropId,
  89. {@Path() int page = 0, @Path() int size = 20});
  90. @GET(
  91. "/api/tb-crops-scan-qrCode/{cropCode}?page={page}&size={size}&sort=executeDate,DESC")
  92. Future<CropPlot> getCropDetailByCode(@Path() String cropCode,
  93. {@Path() int page = 0, @Path() int size = 20});
  94. @PUT("/api/tb-crops")
  95. Future<void> updateCrop(@Body() TbCropDTO crop);
  96. //Device
  97. @GET("/api/listDeviceOfUserCustomers?query={query}")
  98. Future<List<Device>> getDevices({@Path() String query});
  99. //Get environment parameter
  100. @GET("/api/list-environment-updates-display/{cropId}?page={page}&size={size}")
  101. Future<List<EnvironmentParameter>> getEnvironmentParameters(
  102. @Path() int cropId,
  103. {@Path() int page = 0,
  104. @Path() int size = 20});
  105. }