createGroup method
takes AtGroup as an input and creates the group on success return AtGroup otherwise null
Implementation
@override
Future<AtGroup?> createGroup(AtGroup? atGroup) async {
if (atGroup == null || atGroup.groupName == null) {
throw Exception('Group name is null or empty String');
}
var id = atGroup.groupId;
if (id != null) {
var group = await getGroup(id);
if (group != null) {
throw AlreadyExistsException('Group is already exisits with id $id');
}
}
//create groupID
var groupId = Uuid().v1();
atGroup.groupId = groupId;
var groupName = atGroup.groupName;
var atKey = _formKey(KeyType.group, key: groupId);
//update atGroup
atGroup.createdBy = AtUtils.fixAtSign(atSign);
atGroup.updatedBy = AtUtils.fixAtSign(atSign);
atGroup.createdOn = DateTime.now();
atGroup.updatedOn = DateTime.now();
var json = atGroup.toJson();
var value = jsonEncode(json);
var result = await atClient!.put(atKey, value);
if (result) {
print('Group creation successful. Adding to group list');
var atGroupBasicInfo = AtGroupBasicInfo(groupId, groupName);
// add AtGroupBasicInfo object to list of groupNames
var success = await _addToGroupList(atGroupBasicInfo);
print('Add to group list result : $success');
return atGroup;
}
return null;
}