示例#1
0
    def get(self):
        """
        Return les evenelents que l'utilisateur a créée
        :return:
        """
        user = token_service.get_user_by_token()

        evenements = user.evenements_cree

        res = {}
        indice = 0
        for event in evenements:
            res[indice] = {
                "id": event.id,
                "titre": event.titre,
                "description": event.description,
                "date": str(event.date),
                "autheur": event.author.username
            }
            indice += 1

        return {
            "response": "SUCCESS",
            "message": "Liste des evenement.",
            "evenements": res
        }
示例#2
0
    def post(self):
        """
        Permet a un utilisateur de créée un evenement
        :return:
        """
        data = request.get_json()

        user = token_service.get_user_by_token()

        evenement = Evenement(author=user)
        evenement.titre = data["titre"]
        evt_date = data["date"]
        evenement.date = datetime.strptime(evt_date, '%d/%m/%Y %H:%M')
        if "description" in data:
            evenement.description = data["description"]

        if "isPrivate" in data:
            evenement.isprivate = data["isPrivate"]

        db.session.add(evenement)

        discution = Discution(evenemnt=evenement)

        db.session.add(discution)

        db.session.commit()

        return {"response": "SUCCESS", "message": "Evenement is created"}
示例#3
0
 def delete(self):
     """
     Permet de suprimer son compte
     :return:
     """
     user = token_service.get_user_by_token()
     db.session.delete(user)
     db.session.commit()
     del session['api_sessions_token']
     return {"response": "SUCCESS", "message": "Goodbye."}
示例#4
0
    def post(self, id_user):
        user = token_service.get_user_by_token()
        user_followed: User = User.query.get(id_user)

        user_followed.request_follwed.append(user)
        db.session.commit()

        return {
            "response": "SUCCESS",
            "message": "Request follow user " + str(id_user)
        }
示例#5
0
    def delete(self, id_evenement):
        event: Evenement = Evenement.query.get(id_evenement)
        user = token_service.get_user_by_token()

        if user not in event.inscrits:
            if user is None:
                return {"response": "Error", "message": "User  Not autorized"}, 403

        event.inscrits.remove(user)

        db.session.commit()

        return {"response": "SUCCESS",
                "message": "Desinscription for Evenement : " + str(id_evenement) + " is validate"}
示例#6
0
    def delete(self):
        """
        Permet a un utilisateur de suprimmer un evenement
        :return:
        """
        data = request.get_json()

        id_event = data["id_event"]

        user = token_service.get_user_by_token()

        evenement = user.evenements_cree.filter_by(id=id_event).first()

        db.session.delete(evenement)
        db.session.commit()

        return {"response": "SUCCESS", "message": "Evenement is delete"}
示例#7
0
    def put(self, id_evenement):
        """

        :param id_evenement:
        :return:
        """
        event: Evenement = Evenement.query.get(id_evenement)
        user = token_service.get_user_by_token()

        if user is None:
            return {"response": "Error", "message": "Inscription Not autorized"}, 403

        event.inscrits.append(user)

        db.session.commit()

        return {"response": "SUCCESS", "message": "Inscription for Evenement : " + str(id_evenement) + " is validate"}
示例#8
0
    def get(self):
        """
        Return son profil utilisateur
        :return:
        """
        user = token_service.get_user_by_token()
        evenements = user.evenements_cree
        evenement_follow = user.evenements
        followeds = user.followed
        profile = {"username": user.username, "email": user.email}

        indice = 0
        profile["evenements"] = {}
        for event in evenements:
            profile["evenements"][indice] = {
                "id": event.id,
                "titre": event.titre,
                "description": event.description,
                "date": str(event.date)
            }
            indice += 1

        indice = 0
        profile["followEvent"] = {}
        for event in evenement_follow:
            profile["followEvent"][indice] = {
                "id": event.id,
                "titre": event.titre,
                "description": event.description,
                "date": str(event.date),
                "autheur": event.author.username
            }
            indice += 1

        indice = 0
        profile["amies"] = {}
        for followed in followeds:
            profile["amies"][indice] = {"username": followed.username}

        return {
            "response": "SUCCESS",
            "message": "Your profile",
            "profile": profile
        }
示例#9
0
    def get(self):
        """
        Return les users que le user courant follow
        :return:
        """
        user = token_service.get_user_by_token()

        followeds = user.followed

        indice = 0
        follow = {}
        for followed in followeds:
            follow[indice] = {"username": followed.username}

        return {
            "response": "SUCCESS",
            "message": "You follow",
            "followeds": follow
        }
示例#10
0
    def post(self, id_evenement):
        data = request.get_json()
        data_message = data["message"]

        event: Evenement = Evenement.query.get(id_evenement)
        user = token_service.get_user_by_token()

        message = Message(message_author=user)
        message.text = data_message

        message.date = datetime.now()

        discution: Discution = event.discution
        discution.message.append(message)

        db.session.commit()

        return {"response": "SUCCESS",
                "message": "Discution  for Evenement"}
示例#11
0
    def get(self):
        """
        return l'ensemble des events public
        et des events créée par les utilisateur que le user follow
        :return: dict
        """

        user = token_service.get_user_by_token()

        events = Evenement.query.filter_by(isprivate=False)

        if user is not None:
            for follow in user.followed:
                events_follow = Evenement.query.filter_by(author=follow)
                events = events.union(events_follow)

        res = {}

        for event in events:
            res[event.id] = {"titre": event.titre, "description": event.description, "date": str(event.date),
                             "autheur": event.author.username}
        return {"response": "SUCCESS", "message": "Get Evenements : ", "evenements": res}
示例#12
0
    def get(self, id_evenement):
        event: Evenement = Evenement.query.get(id_evenement)
        user = token_service.get_user_by_token()

        if event is None:
            return {"response": "Error", "message": "Evenement  Not Founf"}, 404

        if event.isprivate:
            if user is None or user not in event.inscrits:
                return {"response": "Error", "message": "User  Not autorized"}, 403

        discution: Discution = event.discution

        reponse = {}
        id_message = 0
        message: Message
        for message in discution.message:
            reponse[id_message] = {"author": message.author, "message": message.text,
                                   "date": str(message.date.strftime('%d/%m/%Y %H:%M:%S'))}
            id_message += 1

        return {"response": "SUCCESS",
                "message": "Discution  for Evenement : " + str(id_evenement), "discusion": reponse}