async def requestReceived(websocket, session, request): global marksSubscribers if websocket.authenticated == False: await websocket.send(convertToJson({'operation' : 'tokenError', 'table' : 'TokenAuthentication'})) return #Websockets endpoints if request['operation'] == 'get': #get endpoint marks = Mark.getMarks(session) response = convertToJson({'operation' : 'get', 'table' : 'Marks', 'data' : marks}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint marks = Mark.getMarks(session) response = convertToJson({'operation' : 'get', 'table' : 'Marks', 'data' : marks}) marksSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['classeId', 'studentId', 'teacherId', 'value', 'date']) == False: print('Not all parameters were provided for ADD in Marks') await websocket.send(convertToJson({'error' : 'Invalid request'})) return mark = dict_as_obj(request['data'], Mark.Mark(), ['markId', 'creationTime']) mark = Mark.addMark(session, mark) response = convertToJson({'operation' : 'add', 'table' : 'Marks', 'data' : mark}) marksSubscribers = set(filter(removeClosedConnection, marksSubscribers)) for subscriber in marksSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['markId']) == False: print('Not all parameters were provided for UPDATE in Marks') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] mark = Mark.getMarksByMarkId(session, data['markId'])[0] mark = dict_as_obj(data, mark) mark = Mark.updateMark(session, mark) response = convertToJson({'operation' : 'update', 'table' : 'Marks', 'data' : mark}) marksSubscribers = set(filter(removeClosedConnection, marksSubscribers)) for subscriber in marksSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['markId']) == False: print('Not all parameters were provided for DELETE in Marks') await websocket.send(convertToJson({'error' : 'Invalid request'})) return mark = Mark.deleteMark(session, request['data']['markId']) response = convertToJson({'operation' : 'delete', 'table' : 'Marks', 'data' : mark}) marksSubscribers = set(filter(removeClosedConnection, marksSubscribers)) for subscriber in marksSubscribers: await subscriber.send(response)
async def requestReceived(websocket, session, request): global studentClassesSubscribers if websocket.authenticated == False: await websocket.send(convertToJson({'operation' : 'tokenError', 'table' : 'TokenAuthentication'})) return #Websockets endpoints if request['operation'] == 'get': #get endpoint studentClasses = StudentClasse.getStudentClasses(session) response = convertToJson({'operation' : 'get', 'table' : 'StudentClasses', 'data' : studentClasses}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint studentClasses = StudentClasse.getStudentClasses(session) response = convertToJson({'operation' : 'get', 'table' : 'StudentClasses', 'data' : studentClasses}) studentClassesSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['studentId', 'classeId']) == False: print('Not all parameters were provided for ADD in StudentClasses') await websocket.send(convertToJson({'error' : 'Invalid request'})) return studentClasse = dict_as_obj(request['data'], StudentClasse.StudentClasse(), ['studentClasseId', 'creationTime']) studentClasse = StudentClasse.addStudentClasse(session, studentClasse) response = convertToJson({'operation' : 'add', 'table' : 'StudentClasses', 'data' : studentClasse}) studentClassesSubscribers = set(filter(removeClosedConnection, studentClassesSubscribers)) for subscriber in studentClassesSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['studentClasseId']) == False: print('Not all parameters were provided for UPDATE in StudentClasses') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] studentClasse = StudentClasse.getStudentClassesByStudentClasseId(session, data['studentClasseId'])[0] studentClasse = dict_as_obj(data, studentClasse) studentClasse = StudentClasse.updateStudentClasse(session, studentClasse) response = convertToJson({'operation' : 'update', 'table' : 'StudentClasses', 'data' : studentClasse}) studentClassesSubscribers = set(filter(removeClosedConnection, studentClassesSubscribers)) for subscriber in studentClassesSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['studentClasseId']) == False: print('Not all parameters were provided for DELETE in StudentClasses') await websocket.send(convertToJson({'error' : 'Invalid request'})) return studentClasse = StudentClasse.deleteStudentClasse(session, request['data']['studentClasseId']) response = convertToJson({'operation' : 'delete', 'table' : 'StudentClasses', 'data' : studentClasse}) studentClassesSubscribers = set(filter(removeClosedConnection, studentClassesSubscribers)) for subscriber in studentClassesSubscribers: await subscriber.send(response)
async def requestReceived(websocket, session, request): global tokenUsersSubscribers #Websockets endpoints if request['operation'] == 'get': #get endpoint tokenUsers = TokenUser.getTokenUsers(session) response = convertToJson({'operation' : 'get', 'table' : 'TokenUsers', 'data' : tokenUsers}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint tokenUsers = TokenUser.getTokenUsers(session) response = convertToJson({'operation' : 'get', 'table' : 'TokenUsers', 'data' : tokenUsers}) tokenUsersSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['username', 'password', 'type']) == False: print('Not all parameters were provided for ADD in TokenUsers') await websocket.send(convertToJson({'error' : 'Invalid request'})) return tokenUser = dict_as_obj(request['data'], TokenUser.TokenUser(), ['tokenUserId', 'creationTime']) tokenUser = TokenUser.addTokenUser(session, tokenUser) response = convertToJson({'operation' : 'add', 'table' : 'TokenUsers', 'data' : tokenUser}) tokenUsersSubscribers = set(filter(removeClosedConnection, tokenUsersSubscribers)) for subscriber in tokenUsersSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['tokenUserId']) == False: print('Not all parameters were provided for UPDATE in TokenUsers') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] tokenUser = TokenUser.getTokenUsersByTokenUserId(session, data['tokenUserId'])[0] tokenUser = dict_as_obj(data, tokenUser) tokenUser = TokenUser.updateTokenUser(session, tokenUser) response = convertToJson({'operation' : 'update', 'table' : 'TokenUsers', 'data' : tokenUser}) tokenUsersSubscribers = set(filter(removeClosedConnection, tokenUsersSubscribers)) for subscriber in tokenUsersSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['tokenUserId']) == False: print('Not all parameters were provided for DELETE in TokenUsers') await websocket.send(convertToJson({'error' : 'Invalid request'})) return tokenUser = TokenUser.deleteTokenUser(session, request['data']['tokenUserId']) response = convertToJson({'operation' : 'delete', 'table' : 'TokenUsers', 'data' : tokenUser}) tokenUsersSubscribers = set(filter(removeClosedConnection, tokenUsersSubscribers)) for subscriber in tokenUsersSubscribers: await subscriber.send(response)
async def requestReceived(websocket, session, request): global notificationsSubscribers #Websockets endpoints if request['operation'] == 'get': #get endpoint notifications = Notification.getNotifications(session) response = convertToJson({'operation' : 'get', 'table' : 'Notifications', 'data' : notifications}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint notifications = Notification.getNotifications(session) response = convertToJson({'operation' : 'get', 'table' : 'Notifications', 'data' : notifications}) notificationsSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['title', 'message']) == False: print('Not all parameters were provided for ADD in Notifications') await websocket.send(convertToJson({'error' : 'Invalid request'})) return notification = dict_as_obj(request['data'], Notification.Notification(), ['notificationId', 'creationTime']) notification = Notification.addNotification(session, notification) response = convertToJson({'operation' : 'add', 'table' : 'Notifications', 'data' : notification}) notificationsSubscribers = set(filter(removeClosedConnection, notificationsSubscribers)) for subscriber in notificationsSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['notificationId']) == False: print('Not all parameters were provided for UPDATE in Notifications') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] notification = Notification.getNotificationsByNotificationId(session, data['notificationId'])[0] notification = dict_as_obj(data, notification) notification = Notification.updateNotification(session, notification) response = convertToJson({'operation' : 'update', 'table' : 'Notifications', 'data' : notification}) notificationsSubscribers = set(filter(removeClosedConnection, notificationsSubscribers)) for subscriber in notificationsSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['notificationId']) == False: print('Not all parameters were provided for DELETE in Notifications') await websocket.send(convertToJson({'error' : 'Invalid request'})) return notification = Notification.deleteNotification(session, request['data']['notificationId']) response = convertToJson({'operation' : 'delete', 'table' : 'Notifications', 'data' : notification}) notificationsSubscribers = set(filter(removeClosedConnection, notificationsSubscribers)) for subscriber in notificationsSubscribers: await subscriber.send(response)
async def requestReceived(websocket, session, request): global cardsSubscribers #Websockets endpoints if request['operation'] == 'get': #get endpoint cards = Card.getCards(session) response = convertToJson({'operation' : 'get', 'table' : 'Cards', 'data' : cards}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint cards = Card.getCards(session) response = convertToJson({'operation' : 'get', 'table' : 'Cards', 'data' : cards}) cardsSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['playerId', 'type', 'number']) == False: print('Not all parameters were provided for ADD in Cards') await websocket.send(convertToJson({'error' : 'Invalid request'})) return card = dict_as_obj(request['data'], Card.Card(), ['cardId', 'creationTime']) card = Card.addCard(session, card) response = convertToJson({'operation' : 'add', 'table' : 'Cards', 'data' : card}) cardsSubscribers = set(filter(removeClosedConnection, cardsSubscribers)) for subscriber in cardsSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['cardId']) == False: print('Not all parameters were provided for UPDATE in Cards') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] card = Card.getCardsByCardId(session, data['cardId'])[0] card = dict_as_obj(data, card) card = Card.updateCard(session, card) response = convertToJson({'operation' : 'update', 'table' : 'Cards', 'data' : card}) cardsSubscribers = set(filter(removeClosedConnection, cardsSubscribers)) for subscriber in cardsSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['cardId']) == False: print('Not all parameters were provided for DELETE in Cards') await websocket.send(convertToJson({'error' : 'Invalid request'})) return card = Card.deleteCard(session, request['data']['cardId']) response = convertToJson({'operation' : 'delete', 'table' : 'Cards', 'data' : card}) cardsSubscribers = set(filter(removeClosedConnection, cardsSubscribers)) for subscriber in cardsSubscribers: await subscriber.send(response)
def patch(self): requestedArgs = getArguments( ['playerId', 'name', 'type', 'creationTime']) args = requestedArgs.parse_args() player = Player.getPlayersByPlayerId(self.session, args['playerId'])[0] player = dict_as_obj(args, player) return Player.updatePlayer(self.session, player)
def patch(self): requestedArgs = getArguments(['classRoomId', 'name', 'creationTime']) args = requestedArgs.parse_args() classRoom = ClassRoom.getClassRoomsByClassRoomId( self.session, args['classRoomId'])[0] classRoom = dict_as_obj(args, classRoom) return ClassRoom.updateClassRoom(self.session, classRoom)
def patch(self): requestedArgs = getArguments( ['notificationId', 'title', 'message', 'creationTime']) args = requestedArgs.parse_args() notification = Notification.getNotificationsByNotificationId( self.session, args['notificationId'])[0] notification = dict_as_obj(args, notification) return Notification.updateNotification(self.session, notification)
def patch(self): requestedArgs = getArguments([ 'userId', 'firstName', 'lastName', 'email', 'type', 'creationTime' ]) args = requestedArgs.parse_args() user = User.getUsersByUserId(self.session, args['userId'])[0] user = dict_as_obj(args, user) return User.updateUser(self.session, user)
def patch(self): requestedArgs = getArguments( ['tokenUserId', 'username', 'password', 'type', 'creationTime']) args = requestedArgs.parse_args() tokenUser = TokenUser.getTokenUsersByTokenUserId( self.session, args['tokenUserId'])[0] tokenUser = dict_as_obj(args, tokenUser) return TokenUser.updateTokenUser(self.session, tokenUser)
def patch(self): requestedArgs = getArguments( ['studentClasseId', 'studentId', 'classeId', 'creationTime']) args = requestedArgs.parse_args() studentClasse = StudentClasse.getStudentClassesByStudentClasseId( self.session, args['studentClasseId'])[0] studentClasse = dict_as_obj(args, studentClasse) return StudentClasse.updateStudentClasse(self.session, studentClasse)
def patch(self): requestedArgs = getArguments( ['teacherId', 'name', 'email', 'creationTime']) args = requestedArgs.parse_args() teacher = Teacher.getTeachersByTeacherId(self.session, args['teacherId'])[0] teacher = dict_as_obj(args, teacher) return Teacher.updateTeacher(self.session, teacher)
def patch(self): requestedArgs = getArguments([ 'markId', 'classeId', 'studentId', 'teacherId', 'value', 'date', 'creationTime' ]) args = requestedArgs.parse_args() mark = Mark.getMarksByMarkId(self.session, args['markId'])[0] mark = dict_as_obj(args, mark) return Mark.updateMark(self.session, mark)
def patch(self): requestedArgs = getArguments([ 'tokenId', 'tokenUserId', 'value', 'address', 'lastUpdate', 'creationTime' ]) args = requestedArgs.parse_args() token = Token.getTokensByTokenId(self.session, args['tokenId'])[0] token = dict_as_obj(args, token) return Token.updateToken(self.session, token)
def patch(self): requestedArgs = getArguments([ 'absenteId', 'classeId', 'studentId', 'teacherId', 'date', 'creationTime' ]) args = requestedArgs.parse_args() absente = Absente.getAbsenteByAbsenteId(self.session, args['absenteId'])[0] absente = dict_as_obj(args, absente) return Absente.updateAbsente(self.session, absente)
def post(self): requestedArgs = getArguments(['studentId', 'classeId']) args = requestedArgs.parse_args() studentClasse = dict_as_obj(args, StudentClasse.StudentClasse()) return StudentClasse.addStudentClasse(self.session, studentClasse)
def post(self): requestedArgs = getArguments( ['classeId', 'studentId', 'teacherId', 'date']) args = requestedArgs.parse_args() absente = dict_as_obj(args, Absente.Absente()) return Absente.addAbsente(self.session, absente)
def patch(self): requestedArgs = getArguments(['studentId', 'name', 'email', 'creationTime']) args = requestedArgs.parse_args() student = Student.getStudentsByStudentId(self.session, args['studentId'])[0] student = dict_as_obj(args, student) return Student.updateStudent(self.session, student)
def post(self): requestedArgs = getArguments(['title', 'message']) args = requestedArgs.parse_args() notification = dict_as_obj(args, Notification.Notification()) return Notification.addNotification(self.session, notification)
def post(self): requestedArgs = getArguments( ['tokenUserId', 'value', 'address', 'lastUpdate']) args = requestedArgs.parse_args() token = dict_as_obj(args, Token.Token()) return Token.addToken(self.session, token)
def post(self): requestedArgs = getArguments(['name', 'email']) args = requestedArgs.parse_args() teacher = dict_as_obj(args, Teacher.Teacher()) return Teacher.addTeacher(self.session, teacher)
def patch(self): requestedArgs = getArguments(['cardId', 'playerId', 'type', 'number', 'creationTime']) args = requestedArgs.parse_args() card = Card.getCardsByCardId(self.session, args['cardId'])[0] card = dict_as_obj(args, card) return Card.updateCard(self.session, card)
def post(self): requestedArgs = getArguments(['name']) args = requestedArgs.parse_args() classRoom = dict_as_obj(args, ClassRoom.ClassRoom()) return ClassRoom.addClassRoom(self.session, classRoom)
def post(self): requestedArgs = getArguments( ['classeId', 'studentId', 'teacherId', 'value', 'date']) args = requestedArgs.parse_args() mark = dict_as_obj(args, Mark.Mark()) return Mark.addMark(self.session, mark)
async def requestReceived(websocket, session, request): global classRoomsSubscribers if websocket.authenticated == False: await websocket.send( convertToJson({ 'operation': 'tokenError', 'table': 'TokenAuthentication' })) return #Websockets endpoints if request['operation'] == 'get': #get endpoint classRooms = ClassRoom.getClassRooms(session) response = convertToJson({ 'operation': 'get', 'table': 'ClassRooms', 'data': classRooms }) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint classRooms = ClassRoom.getClassRooms(session) response = convertToJson({ 'operation': 'get', 'table': 'ClassRooms', 'data': classRooms }) classRoomsSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['name']) == False: print('Not all parameters were provided for ADD in ClassRooms') await websocket.send(convertToJson({'error': 'Invalid request'})) return classRoom = dict_as_obj(request['data'], ClassRoom.ClassRoom(), ['classRoomId', 'creationTime']) classRoom = ClassRoom.addClassRoom(session, classRoom) response = convertToJson({ 'operation': 'add', 'table': 'ClassRooms', 'data': classRoom }) classRoomsSubscribers = set( filter(removeClosedConnection, classRoomsSubscribers)) for subscriber in classRoomsSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['classRoomId']) == False: print('Not all parameters were provided for UPDATE in ClassRooms') await websocket.send(convertToJson({'error': 'Invalid request'})) return data = request['data'] classRoom = ClassRoom.getClassRoomsByClassRoomId( session, data['classRoomId'])[0] classRoom = dict_as_obj(data, classRoom) classRoom = ClassRoom.updateClassRoom(session, classRoom) response = convertToJson({ 'operation': 'update', 'table': 'ClassRooms', 'data': classRoom }) classRoomsSubscribers = set( filter(removeClosedConnection, classRoomsSubscribers)) for subscriber in classRoomsSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['classRoomId']) == False: print('Not all parameters were provided for DELETE in ClassRooms') await websocket.send(convertToJson({'error': 'Invalid request'})) return classRoom = ClassRoom.deleteClassRoom(session, request['data']['classRoomId']) response = convertToJson({ 'operation': 'delete', 'table': 'ClassRooms', 'data': classRoom }) classRoomsSubscribers = set( filter(removeClosedConnection, classRoomsSubscribers)) for subscriber in classRoomsSubscribers: await subscriber.send(response)
def post(self): requestedArgs = getArguments(['playerId', 'type', 'number']) args = requestedArgs.parse_args() card = dict_as_obj(args, Card.Card()) return Card.addCard(self.session, card)
def post(self): requestedArgs = getArguments( ['firstName', 'lastName', 'email', 'type']) args = requestedArgs.parse_args() user = dict_as_obj(args, User.User()) return User.addUser(self.session, user)
def post(self): requestedArgs = getArguments(['name', 'email']) args = requestedArgs.parse_args() student = dict_as_obj(args, Student.Student()) return Student.addStudent(self.session, student)
def post(self): requestedArgs = getArguments(['username', 'password', 'type']) args = requestedArgs.parse_args() tokenUser = dict_as_obj(args, TokenUser.TokenUser()) return TokenUser.addTokenUser(self.session, tokenUser)
async def requestReceived(websocket, session, playersConnected, request): global playersSubscribers #Websockets endpoints if request['operation'] == 'get': #get endpoint players = Player.getPlayers(session) response = convertToJson({'operation' : 'get', 'table' : 'Players', 'data' : players}) await websocket.send(response) elif request['operation'] == 'subscribe': #subscription endpoint players = Player.getPlayers(session) response = convertToJson({'operation' : 'get', 'table' : 'Players', 'data' : players}) playersSubscribers.add(websocket) await websocket.send(response) elif request['operation'] == 'add': #add endpoint if checkArguments(request, ['name', 'type']) == False: print('Not all parameters were provided for ADD in Players') await websocket.send(convertToJson({'error' : 'Invalid request'})) return player = dict_as_obj(request['data'], Player.Player(), ['playerId', 'creationTime']) player = Player.addPlayer(session, player) playersConnected.append({'player':player, 'socket':websocket, 'cards' : [], 'turnPassed' : False, 'rank' : -1, 'score' : 0}) #inform player response = convertToJson({'operation' : 'registered', 'table' : 'Game', 'data' : player}) await websocket.send(response) response = convertToJson({'operation' : 'add', 'table' : 'Players', 'data' : player}) playersSubscribers = set(filter(removeClosedConnection, playersSubscribers)) for subscriber in playersSubscribers: await subscriber.send(response) elif request['operation'] == 'update': #update endpoint if checkArguments(request, ['playerId']) == False: print('Not all parameters were provided for UPDATE in Players') await websocket.send(convertToJson({'error' : 'Invalid request'})) return data = request['data'] player = Player.getPlayersByPlayerId(session, data['playerId'])[0] player = dict_as_obj(data, player) player = Player.updatePlayer(session, player) response = convertToJson({'operation' : 'update', 'table' : 'Players', 'data' : player}) playersSubscribers = set(filter(removeClosedConnection, playersSubscribers)) for subscriber in playersSubscribers: await subscriber.send(response) elif request['operation'] == 'delete': #delete endpoint if checkArguments(request, ['playerId']) == False: print('Not all parameters were provided for DELETE in Players') await websocket.send(convertToJson({'error' : 'Invalid request'})) return player = Player.deletePlayer(session, request['data']['playerId']) response = convertToJson({'operation' : 'delete', 'table' : 'Players', 'data' : player}) playersSubscribers = set(filter(removeClosedConnection, playersSubscribers)) for subscriber in playersSubscribers: await subscriber.send(response)