deleteMapping method
Deletes the mapping with the given mappingId
from the slot with the given slotId
.
Implementation
Future<void> deleteMapping({required int slotId, required int mappingId}) async {
if (!state.hasData) {
log('Cannot delete mapping: No data');
return;
}
log('Deleting mapping $mappingId from slot $slotId');
try {
data(
state.requireData.map((s) {
if (s.id == slotId) {
return s.copyWith(mappings: s.mappings.where((m) => m.id != mappingId).toList());
}
return s;
}).toList(),
);
await _datasource.deleteSlotMapping(
token: _auth.state.requireData.pick(Webservice.lb_planner_api),
mappingId: mappingId,
);
log('Deleted mapping $mappingId from slot $slotId');
} catch (e, s) {
log('Failed to delete mapping $mappingId from slot $slotId', e, s);
}
}