Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
4a3986c6
Verified
Commit
4a3986c6
authored
4 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #16063 TIME 3:15 WIP Tiles update delete and update positions
parent
4d4b1002
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rest/index.php
+3
-0
3 additions, 0 deletions
rest/index.php
src/app/home/controllers/TileController.php
+102
-1
102 additions, 1 deletion
src/app/home/controllers/TileController.php
src/app/home/models/TileModel.php
+1
-1
1 addition, 1 deletion
src/app/home/models/TileModel.php
with
106 additions
and
2 deletions
rest/index.php
+
3
−
0
View file @
4a3986c6
...
@@ -528,6 +528,9 @@ $app->post('/templates/{id}/mergeEmail', \Template\controllers\TemplateControlle
...
@@ -528,6 +528,9 @@ $app->post('/templates/{id}/mergeEmail', \Template\controllers\TemplateControlle
//Tiles
//Tiles
$app
->
get
(
'/tiles'
,
\Home\controllers\TileController
::
class
.
':get'
);
$app
->
get
(
'/tiles'
,
\Home\controllers\TileController
::
class
.
':get'
);
$app
->
post
(
'/tiles'
,
\Home\controllers\TileController
::
class
.
':create'
);
$app
->
post
(
'/tiles'
,
\Home\controllers\TileController
::
class
.
':create'
);
$app
->
put
(
'/tiles/{id}'
,
\Home\controllers\TileController
::
class
.
':update'
);
$app
->
delete
(
'/tiles/{id}'
,
\Home\controllers\TileController
::
class
.
':delete'
);
$app
->
put
(
'/tilesPositions'
,
\Home\controllers\TileController
::
class
.
':updatePositions'
);
//Users
//Users
$app
->
put
(
'/users/export'
,
\User\controllers\UserController
::
class
.
':getExport'
);
$app
->
put
(
'/users/export'
,
\User\controllers\UserController
::
class
.
':getExport'
);
...
...
This diff is collapsed.
Click to expand it.
src/app/home/controllers/TileController.php
+
102
−
1
View file @
4a3986c6
...
@@ -33,6 +33,10 @@ class TileController
...
@@ -33,6 +33,10 @@ class TileController
'data'
=>
[
$GLOBALS
[
'id'
]]
'data'
=>
[
$GLOBALS
[
'id'
]]
]);
]);
foreach
(
$tiles
as
$key
=>
$tile
)
{
$tiles
[
'parameters'
]
=
json_decode
(
$tile
[
'parameters'
],
true
);
}
return
$response
->
withJson
([
'tiles'
=>
$tiles
]);
return
$response
->
withJson
([
'tiles'
=>
$tiles
]);
}
}
...
@@ -69,7 +73,7 @@ class TileController
...
@@ -69,7 +73,7 @@ class TileController
HistoryController
::
add
([
HistoryController
::
add
([
'tableName'
=>
'tiles'
,
'tableName'
=>
'tiles'
,
'recordId'
=>
$
GLOBALS
[
'id'
]
,
'recordId'
=>
$
id
,
'eventType'
=>
'ADD'
,
'eventType'
=>
'ADD'
,
'eventId'
=>
'tileCreation'
,
'eventId'
=>
'tileCreation'
,
'info'
=>
'tile creation'
'info'
=>
'tile creation'
...
@@ -77,4 +81,101 @@ class TileController
...
@@ -77,4 +81,101 @@ class TileController
return
$response
->
withJson
([
'id'
=>
$id
]);
return
$response
->
withJson
([
'id'
=>
$id
]);
}
}
public
function
update
(
Request
$request
,
Response
$response
,
array
$args
)
{
$tile
=
TileModel
::
getById
([
'select'
=>
[
'user_id'
],
'id'
=>
$args
[
'id'
]]);
if
(
empty
(
$tile
)
||
$tile
[
'user_id'
]
!=
$GLOBALS
[
'id'
])
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Tile out of perimeter'
]);
}
$body
=
$request
->
getParsedBody
();
if
(
empty
(
$body
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body is empty'
]);
}
elseif
(
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'type'
]
??
null
)
||
!
in_array
(
$body
[
'type'
],
TileController
::
TYPES
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body type is empty, not a string or not valid'
]);
}
elseif
(
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'view'
]
??
null
)
||
!
in_array
(
$body
[
'view'
],
TileController
::
VIEWS
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body view is empty, not a string or not valid'
]);
}
TileModel
::
update
([
'set'
=>
[
'type'
=>
$body
[
'type'
],
'view'
=>
$body
[
'view'
],
'parameters'
=>
empty
(
$body
[
'parameters'
])
?
'{}'
:
json_encode
(
$body
[
'parameters'
])
],
'where'
=>
[
'id = ?'
],
'data'
=>
[
$args
[
'id'
]]
]);
HistoryController
::
add
([
'tableName'
=>
'tiles'
,
'recordId'
=>
$args
[
'id'
],
'eventType'
=>
'UP'
,
'eventId'
=>
'tileModification'
,
'info'
=>
'tile modification'
]);
return
$response
->
withStatus
(
204
);
}
public
function
delete
(
Request
$request
,
Response
$response
,
array
$args
)
{
$tile
=
TileModel
::
getById
([
'select'
=>
[
'user_id'
],
'id'
=>
$args
[
'id'
]]);
if
(
empty
(
$tile
)
||
$tile
[
'user_id'
]
!=
$GLOBALS
[
'id'
])
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Tile out of perimeter'
]);
}
TileModel
::
delete
([
'where'
=>
[
'id = ?'
],
'data'
=>
[
$args
[
'id'
]]
]);
HistoryController
::
add
([
'tableName'
=>
'tiles'
,
'recordId'
=>
$args
[
'id'
],
'eventType'
=>
'DEL'
,
'eventId'
=>
'tileSuppression'
,
'info'
=>
'tile suppression'
]);
return
$response
->
withStatus
(
204
);
}
public
function
updatePositions
(
Request
$request
,
Response
$response
)
{
$body
=
$request
->
getParsedBody
();
if
(
empty
(
$body
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body is empty'
]);
}
elseif
(
!
Validator
::
arrayType
()
->
notEmpty
()
->
validate
(
$body
[
'tiles'
]
??
null
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body tiles is empty not not an array'
]);
}
$userTiles
=
TileModel
::
get
([
'select'
=>
[
'id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
]]]);
if
(
count
(
$userTiles
)
!=
count
(
$body
[
'tiles'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body tiles do not match user tiles'
]);
}
$allTiles
=
array_column
(
$userTiles
,
'id'
);
foreach
(
$body
[
'tiles'
]
as
$tile
)
{
if
(
!
in_array
(
$tile
[
'id'
],
$allTiles
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Tiles out of perimeter'
]);
}
}
foreach
(
$body
[
'tiles'
]
as
$key
=>
$tile
)
{
if
(
$key
!=
$tile
[
'position'
])
{
TileModel
::
update
([
'set'
=>
[
'position'
=>
$key
,
],
'where'
=>
[
'id = ?'
],
'data'
=>
[
$tile
[
'id'
]]
]);
}
}
return
$response
->
withStatus
(
204
);
}
}
}
This diff is collapsed.
Click to expand it.
src/app/home/models/TileModel.php
+
1
−
1
View file @
4a3986c6
...
@@ -59,7 +59,7 @@ class TileModel
...
@@ -59,7 +59,7 @@ class TileModel
public
static
function
create
(
array
$args
)
public
static
function
create
(
array
$args
)
{
{
ValidatorModel
::
notEmpty
(
$args
,
[
'user_id'
,
'type'
,
'view'
,
'position'
]);
ValidatorModel
::
notEmpty
(
$args
,
[
'user_id'
,
'type'
,
'view'
]);
ValidatorModel
::
stringType
(
$args
,
[
'type'
,
'view'
,
'parameters'
]);
ValidatorModel
::
stringType
(
$args
,
[
'type'
,
'view'
,
'parameters'
]);
ValidatorModel
::
intVal
(
$args
,
[
'user_id'
,
'position'
]);
ValidatorModel
::
intVal
(
$args
,
[
'user_id'
,
'position'
]);
...
...
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