diff --git a/API_Interfaces.txt b/API_Interfaces.txt index 241c148..9a73149 100644 --- a/API_Interfaces.txt +++ b/API_Interfaces.txt @@ -26,7 +26,7 @@ UserAPI (api/user) POST -> Create a user if it not already exists In: email = Email and login of the user (must be unique) - role = Role of the user (can be concatenated with -) 1=secrétaire, 2=resp_formation, 3=tuteur_univ, 4=étudiant + role = Role of the user (can be concatenated with -) 1=secrétaire, 2=resp_formation, 3=tuteur_univ, 4=étudiant, 5=tuteur_ent Out: 200 -> UID = : The user already exists with the id USER_ID 201 -> UID = : The user has been successfully created with the id USER_ID @@ -34,7 +34,7 @@ POST -> Create a user if it not already exists PUT -> Modify an existing user In: (Suffix = /byuid/) - role = Role of the user (can be concatenated with -) 1=secrétaire, 2=resp_formation, 3=tuteur_univ, 4=étudiant + role = Role of the user (can be concatenated with -) 1=secrétaire, 2=resp_formation, 3=tuteur_univ, 4=étudiant, 5=tuteur_ent phone = Phone number of the user (00.00.00.00.00) email = Email of the user (must be unique) Out: diff --git a/backend/app/OLA_DATA.mysql b/backend/app/OLA_DATA.mysql index 31fd9a8..1daf4d5 100644 --- a/backend/app/OLA_DATA.mysql +++ b/backend/app/OLA_DATA.mysql @@ -12,7 +12,7 @@ INSERT INTO `USER` VALUES (6, 'tut', '3', 'tut@univ-tlse2.fr', '01.23.45.67.89') INSERT INTO `GROUP` VALUES (1, 'M2_ICE_2016-2017_TEST', '2017', 'Master2 ICE', 'Master 2 Informatique Collaborative en Entreprise', 'Sciences du chômage proffessionnel', 5, 1, '/home/dan/PycharmProjects/OLA/backend/app/OLA_RESSOURCES/M2_ICE_2016-2017_TEST'); INSERT INTO `GROUP` VALUES (2, 'M1_ICE_2016-2017_TEST', '2017', 'Master1 ICE', 'Master 1 Informatique Collaborative en Entreprise', 'Sciences du chômage proffessionnel', 5, 1, '/home/dan/PycharmProjects/OLA/backend/app/OLA_RESSOURCES/M1_ICE_2016-2017_TEST'); -INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 5, 2); -INSERT INTO TUTORSHIP VALUES (DEFAULT, 2, 5, 4); -INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 6, 3); +INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 2, 5); +INSERT INTO TUTORSHIP VALUES (DEFAULT, 2, 4, 5); +INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 3, 6); diff --git a/backend/app/api/UserInfoAPI.py b/backend/app/api/UserInfoAPI.py index 55f3625..c1807e9 100644 --- a/backend/app/api/UserInfoAPI.py +++ b/backend/app/api/UserInfoAPI.py @@ -1,6 +1,8 @@ from flask import session from flask_restful import Resource +from app.model import * + class UserInfoAPI(Resource): """ @@ -8,5 +10,24 @@ class UserInfoAPI(Resource): """ def get(self): - user = session["user"] + user = session.get("user", None) return {'USER': user}, 200 + + +class UserGroupsAPI(Resource): + """ + UserGroups Api Resource + """ + + def get(self): + user = session.get("user", None) + if user is not None: + subquery = LIVRET.select().distinct().with_only_columns([LIVRET.c.tutorship_id]) + query = TUTORSHIP.select( + and_(TUTORSHIP.c.student_id == user["id"], TUTORSHIP.c.id.notin_(subquery))).distinct() + res = query.execute() + liste = [] + for r in res: + liste.append(r.group_id) + + return {'GROUP_LIST': liste}, 200 diff --git a/backend/app/urls.py b/backend/app/urls.py index a841988..5ccd60b 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -1,7 +1,8 @@ from app.api.GroupAPI import GroupAPI +from app.api.LivretAPI import LivretAPI from app.api.LoginAPI import LoginAPI from app.api.UserAPI import UserAPI -from app.api.UserInfoAPI import UserInfoAPI +from app.api.UserInfoAPI import UserInfoAPI, UserGroupsAPI from app.api.exampleapi import SomeApi from app.core import api @@ -9,6 +10,8 @@ from app.core import api api.add_resource(SomeApi, '/api/someapi', '/api/someapi/') api.add_resource(LoginAPI, '/api/login') api.add_resource(UserInfoAPI, '/api/userInfo') +api.add_resource(UserGroupsAPI, '/api/userGroups') api.add_resource(UserAPI, '/api/user', '/api/user/byuid/', '/api/user/byemail/', '/api/user/byhash/') api.add_resource(GroupAPI, '/api/group', '/api/group/bygid/', '/api/group/byname/') +api.add_resource(LivretAPI, '/api/livret', '/api/livret/byuid/')