def chats(): handler = ChatsHandler() adminHandler = AdminsHandler() usersHandler = UsersHandler() #Json format recieves name of group and name of administrator #json = {'group_name': 'DB Class', 'first_name': 'John', 'last_name':'Doe'} if request.method == 'POST': # PRE: user must exist if (handler.checkGroup(request.json) is None): #check if group already exist return handler.registerGroup( request.json ) #recieves group name and user name (admin) from form else: return jsonify(Error="Invalid registration."), 405 elif request.method == 'DELETE': # PRE: user must exist if (handler.checkGroup(request.json) is None): #check if group already exist return jsonify(Error="Invalid group."), 405 else: return handler.removeGroup( request.json ) #recieves name of user trying to delete and group elif request.method == 'GET': return handler.getAllChats() else: return jsonify(Error="Method not allowed."), 405
def getChatById(chat_id): handler = ChatsHandler() if request.method == 'GET': return handler.getChatByID(chat_id) elif request.method == 'DELETE': if handler.checkGroup( request.json) is None: # check if group already exist return jsonify(Error="Invalid group."), 405 else: return handler.removeGroup(request.json) else: return jsonify(Error="Method not allowed"), 405
def chatsByAdmin(user_id): handler = AdminsHandler() contactHandler = ContactHandler() groupHandler = ChatsHandler() memberHandler = MembershipHandler() # JSON FORMAT #Group name and name of user to add/remove to group #json = {'group_name':'DB Class','first_name': 'John', 'last_name': 'Doe'} if request.method == 'GET': return handler.getChatsAdministratedByUser(user_id) # Add a user to a group elif request.method == 'POST': # check if user and group exist # if ( (memberHandler.checkContact(request.json) is not None) and (groupHandler.checkGroup(request.form) is not None) ): # return memberHandler.addMember(request.json, user_id) # returns user name added and group in which was added, user_id is of admin if ((groupHandler.checkGroup(request.form) is not None)): return memberHandler.addMember( request.json, user_id ) # returns user name added and group in which was added, user_id is of admin else: return jsonify( Error="User trying to add or group, doesn't exists."), 405 elif request.method == 'DELETE': # check if user and group exist #print(form) if ((memberHandler.checkContact(request.json) is not None) and (groupHandler.checkGroup(request.form) is not None)): return memberHandler.removeMember( request.json, user_id ) # returns user name of member removed, parameter admin_id else: return jsonify(Error="Member or group doesn't exists."), 405 else: return jsonify(Error="Method not allowed"), 405
def getChatById(chat_id): handler = ChatsHandler() return handler.getChatByID(chat_id)
def chats(): handler = ChatsHandler() return handler.getAllChats()