Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iqdevTranningProj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Александр Плохих
iqdevTranningProj
Commits
48b0e95d
Commit
48b0e95d
authored
1 year ago
by
Александр Плохих
Browse files
Options
Downloads
Patches
Plain Diff
add diff days action | controller | req
parent
19237b0d
No related branches found
No related tags found
1 merge request
!7
make controller
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Actions/DiffDaysAction.php
+21
-0
21 additions, 0 deletions
src/Actions/DiffDaysAction.php
src/Controller/DiffDaysController.php
+7
-7
7 additions, 7 deletions
src/Controller/DiffDaysController.php
src/Requests/DiffDaysRequest.php
+29
-0
29 additions, 0 deletions
src/Requests/DiffDaysRequest.php
with
57 additions
and
7 deletions
src/Actions/DiffDaysAction.php
0 → 100644
+
21
−
0
View file @
48b0e95d
<?php
namespace
App\Actions
;
use
DateTimeImmutable
;
class
DiffDaysAction
{
/**
* Вернет кол-во дней между датами
* @param DateTimeImmutable $dateStart дата начала
* @param DateTimeImmutable $dateEnd дата окончания
* @return int
* */
public
function
act
(
DateTimeImmutable
$dateStart
,
DateTimeImmutable
$dateEnd
):
int
{
return
(
int
)
$dateStart
->
diff
(
$dateEnd
)
->
format
(
'%a'
);
}
}
This diff is collapsed.
Click to expand it.
src/Controller/DiffDaysController.php
+
7
−
7
View file @
48b0e95d
...
...
@@ -2,6 +2,8 @@
namespace
App\Controller
;
use
App\Actions\DiffDaysAction
;
use
App\Requests\DiffDaysRequest
;
use
DateTimeImmutable
;
use
HttpResponse
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
...
...
@@ -14,16 +16,14 @@ class DiffDaysController extends AbstractController
{
/**
* Контроллер вернет кол-во дней между датами
* @param Request $request
* @param DiffDaysRequest $request
* @param DiffDaysAction $action
* @return Response
*/
#[Route('/diff/days', name: 'app_diff_days', methods: ['POST'])]
public
function
index
(
Request
$request
):
Response
public
function
index
(
DiffDays
Request
$request
,
DiffDaysAction
$action
):
Response
{
$dateStart
=
new
DateTimeImmutable
(
$request
->
toArray
()[
'date_start'
]);
$dateEnd
=
new
DateTimeImmutable
(
$request
->
toArray
()[
'date_end'
]);
return
new
JsonResponse
([
"interval"
=>
(
$dateStart
->
diff
(
$dateEnd
)
->
format
(
"%a"
))]
,
Response
::
HTTP_OK
);
$array
=
$request
->
serialise
();
return
new
JsonResponse
(
$action
->
act
(
$array
[
0
],
$array
[
1
]));
}
}
This diff is collapsed.
Click to expand it.
src/Requests/DiffDaysRequest.php
0 → 100644
+
29
−
0
View file @
48b0e95d
<?php
namespace
App\Requests
;
use
DateTimeImmutable
;
use
Symfony\Component\Validator\Constraints\Date
;
use
Symfony\Component\Validator\Constraints\NotBlank
;
class
DiffDaysRequest
extends
BaseRequest
{
#[Date]
#[NotBlank]
public
$startDate
;
#[Date]
#[NotBlank]
public
$endDate
;
/**
* @return mixed
*/
public
function
serialise
():
mixed
{
return
[
'startDate'
=>
new
DateTimeImmutable
(
$this
->
startDate
),
'endDate'
=>
new
DateTimeImmutable
(
$this
->
endDate
),
];
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment