1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Awin\ReportTask\Bundle\ReportBundle\Controller\v1; |
4
|
|
|
|
5
|
|
|
use Awin\ReportTask\Bundle\ReportBundle\Model\Merchant; |
6
|
|
|
use Awin\ReportTask\Bundle\ReportBundle\Model\TransactionCsvStorage; |
7
|
|
|
use Awin\ReportTask\Bundle\ReportBundle\Model\TransactionTable; |
8
|
|
|
use Awin\ReportTask\Bundle\ReportBundle\Service\Observer\ReportObserver; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
11
|
|
|
use FOS\RestBundle\Controller\FOSRestController; |
12
|
|
|
use FOS\RestBundle\Controller\Annotations as Rest; |
13
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
14
|
|
|
|
15
|
|
|
class ReportController extends FOSRestController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @ApiDoc( |
19
|
|
|
* resource=false, |
20
|
|
|
* description="The endpoint to generate merchant report", |
21
|
|
|
* headers={ |
22
|
|
|
* { |
23
|
|
|
* "name"="Access-Token", |
24
|
|
|
* "description"="Domain ID or token" |
25
|
|
|
* } |
26
|
|
|
* }, |
27
|
|
|
* statusCodes={ |
28
|
|
|
* 200="Returned when report is generated successful", |
29
|
|
|
* 403="Returned when request is not authorised", |
30
|
|
|
* 500={ |
31
|
|
|
* "Returned when the report generation fails", |
32
|
|
|
* "Returned when input param lead to the validation failure" |
33
|
|
|
* } |
34
|
|
|
* }, |
35
|
|
|
* parameters={ |
36
|
|
|
* {"name"="merchant_id", "dataType"="int", "required"=false, "description"="the merchant_id for generate report"}, |
37
|
|
|
* {"name"="date", "dataType"="string", "required"=false, "description"="the date for generate report"} |
38
|
|
|
* } |
39
|
|
|
* ) |
40
|
|
|
* |
41
|
|
|
* @return JsonResponse |
42
|
|
|
*/ |
43
|
|
|
public function generateReport(Request $request) |
44
|
|
|
{ |
45
|
|
|
$merchantId = $request->get('merchant_id'); |
46
|
|
|
$date = $request->get('date'); |
47
|
|
|
|
48
|
|
|
$reportService = $this->container->get('app.report_service'); |
49
|
|
|
$reportService->attach(new ReportObserver()); |
50
|
|
|
$currencyService = $this->container->get('app.currency_service'); |
51
|
|
|
$merchantTransactionService = $this->container->get('app.merchant_transaction_service'); |
52
|
|
|
$merchantTransactionService->setTransactionRepository(new TransactionTable('var/storage/data.csv')); |
53
|
|
|
$merchantTransactionService->setMerchantRepository(new Merchant()); |
54
|
|
|
$storage = new TransactionCsvStorage('var/storage/data.csv'); |
55
|
|
|
|
56
|
|
|
$reportService->generate($merchantTransactionService, $currencyService, $storage, $merchantId, $date); |
57
|
|
|
|
58
|
|
|
$response = new JsonResponse([ |
59
|
|
|
'success' => true, |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
return $response; |
63
|
|
|
} |
64
|
|
|
} |