Browse Source

change api get supply

master
daivph 5 years ago
parent
commit
681832470e
13 changed files with 66 additions and 73 deletions
  1. +43
    -0
      lib/custom_model/Supply.dart
  2. +3
    -3
      lib/data/api/rest_client.dart
  3. +3
    -3
      lib/data/api/rest_client.g.dart
  4. +3
    -3
      lib/data/repository/repository.dart
  5. +0
    -20
      lib/models/Supply.dart
  6. +0
    -28
      lib/models/Supply.g.dart
  7. +0
    -1
      lib/models/index.dart
  8. +2
    -2
      lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart
  9. +2
    -2
      lib/presentation/screens/actions/state_management_helper/change_supply.dart
  10. +5
    -6
      lib/presentation/screens/resources/bloc/supply_bloc.dart
  11. +4
    -4
      lib/presentation/screens/resources/sc_resource_helper.dart
  12. +0
    -1
      lib/presentation/screens/resources/widget_search.dart
  13. +1
    -0
      lib/utils/const_common.dart

+ 43
- 0
lib/custom_model/Supply.dart View File

class Supply {
int id;
num quantity;
String unit;
int tbWarehouseId;
String tbWarehouseName;
String tbSuppliesName;
int tbSuppliesId;
bool isSelected;

Supply(
{this.id,
this.quantity,
this.unit,
this.tbWarehouseId,
this.tbWarehouseName,
this.tbSuppliesName,
this.tbSuppliesId,
this.isSelected});

Supply.fromJson(Map<String, dynamic> json) {
id = json['id'];
quantity = json['quantity'];
unit = json['unit'];
tbWarehouseId = json['tbWarehouseId'];
tbWarehouseName = json['tbWarehouseName'];
tbSuppliesName = json['tbSuppliesName'];
tbSuppliesId = json['tbSuppliesId'];
isSelected = false;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['quantity'] = this.quantity;
data['unit'] = this.unit;
data['tbWarehouseId'] = this.tbWarehouseId;
data['tbWarehouseName'] = this.tbWarehouseName;
data['tbSuppliesName'] = this.tbSuppliesName;
data['tbSuppliesId'] = this.tbSuppliesId;
return data;
}
}

+ 3
- 3
lib/data/api/rest_client.dart View File

import 'package:farm_tpf/custom_model/Device.dart'; import 'package:farm_tpf/custom_model/Device.dart';
import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; import 'package:farm_tpf/custom_model/EnvironmentParameter.dart';
import 'package:farm_tpf/custom_model/Harvest.dart'; import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/custom_model/WaterType.dart'; import 'package:farm_tpf/custom_model/WaterType.dart';
import 'package:farm_tpf/custom_model/account.dart'; import 'package:farm_tpf/custom_model/account.dart';
import 'package:farm_tpf/custom_model/password.dart'; import 'package:farm_tpf/custom_model/password.dart';
import 'package:farm_tpf/custom_model/user.dart'; import 'package:farm_tpf/custom_model/user.dart';
import 'package:farm_tpf/custom_model/user_request.dart'; import 'package:farm_tpf/custom_model/user_request.dart';
import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/models/index.dart'; import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/utils/const_common.dart'; import 'package:farm_tpf/utils/const_common.dart';
import 'package:retrofit/retrofit.dart'; import 'package:retrofit/retrofit.dart';
@PUT("/api/update-my-profile") @PUT("/api/update-my-profile")
Future<Account> updateProfile(@Body() Account account); Future<Account> updateProfile(@Body() Account account);


@GET("/api/tb-supplies-by-type/{type}")
Future<List<Supply>> getSupplies(@Path() String type);
@GET("/api/list-supplies-in-warehouses/ALL?q={query}")
Future<List<Supply>> getSupplies({@Path() String query = ""});


//Common //Common
@PUT("/api/update-fcmToken") @PUT("/api/update-fcmToken")

+ 3
- 3
lib/data/api/rest_client.g.dart View File

} }


@override @override
getSupplies(type) async {
ArgumentError.checkNotNull(type, 'type');
getSupplies({query = ""}) async {
const _extra = <String, dynamic>{}; const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{}; final queryParameters = <String, dynamic>{};
queryParameters.removeWhere((k, v) => v == null);
final _data = <String, dynamic>{}; final _data = <String, dynamic>{};
final Response<List<dynamic>> _result = await _dio.request( final Response<List<dynamic>> _result = await _dio.request(
'/api/tb-supplies-by-type/$type',
'/api/list-supplies-in-warehouses/ALL?q=$query',
queryParameters: queryParameters, queryParameters: queryParameters,
options: RequestOptions( options: RequestOptions(
method: 'GET', method: 'GET',

+ 3
- 3
lib/data/repository/repository.dart View File

import 'package:farm_tpf/custom_model/Device.dart'; import 'package:farm_tpf/custom_model/Device.dart';
import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; import 'package:farm_tpf/custom_model/EnvironmentParameter.dart';
import 'package:farm_tpf/custom_model/Harvest.dart'; import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/custom_model/WaterType.dart'; import 'package:farm_tpf/custom_model/WaterType.dart';
import 'package:farm_tpf/custom_model/user.dart'; import 'package:farm_tpf/custom_model/user.dart';
import 'package:farm_tpf/custom_model/user_request.dart'; import 'package:farm_tpf/custom_model/user_request.dart';
import 'package:farm_tpf/data/api/dio_provider.dart'; import 'package:farm_tpf/data/api/dio_provider.dart';
import 'package:farm_tpf/data/api/rest_client.dart'; import 'package:farm_tpf/data/api/rest_client.dart';
import 'package:farm_tpf/models/PagedResult.dart'; import 'package:farm_tpf/models/PagedResult.dart';
import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/models/index.dart'; import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/utils/const_common.dart'; import 'package:farm_tpf/utils/const_common.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
return value; return value;
} }


Future<List<Supply>> getSupplies(String type) async {
Future<List<Supply>> getSupplies({String query = ""}) async {
final client = RestClient(dio); final client = RestClient(dio);
return client.getSupplies(type);
return client.getSupplies(query: query);
} }


Object getInstanceClass() { Object getInstanceClass() {

+ 0
- 20
lib/models/Supply.dart View File

import 'package:json_annotation/json_annotation.dart';

part 'Supply.g.dart';

@JsonSerializable()
class Supply {
Supply();

num id;
String name;
String sku;
String manufacturer;
String unit;
num tbSuppliesTypeId;
num tbCustomerId;
bool isSelected;

factory Supply.fromJson(Map<String, dynamic> json) => _$SupplyFromJson(json);
Map<String, dynamic> toJson() => _$SupplyToJson(this);
}

+ 0
- 28
lib/models/Supply.g.dart View File

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'Supply.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

Supply _$SupplyFromJson(Map<String, dynamic> json) {
return Supply()
..id = json['id'] as num
..name = json['name'] as String
..sku = json['sku'] as String
..manufacturer = json['manufacturer'] as String
..unit = json['unit'] as String
..tbSuppliesTypeId = json['tbSuppliesTypeId'] as num
..tbCustomerId = json['tbCustomerId'] as num;
}

Map<String, dynamic> _$SupplyToJson(Supply instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
'sku': instance.sku,
'manufacturer': instance.manufacturer,
'unit': instance.unit,
'tbSuppliesTypeId': instance.tbSuppliesTypeId,
'tbCustomerId': instance.tbCustomerId
};

+ 0
- 1
lib/models/index.dart View File

export 'Supply.dart';
export 'Crop.dart'; export 'Crop.dart';
export 'ResourceHelper.dart'; export 'ResourceHelper.dart';
export 'ActionType.dart'; export 'ActionType.dart';

+ 2
- 2
lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart View File

import 'package:farm_tpf/custom_model/Media.dart'; import 'package:farm_tpf/custom_model/Media.dart';
import 'package:farm_tpf/custom_model/Nursery.dart'; import 'package:farm_tpf/custom_model/Nursery.dart';
import 'package:farm_tpf/custom_model/NurseryDetail.dart'; import 'package:farm_tpf/custom_model/NurseryDetail.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/data/api/app_exception.dart'; import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.dart'; import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
.push(MaterialPageRoute( .push(MaterialPageRoute(
builder: (_) => ResourceHelperScreen( builder: (_) => ResourceHelperScreen(
titleName: "Giá thể", titleName: "Giá thể",
type: ConstCommon.supplyTypeSubStrate,
type: ConstCommon.supplyTypeAll,
selectedId: Get.find<ChangeSupply>().selectedSupplyId), selectedId: Get.find<ChangeSupply>().selectedSupplyId),
fullscreenDialog: false)) fullscreenDialog: false))
.then((value) { .then((value) {

+ 2
- 2
lib/presentation/screens/actions/state_management_helper/change_supply.dart View File

import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';


class ChangeSupply extends GetxController { class ChangeSupply extends GetxController {
void change(Supply supply) { void change(Supply supply) {
currentSupply = supply; currentSupply = supply;
selectedSupplyId = supply.id; selectedSupplyId = supply.id;
selectedSupplyName = supply.name;
selectedSupplyName = supply.tbSuppliesName;
update(); update();
} }



+ 5
- 6
lib/presentation/screens/resources/bloc/supply_bloc.dart View File



import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/data/repository/repository.dart'; import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/utils/bloc/infinity_scroll_bloc.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';


part 'supply_event.dart'; part 'supply_event.dart';
) async* { ) async* {
if (event is DataFetched) { if (event is DataFetched) {
try { try {
final response = await repository.getSupplies(event.type);
final response = await repository.getSupplies(query: event.type);
List<Supply> supplies = response.map((supply) { List<Supply> supplies = response.map((supply) {
if (supply.id == event.selectedId) { if (supply.id == event.selectedId) {
supply.isSelected = true; supply.isSelected = true;
} }
} else if (event is OnRefresh) { } else if (event is OnRefresh) {
try { try {
final response = await repository.getSupplies(event.type);
final response = await repository.getSupplies(query: event.type);
List<Supply> supplies = response.map((supply) { List<Supply> supplies = response.map((supply) {
if (supply.id == event.selectedId) { if (supply.id == event.selectedId) {
supply.isSelected = true; supply.isSelected = true;
} }
} else if (event is OnSearch) { } else if (event is OnSearch) {
try { try {
final response = await repository.getSupplies(event.type);
final response = await repository.getSupplies(query: event.type);
bool query(Supply supply) => bool query(Supply supply) =>
event.searchString.isEmpty || event.searchString.isEmpty ||
supply.name
supply.tbSuppliesName
.toLowerCase() .toLowerCase()
.contains(event.searchString.toLowerCase()); .contains(event.searchString.toLowerCase());
final result = response.where(query).toList(); final result = response.where(query).toList();

+ 4
- 4
lib/presentation/screens/resources/sc_resource_helper.dart View File

import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/data/repository/repository.dart'; import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart';
child: Card( child: Card(
child: Material( child: Material(
child: RadioListTile( child: RadioListTile(
title: Text(item.name.toString()),
subtitle: Text(item.manufacturer.toString()),
title: Text(item.tbSuppliesName.toString()),
subtitle: Text(item.tbWarehouseName.toString()),
value: item, value: item,
groupValue: item.isSelected == null ? null : item,
groupValue: item.isSelected == false ? null : item,
onChanged: (Supply value) { onChanged: (Supply value) {
print("selected value: ${value.id}"); print("selected value: ${value.id}");
Navigator.of(context).pop(value); Navigator.of(context).pop(value);

+ 0
- 1
lib/presentation/screens/resources/widget_search.dart View File

import 'package:farm_tpf/models/Supply.dart';
import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart';
import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';

+ 1
- 0
lib/utils/const_common.dart View File

static const String supplyTypeDung = "PHANBON"; static const String supplyTypeDung = "PHANBON";
static const String supplyTypeSubStrate = "GIATHE"; static const String supplyTypeSubStrate = "GIATHE";
static const String supplyTypeProtectPlant = "THUOCBVTV"; static const String supplyTypeProtectPlant = "THUOCBVTV";
static const String supplyTypeAll = "";
} }


enum CRUDStatus { unknown, add, edit, delete } enum CRUDStatus { unknown, add, edit, delete }

Loading…
Cancel
Save