ScoDoc/app/api/debug.py

50 lines
1.3 KiB
Python
Raw Normal View History

from app.api import bp
from app.api.auth import token_auth, token_permission_required
from app.models import NotesNotes, FormSemestre
from app.scodoc.sco_permissions import Permission
from flask import jsonify
from app import models
from app import db
import time
import random
import datetime
@bp.route("/create_note", methods=["GET"])
@token_auth.login_required
@token_permission_required(Permission.APIView)
def create_note():
note = NotesNotes()
db.session.add(note)
db.session.commit()
return jsonify(note.to_dict())
@bp.route("/change_value_note/<int:note_id>", methods=["GET"])
@token_auth.login_required
@token_permission_required(Permission.APIView)
def change_value_note(note_id: int):
note = NotesNotes.query.get_or_404(note_id)
note.value = 10
db.session.commit()
return jsonify(note.to_dict())
@bp.route(
"/change_date_note/<int:note_id>", methods=["GET"]
) # XXX TODO test avec notes_add() en plus
@token_auth.login_required
@token_permission_required(Permission.APIView)
def change_date_note(note_id: int):
formsemestre = FormSemestre.query.get_or_404(1)
date_debut = formsemestre.date_debut
date_fin = formsemestre.date_fin
note = NotesNotes.query.get_or_404(note_id)
note.date = date_debut + random.random() * (date_fin - date_debut)
db.session.commit()
return jsonify(note.to_dict())