def createGroup(self, json): dao = GroupDAO() chat_name = json['chat_name'] user_id = json['user_id'] chat_group_id = dao.createGroup(chat_name, user_id) dao.addContactTogroup(chat_group_id, user_id) #add user to group return jsonify(chat_group_id), 201
def getGroupByGroupID(self, gID): dao = GroupDAO() result = dao.getGroupByGroupID(gID) if not result: return jsonify(Error="Not found"), 404 mapped_result = mapGroupToDict(result) return jsonify(mapped_result)
def removeMember(self, chat_group_id, json): dao = GroupDAO() user_id = json['user_id'] if user_id: result = dao.removeContactFromGroup(chat_group_id, user_id) return jsonify(result), 200 else: return jsonify(Error="Unexpected attributes in post request"), 400
def getAllGroups(self): dao = GroupDAO() result = dao.getAllGroups() if not result: return jsonify(Error="Not found"), 404 mapped_result = [] for r in result: mapped_result.append(mapGroupToDict(r)) return jsonify(mapped_result)
def getGroupMembersByGroupID(self, gID): dao = GroupDAO() result = dao.getGroupMembersByGroupID(gID) if not result: return jsonify(Error="Not found"), 404 mapped_result = [] for r in result: mapped_result.append(mapUserToDict(r)) return jsonify(mapped_result)
def removeMember(self, gID, json): dao = GroupDAO() if len(json) != 1: return jsonify(Error="Malformed post request"), 400 else: contactid = json['contactid'] if contactid: result = dao.removeContactFromGroup(gID, contactid) return jsonify(result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def deleteGroup(self, json): dao = GroupDAO() if len(json) != 2: return jsonify(Error="Malformed post request"), 400 else: groupId = json['groupId'] ownerId = json['ownerid'] if groupId and ownerId: result = dao.deleteGroup(groupId, ownerId) return jsonify(result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def searchGroup(self, args): groupname = args.get("groupname") dao = GroupDAO() if groupname: result = dao.getGroupByName(groupname) return jsonify(result)
def getAllgroups(self): dao = GroupDAO() result = dao.getAllGroups() return jsonify(Users=result)
def getMembersByGroupID(self, gID): dao = GroupDAO() result = dao.getMembersByGroupID(gID) return jsonify(Members=result)
def getGroupOwnerByID(self, gID): dao = GroupDAO() result = dao.getGroupOwnerByID(gID) return jsonify(Owner=result)
def getGroupById(self, gID): dao = GroupDAO() result = dao.getGroupByID(gID) return jsonify(User=result)
def deleteGroup(self, json): dao = GroupDAO() chat_group_id = json['chat_group_id'] user_id = json['user_id'] result = dao.deleteGroup(chat_group_id, user_id) return jsonify(result), 201