feat(backend): ajout 8 endpoints manquants workflow financier
Endpoints ajoutés :
- POST /api/finance/approvals - requestApproval (avec organizationId)
- GET /api/finance/approvals/history - historique filtrable
- PUT /api/finance/budgets/{id} - updateBudget (name, description, status)
- DELETE /api/finance/budgets/{id} - deleteBudget (soft delete)
- GET /api/finance/stats - statistiques workflow global
- GET /api/finance/audit-logs - logs d'audit filtrables
- GET /api/finance/audit-logs/anomalies - détection anomalies
- POST /api/finance/audit-logs/export - export CSV/PDF
Services :
- ApprovalService.requestApproval() : logique niveaux LEVEL1/2/3 selon montant
- ApprovalService.getApprovalsHistory() : filtres date + statut
- BudgetService.updateBudget() : validation statut + approbation
- BudgetService.deleteBudget() : soft delete (actif=false)
Notes :
- Niveau approbation : <100K=NONE, 100K-1M=LEVEL1, 1M-5M=LEVEL2, >5M=LEVEL3
- organizationId optionnel dans requestApproval (pas de récup auto depuis Membre)
- FinanceWorkflowResource créé pour stats/audit (implémentation stub)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -225,6 +225,60 @@ public class BudgetService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour un budget
|
||||
*/
|
||||
@Transactional
|
||||
public BudgetResponse updateBudget(UUID budgetId, Map<String, Object> updates) {
|
||||
LOG.infof("Mise à jour du budget %s", budgetId);
|
||||
|
||||
Budget budget = budgetRepository.findByIdOptional(budgetId)
|
||||
.orElseThrow(() -> new NotFoundException("Budget non trouvé: " + budgetId));
|
||||
|
||||
// Mise à jour des champs simples
|
||||
if (updates.containsKey("name")) {
|
||||
budget.setName((String) updates.get("name"));
|
||||
}
|
||||
if (updates.containsKey("description")) {
|
||||
budget.setDescription((String) updates.get("description"));
|
||||
}
|
||||
if (updates.containsKey("status")) {
|
||||
String newStatus = (String) updates.get("status");
|
||||
if (!List.of("DRAFT", "ACTIVE", "CLOSED", "ARCHIVED").contains(newStatus)) {
|
||||
throw new BadRequestException("Statut invalide: " + newStatus);
|
||||
}
|
||||
budget.setStatus(newStatus);
|
||||
|
||||
// Si on active le budget, enregistrer la date d'approbation
|
||||
if ("ACTIVE".equals(newStatus) && budget.getApprovedAt() == null) {
|
||||
budget.setApprovedAt(LocalDateTime.now());
|
||||
budget.setApprovedById(UUID.fromString(jwt.getClaim("sub")));
|
||||
}
|
||||
}
|
||||
|
||||
budgetRepository.persist(budget);
|
||||
LOG.infof("Budget %s mis à jour avec succès", budgetId);
|
||||
|
||||
return toResponse(budget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime un budget (soft delete)
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteBudget(UUID budgetId) {
|
||||
LOG.infof("Suppression du budget %s", budgetId);
|
||||
|
||||
Budget budget = budgetRepository.findByIdOptional(budgetId)
|
||||
.orElseThrow(() -> new NotFoundException("Budget non trouvé: " + budgetId));
|
||||
|
||||
// Soft delete: marquer comme inactif
|
||||
budget.setActif(false);
|
||||
budgetRepository.persist(budget);
|
||||
|
||||
LOG.infof("Budget %s supprimé avec succès", budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit une entité Budget en DTO de réponse
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user