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.

132 lines
4.8KB

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