feat: ajout de la gestion des jobs avec création, récupération, suppression et filtrage via l'API, incluant des entités, des composants Vue.js et des mises à jour de la documentation API

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-30 16:14:17 +02:00
parent 4d1d5b9f21
commit fd2d3cd640
21 changed files with 1538 additions and 184 deletions

View File

@@ -0,0 +1,124 @@
import { defineStore } from 'pinia';
import { ApiJobRepository } from '../../infrastructure/api/ApiJobRepository';
const jobRepository = new ApiJobRepository();
export const useActivityStore = defineStore('activity', {
state: () => ({
jobs: [],
loading: false,
error: null,
filter: {
status: ['pending', 'in_progress', 'failed'], // Par défaut, afficher les jobs actifs
sortBy: 'createdAt',
sortOrder: 'DESC'
}
}),
getters: {
activeJobs: state => state.jobs.filter(job => job.isActive()),
completedJobs: state => state.jobs.filter(job => job.isCompleted()),
failedJobs: state => state.jobs.filter(job => job.hasError()),
isLoading: state => state.loading,
hasError: state => !!state.error
},
actions: {
/**
* Charge la liste des jobs selon les filtres actuels
*/
async loadJobs() {
this.loading = true;
this.error = null;
try {
const options = {
page: 1, // Page fixée à 1
limit: 100, // Limite augmentée pour récupérer plus de jobs
sortBy: this.filter.sortBy,
sortOrder: this.filter.sortOrder,
status: this.filter.status
};
const jobCollection = await jobRepository.getJobs(options);
this.jobs = jobCollection.items;
} catch (error) {
this.error = error.message;
console.error('Error loading jobs:', error);
} finally {
this.loading = false;
}
},
/**
* Met à jour les filtres et recharge la liste
* @param {Object} filter
*/
async updateFilter(filter) {
this.filter = { ...this.filter, ...filter };
await this.loadJobs();
},
/**
* Supprime un job par son ID
* @param {string} id
*/
async deleteJob(id) {
this.loading = true;
this.error = null;
try {
await jobRepository.deleteJob(id);
// Supprimer le job de la liste locale
this.jobs = this.jobs.filter(job => job.id !== id);
} catch (error) {
this.error = error.message;
console.error('Error deleting job:', error);
} finally {
this.loading = false;
}
},
/**
* Supprime tous les jobs correspondant aux critères
* @param {Object} criteria
*/
async deleteJobs(criteria = {}) {
this.loading = true;
this.error = null;
try {
const deleted = await jobRepository.deleteJobs(criteria);
// Recharger la liste après suppression
await this.loadJobs();
return deleted;
} catch (error) {
this.error = error.message;
console.error('Error deleting jobs:', error);
} finally {
this.loading = false;
}
},
/**
* Supprime tous les jobs terminés
*/
async deleteCompletedJobs() {
return this.deleteJobs({ status: ['COMPLETED'] });
},
/**
* Supprime tous les jobs en erreur
*/
async deleteFailedJobs() {
return this.deleteJobs({ status: ['ERROR'] });
},
/**
* Supprime tous les jobs
*/
async deleteAllJobs() {
return this.deleteJobs({});
}
}
});