コード例 #1
0
def get_all_interventions():
    try:
        # On crée une connexion à la bdd
        repo = InterventionDbRepository(CONSTANTE.DB_NAME)
        # On execute un getAll
        all_interventions = repo.get_all()
        return jsonify(all_interventions)
    except Exception as exc:
        return str(exc), 400, {}
コード例 #2
0
def get_intervention_by_id(id_intervention):
    try:
        # On crée une connexion à la bdd
        repo = InterventionDbRepository(CONSTANTE.DB_NAME)
        # On execute un getAll
        intervention = repo.get_intervention_by_id(id_intervention)
        return jsonify(intervention)
    except Exception as exc:
        # print("BUG? " + str(exc))
        return str(exc), 400, {}
コード例 #3
0
 def test_save_intervention(self):
     # ARRANGE
     repo = InterventionDbRepository(CONNECTION_STRING)
     uc = InterventionSaveUseCase(repo)
     intervention = Intervention("", "Valentin", "Test")
     # ACT
     response = uc.execute(intervention)
     # ASSERT
     self.assertEqual(response, "True")
コード例 #4
0
 def test_get_all_intervention(self):
     # ARRANGE
     repo = InterventionDbRepository(CONNECTION_STRING)
     uc = InterventionGetAllUseCase(repo)
     # ACT
     response = uc.execute()
     # ASSERT
     self.assertDictEqual(
         response[0], {
             "ref": 1,
             "client": "Geoffrey Soulaques",
             "description": "Problème ordinateur portable"
         })
コード例 #5
0
def post_intervention():
    try:
        # On récupère le json de la requête
        request_content = request.get_json()
        # On le passe dans le validateur
        request_object = InterventionValidatorObject(request_content)
        # On transforme le json en objet Intervention
        intervention = InterventionValidatorObject.get_intervention(
            request_object)
        # On crée une connexion à la bdd
        repo = InterventionDbRepository(CONSTANTE.DB_NAME)
        # On instancie une requête
        uc = InterventionSaveUseCase(repo)
        # On retourne le résultat de l'execution de la requête
        uc.execute(intervention)
        return f"intervention créée: <br/> {intervention.to_dict()}"
    except Exception as exc:
        # print("BUG? " + str(exc))
        return str(exc), 400, {}
コード例 #6
0
def save_intervention():
    repo = InterventionDbRepository(CONNECTION_STRING)
    uc = InterventionSaveUseCase(repo)
    data = request.get_json()
    intervention = InterventionValidator.valid_intervention(data)
    return uc.execute(intervention)
コード例 #7
0
def get_all_interventions():
    repo = InterventionDbRepository(CONNECTION_STRING)
    uc = InterventionGetAllUseCase(repo)
    return jsonify(uc.execute())