Implemented settings, new scan, enhanced UI/UX
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:docuframe/docuframe.dart' as df;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/exceptions.dart';
|
||||
import 'package:hl_lieferservice/services/erpframe.dart';
|
||||
import 'package:hl_lieferservice/util.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../dto/basic_response.dart';
|
||||
import '../../../dto/car_add.dart';
|
||||
@ -14,23 +17,31 @@ class CarService extends ErpFrameService {
|
||||
CarService({required super.config});
|
||||
|
||||
Future<Car> addCar(String plate, int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_addCar",
|
||||
parameter: CarAddDTO.make(teamId, plate).toJson()
|
||||
as Map<String, dynamic>);
|
||||
debugPrint(jsonEncode({"team_id": teamId.toString(), "plate": plate}));
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
debugPrint(responseJson.toString());
|
||||
var response = await post(
|
||||
urlBuilder("_web_addCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"team_id": teamId.toString(), "plate": plate},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
var body = response.body;
|
||||
|
||||
debugPrint("BODY: $body");
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(body);
|
||||
CarAddResponseDTO responseDto = CarAddResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
return Car(
|
||||
id: int.parse(responseDto.car.id), plate: responseDto.car.plate);
|
||||
id: int.parse(responseDto.car.id),
|
||||
plate: responseDto.car.plate,
|
||||
);
|
||||
} else {
|
||||
throw responseDto.message;
|
||||
}
|
||||
@ -40,26 +51,22 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> editCar(Car car) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
var response = await post(
|
||||
urlBuilder("_web_editCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"id": car.id.toString(), "plate": car.plate},
|
||||
);
|
||||
|
||||
debugPrint(car.plate);
|
||||
debugPrint(car.id.toString());
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_editCar",
|
||||
parameter: {"id": car.id, "plate": car.plate});
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
|
||||
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
|
||||
@ -75,22 +82,22 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeCar(int carId, int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_removeCar",
|
||||
parameter: {"team_id": teamId, "id": carId});
|
||||
var response = await post(
|
||||
urlBuilder("_web_removeCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"team_id": teamId.toString(), "id": carId.toString()},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
|
||||
|
||||
@ -105,25 +112,28 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Car>> getCars(int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_getCars", parameter: {"team_id": teamId});
|
||||
|
||||
debugPrint(teamId.toString());
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
debugPrint("RESPONSE");
|
||||
debugPrint(responseJson.toString());
|
||||
var response = await post(
|
||||
urlBuilder("_web_getCars"),
|
||||
headers: getSessionOrThrow(),
|
||||
body:{"team_id": teamId.toString()},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
var body = response.body;
|
||||
|
||||
debugPrint("BODY: $body");
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
CarGetResponseDTO responseDto = CarGetResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
@ -139,8 +149,6 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user