77use VoicesOfWynn \Models \Api \DiscordIntegration \DiscordManager ;
88use VoicesOfWynn \Models \Website \DiscordRole ;
99use VoicesOfWynn \Models \Website \UserException ;
10+ use OpenApi \Attributes as OA ;
1011
12+ #[OA \Tag(name: "Discord Integration " , description: "Endpoints for integrating with the Voices of Wynn Discord server. " )]
1113class DiscordIntegration extends ApiController
1214{
1315 public function process (array $ args ): int
@@ -22,6 +24,21 @@ public function process(array $args): int
2224 }
2325 }
2426
27+ #[OA \Get(
28+ path: "/api/discord-integration " ,
29+ summary: "Get Discord integration data " ,
30+ tags: ["Discord Integration " ],
31+ parameters: [
32+ new OA \Parameter (name: "apiKey " , in: "query " , required: true , schema: new OA \Schema (type: "string " , default: "testing " )),
33+ new OA \Parameter (name: "action " , in: "query " , required: true , schema: new OA \Schema (type: "string " , enum: ["getAllUsers " ]))
34+ ],
35+ responses: [
36+ new OA \Response (response: 200 , description: "Success " , content: new OA \JsonContent (type: "array " , items: new OA \Items (ref: "#/components/schemas/User " ))),
37+ new OA \Response (response: 400 , description: "Bad request - invalid action " ),
38+ new OA \Response (response: 401 , description: "Unauthorized - invalid API key " ),
39+ new OA \Response (response: 500 , description: "Internal server error " , content: new OA \JsonContent (properties: [new OA \Property (property: "error " , type: "string " , description: "Error message " )]))
40+ ]
41+ )]
2542 /**
2643 * @throws UserException
2744 */
@@ -35,13 +52,49 @@ private function get(): int
3552 switch ($ _GET ['action ' ]) {
3653 case 'getAllUsers ' :
3754 $ users = $ manager ->getAllUsers ();
55+ $ decoded = json_decode ($ users , true );
56+
57+ // Check if the response contains an error
58+ if (isset ($ decoded ['error ' ])) {
59+ echo $ users ;
60+ return 500 ;
61+ }
62+
3863 echo $ users ;
3964 return 200 ;
4065 default :
4166 return 400 ;
4267 }
4368 }
4469
70+ #[OA \Post(
71+ path: "/api/discord-integration " ,
72+ summary: "Synchronize a user " ,
73+ tags: ["Discord Integration " ],
74+ requestBody: new OA \RequestBody (
75+ required: true ,
76+ content: new OA \MediaType (
77+ mediaType: "application/x-www-form-urlencoded " ,
78+ schema: new OA \Schema (
79+ required: ["apiKey " , "action " , "discordId " , "discordName " ],
80+ properties: [
81+ new OA \Property (property: "apiKey " , type: "string " , default: "testing " ),
82+ new OA \Property (property: "action " , type: "string " , enum: ["syncUser " ]),
83+ new OA \Property (property: "discordId " , type: "integer " ),
84+ new OA \Property (property: "discordName " , type: "string " ),
85+ new OA \Property (property: "imgurl " , type: "string " ),
86+ new OA \Property (property: "name " , type: "string " ),
87+ new OA \Property (property: "roles " , type: "string " )
88+ ]
89+ )
90+ )
91+ ),
92+ responses: [
93+ new OA \Response (response: 200 , description: "User updated " ),
94+ new OA \Response (response: 201 , description: "User created " ),
95+ new OA \Response (response: 401 , description: "Unauthorized " )
96+ ]
97+ )]
4598 /**
4699 * @throws UserException
47100 */
0 commit comments