From 17fe374e015b5d8ef349dece5c89f3b1ca33a13b Mon Sep 17 00:00:00 2001
From: Akex <a.plokhikh.sas@gmail.com>
Date: Tue, 9 Apr 2024 01:56:24 +0500
Subject: [PATCH] make controller

---
 src/Controller/CountFriday13Controller.php | 28 ++++++++++++++++++++++
 src/Repository/CountFriday13Repository.php | 23 ++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 src/Controller/CountFriday13Controller.php
 create mode 100644 src/Repository/CountFriday13Repository.php

diff --git a/src/Controller/CountFriday13Controller.php b/src/Controller/CountFriday13Controller.php
new file mode 100644
index 0000000..88e200c
--- /dev/null
+++ b/src/Controller/CountFriday13Controller.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\Attribute\Route;
+use function App\Repository\countFriday13;
+
+class CountFriday13Controller extends AbstractController
+{
+    /**
+     * git Контроллер вернет все пятницы 13 в году используя countFriday13 функцию
+     * @param Request $request
+     * @return Response
+     */
+    #[Route('/count/friday13', name: 'app_count_friday13')]
+    public function index(Request $request): Response
+    {
+        $year = $request->toArray()['year'];
+
+        $returnableArray = countFriday13($year);
+
+        return new JsonResponse($returnableArray, Response::HTTP_OK);
+    }
+}
diff --git a/src/Repository/CountFriday13Repository.php b/src/Repository/CountFriday13Repository.php
new file mode 100644
index 0000000..8d3e0d7
--- /dev/null
+++ b/src/Repository/CountFriday13Repository.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Repository;
+use DateTimeImmutable;
+
+/**
+ * Вернет все пятницы 13 в году
+ * @param int $yaer год, в котором необходимо произвести расчет
+ * @return DateTimeImmutable[]
+ */
+function countFriday13(int $year): iterable {
+    $date = new DateTimeImmutable();
+    $AllFri13 = [];
+
+    for ($i = 1; $i<=12; $i++ ){
+        $next13 = $date->setDate($year, $i, 13);
+
+        if ($next13->format("D") === 'Fri'){
+            $AllFri13[] = $next13;
+        }
+    }
+    return $AllFri13;
+}
-- 
GitLab