File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -10,5 +10,6 @@ Simply pastebin coded for education purposes. It looks like it works.
10
10
11
11
## TODO
12
12
- Avatars
13
+ - REST API endpoint for creating pastes
13
14
14
15
![ Screenshot] ( /screenshot.png?raw=true )
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Controller ;
4
+
5
+ use App \Repository \PasteRepository ;
6
+ use Sensio \Bundle \FrameworkExtraBundle \Configuration \Method ;
7
+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
8
+ use Symfony \Component \HttpFoundation \Request ;
9
+ use Symfony \Component \Routing \Annotation \Route ;
10
+
11
+ /**
12
+ * @Route("/api")
13
+ */
14
+ class RestController extends AbstractController {
15
+
16
+ /**
17
+ * @Route("/read")
18
+ * @Method("GET")
19
+ */
20
+ public function read (Request $ request , PasteRepository $ pasteRepository ) {
21
+ $ name = $ request ->get ('name ' );
22
+ if ($ name == null ) {
23
+ return $ this ->json ([
24
+ 'error ' => 1 ,
25
+ 'message ' => 'Missing name parameter '
26
+ ], 400 );
27
+ }
28
+
29
+ $ paste = $ pasteRepository ->findOneByName ($ name );
30
+ if ($ paste == null ) {
31
+ return $ this ->json ([
32
+ 'error ' => 2 ,
33
+ 'message ' => 'Paste does not exists '
34
+ ]);
35
+ }
36
+
37
+ return $ this ->json ($ paste );
38
+ }
39
+
40
+ /**
41
+ * @Route("/last")
42
+ * @Method("GET")
43
+ */
44
+ public function last (PasteRepository $ pasteRepository ) {
45
+ return $ this ->json ($ pasteRepository ->getSidebar ());
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments