def find_history(self, username, page=0, page_size=20): db = get_db() query = db.run( f'MATCH (a:Author)-[:TEACHES]->(c:Course)<-[e:ENROLLED]-(u:User),\ (c:Course)-[:CONDUCTED_IN]->(l:Language),\ (c:Course)-[:PROVIDED_BY]->(p:Provider)\ WHERE (u.username = "******")\ RETURN c.course_id, c.description, c.title, c.photo_link, c.direct_link,\ collect(DISTINCT a.author) as authors , l.language, p.provider, \ e.enrollment_date, e.completion_date, e.status SKIP {page} LIMIT {page_size}' ) result_array = [] for item in query: result_array += [{ "course_id": item[0], "description": item[1], "title": item[2], "photo_link": item[3], "direct_link": item[4], "authors": item[5], "language": item[6], "provider": item[7], "enrollment_date": item[8], "completion_date": item[9], "status": item[10] }] close_db() return result_array
def find_all(self, page=0, page_size=20): db = get_db() courses = db.run( f"MATCH (a:Author)-[:TEACHES]->(c:Course)-[:RELATED_TO]->(k:Knowledge),\ (c:Course)-[:CONDUCTED_IN]->(l:Language), (c:Course)-[:PROVIDED_BY]->(p:Provider)\ RETURN c.course_id, c.description, c.title, c.photo_link, c.direct_link,\ collect(DISTINCT a.author) as authors, collect(DISTINCT k.knowledge) as tags,\ l.language, p.provider SKIP {page} LIMIT {page_size}").records() result_array = [] for item in courses: result_array += [{ "course_id": item[0], "description": item[1], "title": item[2], "photo_link": item[3], "direct_link": item[4], "authors": item[5], "tags": item[6], "language": item[7], "provider": item[8] }] close_db() return result_array
def find(self, query='', page=0, page_size=20): db = get_db() courses = db.run( f'MATCH (c:Course), (a:Author) WHERE (c.title =~".*(?i){query}.*" OR a.author =~".*(?i){query}.*")\ WITH c, a MATCH (a)-[:TEACHES]->(c), \ (c)-[:CONDUCTED_IN]->(l:Language), (c)-[:PROVIDED_BY]->(p:Provider) \ OPTIONAL MATCH (c)-[:RELATED_TO]->(k:Knowledge) \ RETURN c.course_id, c.description, c.title, c.photo_link, c.direct_link, \ collect(DISTINCT a.author) as authors, collect(DISTINCT k.knowledge) as tags, \ l.language, p.provider SKIP {page} LIMIT {page_size}').records() result_array = [] for item in courses: result_array += [{ "course_id": item[0], "description": item[1], "title": item[2], "photo_link": item[3], "direct_link": item[4], "authors": ', '.join(item[5]), "tags": ', '.join(item[6]), "language": item[7], "provider": item[8] }] close_db() return result_array
def get_enrolled_users(self, course_id): db = get_db() results = db.run(''' MATCH (u:User)-[r:ENROLLED]->(c:Course) WHERE c.course_id = $course_id RETURN u.name, u.username, r.enrollment_date, r.completion_date, r.status, u.university ''', course_id=course_id).records() users = [] for user in results: users.append({ 'name': user[0], 'username': user[1], 'enrollment_date': str(user[2]), 'completion_date': str(user[3]) if user[3] != None else None, 'status': user[4], 'university': user[5] }) close_db() return users
def find_by_username(self, username): db = get_db() user = format_cypher_list( db.run('''MATCH (u:User) WHERE u.username = $username RETURN u''', username=username)) close_db() return user
def check_password(self, username, password): db = get_db() query = db.run( f'MATCH (u:User) WHERE u.username="******" AND u.password="******" RETURN COUNT(u)' ).records() for item in query: if item[0] == 1: result = True else: result = False close_db() return result
def create(self): db = get_db() user = { 'age': self.age, 'id': self.id, 'name': self.name, 'password': self.password, 'university': self.university, 'username': self.username } user = db.run('CREATE (a:Author $user) RETURN a', user=user) close_db() return user.value()[0]
def find_all(self, page=0, page_size=20): db = get_db() courses = db.run(f"MATCH (u:User)-[e:ENROLLED]->(c:Course)\ RETURN u.name, collect(DISTINCT c.title) as Courses, collect(DISTINCT c.course_id) as CourseIds, u.username SKIP {page} LIMIT {page_size}" ).records() result_array = [] for item in courses: result_array += [{ "user": item[0], "courses_taken": item[1], "course_id": item[2], "username": item[3] }] close_db() return result_array
def get_weekSections(self, course_id): db = get_db() query = db.run(''' MATCH (w:weekSection) WHERE w.course_id= $course_id RETURN DISTINCT w.week_num, w.week_name, w.week_description ORDER BY w.week_num ''', course_id=course_id).records() result_array = [] for item in query: result_array += [{ "week_num": item[0], "week_title": item[1], "week_description": item[2] }] close_db() return result_array
def find(self, query='', page=0, page_size=20): db = get_db() # Problem: search using author, results in author column only output 1 author (keyword) # and not multiple, if there are any. courses = db.run( f'MATCH (u:User)-[e:ENROLLED]->(c:Course) WHERE (u.name =~ ".*(?i){query}.*")\ RETURN u.name, collect(DISTINCT c.title) as Courses, collect(DISTINCT c.course_id) as CourseIds, u.username SKIP {page} LIMIT {page_size}' ).records() result_array = [] for item in courses: result_array += [{ "user": item[0], "courses_taken": item[1], # '; '.join(item[1]), "course_id": item[2], "username": item[3] }] print(result_array) close_db() return result_array