Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
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
Container registry
Model registry
Operate
Environments
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
betskills
backend
Commits
af056ee8
Commit
af056ee8
authored
8 years ago
by
Jeremy Guiselin
Browse files
Options
Downloads
Patches
Plain Diff
read notifications
parent
072c1b5c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ApiBundle/Controller/DefaultController.php
+17
-4
17 additions, 4 deletions
src/ApiBundle/Controller/DefaultController.php
src/BackendBundle/Repository/NotificationOnDeviceRepository.php
+11
-16
11 additions, 16 deletions
...ckendBundle/Repository/NotificationOnDeviceRepository.php
with
28 additions
and
20 deletions
src/ApiBundle/Controller/DefaultController.php
+
17
−
4
View file @
af056ee8
...
@@ -157,6 +157,12 @@ class DefaultController extends FOSRestController
...
@@ -157,6 +157,12 @@ class DefaultController extends FOSRestController
return
$this
->
handleView
(
$view
);
return
$this
->
handleView
(
$view
);
}
}
/**
* @param Request $request
* @return Response
*
* @Post("/save-purchase")
*/
public
function
savePurchaseAction
(
Request
$request
)
public
function
savePurchaseAction
(
Request
$request
)
{
{
$view
=
View
::
create
();
$view
=
View
::
create
();
...
@@ -207,23 +213,30 @@ class DefaultController extends FOSRestController
...
@@ -207,23 +213,30 @@ class DefaultController extends FOSRestController
/**
/**
* @param string $uuid
* @param string $uuid
*
*
@return Response
*
*
* GET Route annotation.
* GET Route annotation.
* @Get("/notifications/{uuid}/read")
* @Get("/notifications/{uuid}/read")
*/
*/
public
function
readAllNotificationsAction
(
string
$uuid
)
public
function
readAllNotificationsAction
(
string
$uuid
)
{
{
$view
=
View
::
create
();
$device
=
$this
->
getDeviceRepository
()
->
findOneBy
([
'uuid'
=>
$uuid
]);
$device
=
$this
->
getDeviceRepository
()
->
findOneBy
([
'uuid'
=>
$uuid
]);
if
(
$device
)
{
if
(
$device
)
{
try
{
try
{
$this
->
getNotificationOnDeviceRepository
()
->
readAllNotifications
(
$device
);
$this
->
getNotificationOnDeviceRepository
()
->
readAllNotifications
(
$device
);
return
$this
->
handleView
(
$view
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
$view
->
setStatusCode
(
400
);
$this
->
getLogger
()
->
err
(
$e
->
getMessage
());
return
$this
->
handleView
(
$view
);
}
}
}
else
{
}
}
$view
->
setStatusCode
(
400
);
$this
->
getLogger
()
->
err
(
'No device for this uuid'
);
return
$this
->
handleView
(
$view
);
}
}
private
function
getNotificationOnDeviceRepository
()
private
function
getNotificationOnDeviceRepository
()
...
...
This diff is collapsed.
Click to expand it.
src/BackendBundle/Repository/NotificationOnDeviceRepository.php
+
11
−
16
View file @
af056ee8
...
@@ -16,10 +16,7 @@ use Doctrine\ORM\EntityRepository;
...
@@ -16,10 +16,7 @@ use Doctrine\ORM\EntityRepository;
class
NotificationOnDeviceRepository
extends
EntityRepository
class
NotificationOnDeviceRepository
extends
EntityRepository
{
{
public
function
findNotificationsByDevice
(
public
function
findNotificationsByDevice
(
array
$notifications
,
Device
$device
)
array
$notifications
,
Device
$device
)
{
{
return
$this
->
createQueryBuilder
(
's'
)
return
$this
->
createQueryBuilder
(
's'
)
->
where
(
's.notification IN (:notifications)'
)
->
where
(
's.notification IN (:notifications)'
)
...
@@ -32,10 +29,7 @@ class NotificationOnDeviceRepository extends EntityRepository
...
@@ -32,10 +29,7 @@ class NotificationOnDeviceRepository extends EntityRepository
->
getResult
();
->
getResult
();
}
}
public
function
updateStatusOnAllDevices
(
public
function
updateStatusOnAllDevices
(
array
$devices
,
Notification
$notification
)
array
$devices
,
Notification
$notification
)
{
{
foreach
(
$devices
as
$device
)
{
foreach
(
$devices
as
$device
)
{
$notifOnDevice
=
new
NotificationOnDevice
();
$notifOnDevice
=
new
NotificationOnDevice
();
...
@@ -49,13 +43,14 @@ class NotificationOnDeviceRepository extends EntityRepository
...
@@ -49,13 +43,14 @@ class NotificationOnDeviceRepository extends EntityRepository
public
function
readAllNotifications
(
Device
$device
)
public
function
readAllNotifications
(
Device
$device
)
{
{
$qb
=
$this
->
createQueryBuilder
(
'n'
);
$notifications
=
$this
->
findBy
([
$qb
'device'
=>
$device
->
update
(
'n'
)
]);
->
set
(
'n.status'
,
NotificationOnDevice
::
STATUS_READ
)
->
where
(
'n.device = :device'
)
foreach
(
$notifications
as
$notification
)
{
->
setParameter
(
'device'
,
$device
);
$notification
->
setStatus
(
NotificationOnDevice
::
STATUS_READ
);
}
$qb
->
getQuery
()
->
execute
();
$this
->
getEntityManager
()
->
flush
();
}
}
}
}
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