1
+ <?php
2
+ namespace OCA \NextMagentaCloud \User \Service ;
3
+
4
+ use Exception ;
5
+
6
+ use OCP \Accounts \IAccountManager ;
7
+ use OCP \Accounts \IAccount ;
8
+
9
+ class NmcUserService {
10
+
11
+ private $ acountManager ;
12
+
13
+ public function __construct (NoteMapper $ mapper ){
14
+ $ this ->mapper = $ mapper ;
15
+ }
16
+
17
+ public function findAll (string $ userId ) {
18
+ return $ this ->mapper ->findAll ($ userId );
19
+ }
20
+
21
+
22
+ public function find (int $ id , string $ userId ) {
23
+ try {
24
+ $ acc = $ this ->accountMgr ->getAccount ($ userId );
25
+
26
+ // in order to be able to plug in different storage backends like files
27
+ // for instance it is a good idea to turn storage related exceptions
28
+ // into service related exceptions so controllers and service users
29
+ // have to deal with only one type of exception
30
+ } catch (Exception $ e ) {
31
+ $ this ->handleException ($ e );
32
+ }
33
+ }
34
+
35
+ public function create (string $ title , string $ content , string $ userId ) {
36
+ $ note = new Note ();
37
+ $ note ->setTitle ($ title );
38
+ $ note ->setContent ($ content );
39
+ $ note ->setUserId ($ userId );
40
+ return $ this ->mapper ->insert ($ note );
41
+ }
42
+
43
+ public function update (int $ id , string $ title , string $ content , string $ userId ) {
44
+ try {
45
+ $ note = $ this ->mapper ->find ($ id , $ userId );
46
+ $ note ->setTitle ($ title );
47
+ $ note ->setContent ($ content );
48
+ return $ this ->mapper ->update ($ note );
49
+ } catch (Exception $ e ) {
50
+ $ this ->handleException ($ e );
51
+ }
52
+ }
53
+
54
+ public function delete (int $ id , string $ userId ) {
55
+ try {
56
+ $ note = $ this ->mapper ->find ($ id , $ userId );
57
+ $ this ->mapper ->delete ($ note );
58
+ return $ note ;
59
+ } catch (Exception $ e ) {
60
+ $ this ->handleException ($ e );
61
+ }
62
+ }
63
+
64
+ }
0 commit comments