handler method
- @override
override
Must be implemented
Implementation
@override
Future<Response> handler() async {
final bodyStr = jsonDecode(await request.readAsString());
final shortCode = bodyStr['shortCode'];
final coordinate = bodyStr['coordinate'];
final coordsList = (RegExp(r'[0-9]+.[0-9]+').allMatches(coordinate))
.map((i) => double.parse(i.group(0)!))
.toList();
if (shortCode == null || coordinate == null) {
return Response.badRequest(
body: 'WhatsApp Bot: shortCode and coordinate are required',
);
}
final failureOrUpdate = await orderRepository.setCoordsInAddress(
shortCode, coordsList[0], coordsList[1]);
return failureOrUpdate.fold(
(error) => Response.internalServerError(
body: 'WhatsApp Bot: Failure on setting coords: ${error.message}'),
(_) => Response.ok(json.encode({'success': true})),
);
}