File tree Expand file tree Collapse file tree 12 files changed +87
-43
lines changed
User/src/Handler/User/Role Expand file tree Collapse file tree 12 files changed +87
-43
lines changed Original file line number Diff line number Diff line change 55namespace Api \Admin \Handler \Admin ;
66
77use Api \App \Handler \AbstractHandler ;
8- use Core \Admin \Entity \Admin ;
98use Core \Admin \Service \AdminServiceInterface ;
109use Core \App \Exception \NotFoundException ;
11- use Core \App \Message ;
1210use Dot \DependencyInjection \Attribute \Inject ;
1311use Psr \Http \Message \ResponseInterface ;
1412use Psr \Http \Message \ServerRequestInterface ;
@@ -28,12 +26,9 @@ public function __construct(
2826 */
2927 public function handle (ServerRequestInterface $ request ): ResponseInterface
3028 {
31- $ admin = $ this ->adminService ->getAdminRepository ()->find ($ request ->getAttribute ('uuid ' ));
32- if (! $ admin instanceof Admin) {
33- throw new NotFoundException (Message::ADMIN_NOT_FOUND );
34- }
35-
36- $ this ->adminService ->getAdminRepository ()->deleteAdmin ($ admin );
29+ $ this ->adminService ->getAdminRepository ()->deleteAdmin (
30+ $ this ->adminService ->find ($ request ->getAttribute ('uuid ' ))
31+ );
3732
3833 return $ this ->noContentResponse ();
3934 }
Original file line number Diff line number Diff line change 55namespace Api \Admin \Handler \Admin ;
66
77use Api \App \Handler \AbstractHandler ;
8- use Core \Admin \Entity \Admin ;
98use Core \Admin \Service \AdminServiceInterface ;
109use Core \App \Exception \NotFoundException ;
11- use Core \App \Message ;
1210use Dot \DependencyInjection \Attribute \Inject ;
1311use Psr \Http \Message \ResponseInterface ;
1412use Psr \Http \Message \ServerRequestInterface ;
@@ -28,11 +26,9 @@ public function __construct(
2826 */
2927 public function handle (ServerRequestInterface $ request ): ResponseInterface
3028 {
31- $ admin = $ this ->adminService ->getAdminRepository ()->find ($ request ->getAttribute ('uuid ' ));
32- if (! $ admin instanceof Admin) {
33- throw new NotFoundException (Message::ADMIN_NOT_FOUND );
34- }
35-
36- return $ this ->createResponse ($ request , $ admin );
29+ return $ this ->createResponse (
30+ $ request ,
31+ $ this ->adminService ->find ($ request ->getAttribute ('uuid ' ))
32+ );
3733 }
3834}
Original file line number Diff line number Diff line change 66
77use Api \Admin \InputFilter \UpdateAdminInputFilter ;
88use Api \App \Handler \AbstractHandler ;
9- use Core \Admin \Entity \Admin ;
109use Core \Admin \Service \AdminServiceInterface ;
1110use Core \App \Exception \BadRequestException ;
1211use Core \App \Exception \ConflictException ;
1312use Core \App \Exception \NotFoundException ;
14- use Core \App \Message ;
1513use Dot \DependencyInjection \Attribute \Inject ;
1614use Psr \Http \Message \ResponseInterface ;
1715use Psr \Http \Message \ServerRequestInterface ;
@@ -40,10 +38,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4038 throw (new BadRequestException ())->setMessages ($ this ->inputFilter ->getMessages ());
4139 }
4240
43- $ admin = $ this ->adminService ->getAdminRepository ()->find ($ request ->getAttribute ('uuid ' ));
44- if (! $ admin instanceof Admin) {
45- throw new NotFoundException (Message::ADMIN_NOT_FOUND );
46- }
41+ $ admin = $ this ->adminService ->find ($ request ->getAttribute ('uuid ' ));
4742
4843 $ this ->adminService ->updateAdmin ($ admin , (array ) $ this ->inputFilter ->getValues ());
4944
Original file line number Diff line number Diff line change 55namespace Api \Admin \Handler \Admin \Role ;
66
77use Api \App \Handler \AbstractHandler ;
8- use Core \Admin \Entity \AdminRole ;
98use Core \Admin \Service \AdminRoleServiceInterface ;
109use Core \App \Exception \NotFoundException ;
11- use Core \App \Message ;
1210use Dot \DependencyInjection \Attribute \Inject ;
1311use Psr \Http \Message \ResponseInterface ;
1412use Psr \Http \Message \ServerRequestInterface ;
@@ -28,11 +26,9 @@ public function __construct(
2826 */
2927 public function handle (ServerRequestInterface $ request ): ResponseInterface
3028 {
31- $ adminRole = $ this ->adminRoleService ->getAdminRoleRepository ()->find ($ request ->getAttribute ('uuid ' ));
32- if (! $ adminRole instanceof AdminRole) {
33- throw new NotFoundException (Message::ROLE_NOT_FOUND );
34- }
35-
36- return $ this ->createResponse ($ request , $ adminRole );
29+ return $ this ->createResponse (
30+ $ request ,
31+ $ this ->adminRoleService ->find ($ request ->getAttribute ('uuid ' ))
32+ );
3733 }
3834}
Original file line number Diff line number Diff line change 44
55namespace Core \Admin \Service ;
66
7+ use Core \Admin \Entity \AdminRole ;
78use Core \Admin \Repository \AdminRoleRepository ;
9+ use Core \App \Exception \NotFoundException ;
10+ use Core \App \Message ;
811use Dot \DependencyInjection \Attribute \Inject ;
912
1013class AdminRoleService implements AdminRoleServiceInterface
@@ -21,4 +24,17 @@ public function getAdminRoleRepository(): AdminRoleRepository
2124 {
2225 return $ this ->adminRoleRepository ;
2326 }
27+
28+ /**
29+ * @throws NotFoundException
30+ */
31+ public function find (string $ id ): AdminRole
32+ {
33+ $ adminRole = $ this ->adminRoleRepository ->find ($ id );
34+ if (! $ adminRole instanceof AdminRole) {
35+ throw new NotFoundException (Message::ROLE_NOT_FOUND );
36+ }
37+
38+ return $ adminRole ;
39+ }
2440}
Original file line number Diff line number Diff line change 44
55namespace Core \Admin \Service ;
66
7+ use Core \Admin \Entity \AdminRole ;
78use Core \Admin \Repository \AdminRoleRepository ;
9+ use Core \App \Exception \NotFoundException ;
810
911interface AdminRoleServiceInterface
1012{
1113 public function getAdminRoleRepository (): AdminRoleRepository ;
14+
15+ /**
16+ * @throws NotFoundException
17+ */
18+ public function find (string $ id ): AdminRole ;
1219}
Original file line number Diff line number Diff line change @@ -64,6 +64,19 @@ public function deleteAdmin(Admin $admin): void
6464 $ this ->adminRepository ->deleteAdmin ($ admin );
6565 }
6666
67+ /**
68+ * @throws NotFoundException
69+ */
70+ public function find (string $ id ): Admin
71+ {
72+ $ admin = $ this ->adminRepository ->find ($ id );
73+ if (! $ admin instanceof Admin) {
74+ throw new NotFoundException (Message::ADMIN_NOT_FOUND );
75+ }
76+
77+ return $ admin ;
78+ }
79+
6780 /**
6881 * @throws BadRequestException
6982 * @throws ConflictException
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ public function createAdmin(array $data = []): Admin;
2222
2323 public function deleteAdmin (Admin $ admin ): void ;
2424
25+ /**
26+ * @throws NotFoundException
27+ */
28+ public function find (string $ id ): Admin ;
29+
2530 /**
2631 * @throws BadRequestException
2732 * @throws ConflictException
Original file line number Diff line number Diff line change 44
55namespace Core \User \Service ;
66
7+ use Core \App \Exception \NotFoundException ;
8+ use Core \App \Message ;
9+ use Core \User \Entity \UserRole ;
710use Core \User \Repository \UserRoleRepository ;
811use Dot \DependencyInjection \Attribute \Inject ;
912
@@ -13,12 +16,25 @@ class UserRoleService implements UserRoleServiceInterface
1316 UserRoleRepository::class,
1417 )]
1518 public function __construct (
16- protected UserRoleRepository $ roleRepository ,
19+ protected UserRoleRepository $ userRoleRepository ,
1720 ) {
1821 }
1922
20- public function getRoleRepository (): UserRoleRepository
23+ public function getUserRoleRepository (): UserRoleRepository
2124 {
22- return $ this ->roleRepository ;
25+ return $ this ->userRoleRepository ;
26+ }
27+
28+ /**
29+ * @throws NotFoundException
30+ */
31+ public function find (string $ id ): UserRole
32+ {
33+ $ userRole = $ this ->userRoleRepository ->find ($ id );
34+ if (! $ userRole instanceof UserRole) {
35+ throw new NotFoundException (Message::ROLE_NOT_FOUND );
36+ }
37+
38+ return $ userRole ;
2339 }
2440}
Original file line number Diff line number Diff line change 44
55namespace Core \User \Service ;
66
7+ use Core \App \Exception \NotFoundException ;
8+ use Core \User \Entity \UserRole ;
79use Core \User \Repository \UserRoleRepository ;
810
911interface UserRoleServiceInterface
1012{
11- public function getRoleRepository (): UserRoleRepository ;
13+ public function getUserRoleRepository (): UserRoleRepository ;
14+
15+ /**
16+ * @throws NotFoundException
17+ */
18+ public function find (string $ id ): UserRole ;
1219}
You can’t perform that action at this time.
0 commit comments