aa
This commit is contained in:
@@ -46,6 +46,10 @@ class ArticleController extends Controller
|
||||
// ->take(50)
|
||||
->get();
|
||||
|
||||
if ($articoliVenduti->isEmpty()) {
|
||||
return response()->json(['message' => 'Nessun articolo trovato.'], 404);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Registrazione dell'errore
|
||||
return response()->json(['error' => 'Si è verificato un errore durante il recupero dei dati: ' . $e->getMessage()], 500);
|
||||
@@ -97,38 +101,38 @@ class ArticleController extends Controller
|
||||
}
|
||||
|
||||
public function exportArticlesSalesByJSON(Request $request): Response
|
||||
{
|
||||
try {
|
||||
// Recupera gli articoli venduti
|
||||
$articoliVenduti = $this->queryArticlesSales();
|
||||
{
|
||||
try {
|
||||
// Recupera gli articoli venduti
|
||||
$articoliVenduti = $this->queryArticlesSales();
|
||||
|
||||
// Mappa i risultati nella struttura JSON desiderata
|
||||
$result = $articoliVenduti->map(function ($articoloVenduto) {
|
||||
return [
|
||||
'id' => $articoloVenduto->idArticolo,
|
||||
'title' => $articoloVenduto->Titolo,
|
||||
'DataPubblicazione' => $articoloVenduto->DataPubblicazione,
|
||||
'totaleVenduti' => $articoloVenduto->totaleVenduto,
|
||||
'rank3M' => $articoloVenduto->rank3M,
|
||||
'rank6M' => $articoloVenduto->rank6M,
|
||||
'rank1Y' => $articoloVenduto->rank1Y,
|
||||
'venditeLastM' => $articoloVenduto->totaleVendutoUltimoMese,
|
||||
'venditeLast6M' => $articoloVenduto->totaleVendutoUltimi6Mesi,
|
||||
'venditeLastY' => $articoloVenduto->totaleVendutoUltimoAnno,
|
||||
'venditeLast2Y' => $articoloVenduto->totaleVendutoUltimi2Anni,
|
||||
'dataUltimoOrdine' => $articoloVenduto->ultimoOrdine,
|
||||
];
|
||||
});
|
||||
// Mappa i risultati nella struttura JSON desiderata
|
||||
$result = $articoliVenduti->map(function ($articoloVenduto) {
|
||||
return [
|
||||
'id' => $articoloVenduto->idArticolo,
|
||||
'title' => $articoloVenduto->Titolo,
|
||||
'DataPubblicazione' => $articoloVenduto->DataPubblicazione,
|
||||
'totaleVenduti' => $articoloVenduto->totaleVenduto,
|
||||
'rank3M' => $articoloVenduto->rank3M,
|
||||
'rank6M' => $articoloVenduto->rank6M,
|
||||
'rank1Y' => $articoloVenduto->rank1Y,
|
||||
'venditeLastM' => $articoloVenduto->totaleVendutoUltimoMese,
|
||||
'venditeLast6M' => $articoloVenduto->totaleVendutoUltimi6Mesi,
|
||||
'venditeLastY' => $articoloVenduto->totaleVendutoUltimoAnno,
|
||||
'venditeLast2Y' => $articoloVenduto->totaleVendutoUltimi2Anni,
|
||||
'dataUltimoOrdine' => $articoloVenduto->ultimoOrdine,
|
||||
];
|
||||
});
|
||||
|
||||
// Imposta il contenuto della risposta come JSON
|
||||
$response = new Response($result->toJson(), 200);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="articoli_venduti_' . date('Y-m-d') . '.json"');
|
||||
// Imposta il contenuto della risposta come JSON
|
||||
$response = new Response($result->toJson(), 200);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="articoli_venduti_' . date('Y-m-d') . '.json"');
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
||||
} catch (\Exception $e) {
|
||||
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user