44
55use Illuminate \Http \Request ;
66
7+ use Dingo \Api \Exception \StoreResourceFailedException ;
8+
79use Pterodactyl \Transformers \UserTransformer ;
810use Pterodactyl \Models ;
11+ use Pterodactyl \Repositories \UserRepository ;
912
1013/**
1114 * @Resource("Users", uri="/users")
@@ -21,7 +24,7 @@ class UserController extends BaseController
2124 * @Get("/{?page}")
2225 * @Versions({"v1"})
2326 * @Parameters({
24- * @Parameter("page", type="integer", description="The page of results to view.", default=1)
27+ * @Parameter("page", type="integer", description="The page of results to view.", default=1)
2528 * })
2629 * @Response(200)
2730 */
@@ -39,8 +42,8 @@ public function getUsers(Request $request)
3942 * @Get("/{id}/{fields}")
4043 * @Versions({"v1"})
4144 * @Parameters({
42- * @Parameter("id", type="integer", required=true, description="The ID of the user to get information on."),
43- * @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
45+ * @Parameter("id", type="integer", required=true, description="The ID of the user to get information on."),
46+ * @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
4447 * })
4548 * @Response(200)
4649 */
@@ -59,4 +62,82 @@ public function getUserByID(Request $request, $id, $fields = null)
5962 return $ query ->first ();
6063 }
6164
65+ /**
66+ * Create a New User
67+ *
68+ * @Post("/")
69+ * @Versions({"v1"})
70+ * @Transaction({
71+ * @Request({
72+ * "email": "foo@example.com",
73+ * "password": "foopassword",
74+ * "admin": false
75+ * }, headers={"Authorization": "Bearer <jwt-token>"}),
76+ * @Response(200, body={"id": 1}),
77+ * @Response(422, body{
78+ * "message": "A validation error occured.",
79+ * "errors": {
80+ * "email": ["The email field is required."],
81+ * "password": ["The password field is required."],
82+ * "admin": ["The admin field is required."]
83+ * },
84+ * "status_code": 422
85+ * })
86+ * })
87+ */
88+ public function postUsers (Request $ request )
89+ {
90+ try {
91+ $ user = new UserRepository ;
92+ $ create = $ user ->create ($ request ->input ('email ' ), $ request ->input ('password ' ), $ request ->input ('admin ' ));
93+ return [ 'id ' => $ create ];
94+ } catch (\Pterodactyl \Exceptions \DisplayValidationException $ ex ) {
95+ throw new StoreResourceFailedException ('A validation error occured. ' , json_decode ($ ex ->getMessage (), true ));
96+ } catch (\Exception $ ex ) {
97+ throw new StoreResourceFailedException ('Unable to create a user on the system due to an error. ' );
98+ }
99+ }
100+
101+ /**
102+ * Update an Existing User
103+ *
104+ * The data sent in the request will be used to update the existing user on the system.
105+ *
106+ * @Patch("/{id}")
107+ * @Versions({"v1"})
108+ * @Transaction({
109+ * @Request({
110+ * "email": "new@email.com"
111+ * }, headers={"Authorization": "Bearer <jwt-token>"}),
112+ * @Response(200, body={"email": "new@email.com"}),
113+ * @Response(422)
114+ * })
115+ * @Parameters({
116+ * @Parameter("id", type="integer", required=true, description="The ID of the user to modify.")
117+ * })
118+ */
119+ public function patchUser (Request $ request , $ id )
120+ {
121+ //
122+ }
123+
124+ /**
125+ * Delete a User
126+ *
127+ * @Delete("/{id}")
128+ * @Versions({"v1"})
129+ * @Transaction({
130+ * @Request(headers={"Authorization": "Bearer <jwt-token>"}),
131+ * @Response(204),
132+ * @Response(422)
133+ * })
134+ * @Parameters({
135+ * @Parameter("id", type="integer", required=true, description="The ID of the user to delete.")
136+ * })
137+ */
138+ public function deleteUser (Request $ request , $ id )
139+ {
140+ //
141+ }
142+
62143}
0 commit comments