11const express = require ( 'express' ) ;
22const userController = require ( '../controllers/userController' ) ;
3- const authenticateToken = require ( '../middleware/auth' ) ;
4- const authorize = require ( '../middleware/authorize' ) ;
3+ const auth = require ( '../middleware/auth' ) ;
54const multer = require ( 'multer' ) ;
65const upload = multer ( { dest : 'uploads/' } ) ;
76
87const router = express . Router ( ) ;
98
109/**
11- * @swagger
10+ * @openapi
11+ * components:
12+ * securitySchemes:
13+ * bearerAuth:
14+ * type: http
15+ * scheme: bearer
16+ * bearerFormat: JWT
17+ * schemas:
18+ * User:
19+ * type: object
20+ * properties:
21+ * name:
22+ * type: string
23+ * email:
24+ * type: string
25+ * password:
26+ * type: string
27+ * profile_picture:
28+ * type: string
29+ * format: binary
30+ *
1231 * /users:
1332 * get:
14- * summary: Retrieve all users
15- * description: Returns a list of all users
33+ * tags:
34+ * - Users
35+ * summary: Get all users
1636 * security:
1737 * - bearerAuth: []
1838 * responses:
1939 * 200:
20- * description: A list of users
21- * content:
22- * application/json:
23- * schema:
24- * type: array
25- * items:
26- * type: object
27- * properties:
28- * id:
29- * type: integer
30- * name:
31- * type: string
32- * email:
33- * type: string
40+ * description: List of users retrieved successfully
3441 * 401:
35- * description: Unauthorized access
36- * 500:
37- * description: Server error
38- */
39- router . get ( '/' , authenticateToken , userController . getUsers ) ;
40-
41- /**
42- * @swagger
43- * /users/{id}:
44- * get:
45- * summary: Retrieve a user by ID
46- * description: Returns a single user identified by their ID
47- * parameters:
48- * - name: id
49- * in: path
50- * required: true
51- * description: The ID of the user to retrieve
52- * schema:
53- * type: integer
54- * security:
55- * - bearerAuth: []
56- * responses:
57- * 200:
58- * description: User details
59- * content:
60- * application/json:
61- * schema:
62- * type: object
63- * properties:
64- * id:
65- * type: integer
66- * name:
67- * type: string
68- * email:
69- * type: string
70- * 401:
71- * description: Unauthorized access
72- * 404:
73- * description: User not found
74- * 500:
75- * description: Server error
76- */
77- router . get ( '/:id' , authenticateToken , userController . getUserById ) ;
78-
79- /**
80- * @swagger
81- * /users:
42+ * description: Unauthorized - invalid token
43+ *
8244 * post:
45+ * tags:
46+ * - Users
8347 * summary: Create a new user
84- * description: Creates a new user in the system
48+ * security:
49+ * - bearerAuth: []
8550 * requestBody:
8651 * required: true
8752 * content:
88- * application/json :
53+ * multipart/form-data :
8954 * schema:
9055 * type: object
9156 * properties:
@@ -95,44 +60,46 @@ router.get('/:id', authenticateToken, userController.getUserById);
9560 * type: string
9661 * password:
9762 * type: string
98- * required:
99- * - name
100- * - email
101- * - password
102- * security:
103- * - bearerAuth: []
63+ * picture:
64+ * type: string
65+ * format: binary
10466 * responses:
10567 * 201:
10668 * description: User created successfully
107- * content:
108- * application/json:
109- * schema:
110- * type: object
111- * properties:
112- * message:
113- * type: string
114- * userId:
115- * type: integer
116- * 400:
117- * description: Validation error
11869 * 401:
119- * description: Unauthorized access
120- * 500:
121- * description: Server error
122- */
123- router . post ( '/' , authenticateToken , upload . single ( 'picture' ) , userController . createUser ) ;
124-
125- /**
126- * @swagger
70+ * description: Unauthorized - invalid token
71+ *
12772 * /users/{id}:
73+ * get:
74+ * tags:
75+ * - Users
76+ * summary: Get user by ID
77+ * security:
78+ * - bearerAuth: []
79+ * parameters:
80+ * - in: path
81+ * name: id
82+ * required: true
83+ * schema:
84+ * type: integer
85+ * responses:
86+ * 200:
87+ * description: User found successfully
88+ * 401:
89+ * description: Unauthorized - invalid token
90+ * 404:
91+ * description: User not found
92+ *
12893 * put:
129- * summary: Update an existing user
130- * description: Updates the details of an existing user by ID
94+ * tags:
95+ * - Users
96+ * summary: Update user
97+ * security:
98+ * - bearerAuth: []
13199 * parameters:
132- * - name: id
133- * in: path
100+ * - in: path
101+ * name: id
134102 * required: true
135- * description: The ID of the user to update
136103 * schema:
137104 * type: integer
138105 * requestBody:
@@ -146,52 +113,41 @@ router.post('/', authenticateToken, upload.single('picture'), userController.cre
146113 * type: string
147114 * email:
148115 * type: string
149- * required:
150- * - name
151- * - email
152- * security:
153- * - bearerAuth: []
116+ * password:
117+ * type: string
154118 * responses:
155119 * 200:
156120 * description: User updated successfully
157- * 400:
158- * description: Bad request, validation error
159121 * 401:
160- * description: Unauthorized access
122+ * description: Unauthorized - invalid token
161123 * 404:
162124 * description: User not found
163- * 500:
164- * description: Server error
165- */
166- router . put ( '/:id' , authenticateToken , userController . updateUser ) ;
167-
168- /**
169- * @swagger
170- * /users/{id}:
125+ *
171126 * delete:
172- * summary: Delete a user by ID
173- * description: Deletes a user from the system by their ID
127+ * tags:
128+ * - Users
129+ * summary: Delete user
130+ * security:
131+ * - bearerAuth: []
174132 * parameters:
175- * - name: id
176- * in: path
133+ * - in: path
134+ * name: id
177135 * required: true
178- * description: The ID of the user to delete
179136 * schema:
180137 * type: integer
181- * security:
182- * - bearerAuth: []
183138 * responses:
184139 * 200:
185140 * description: User deleted successfully
186141 * 401:
187- * description: Unauthorized access
188- * 403:
189- * description: Forbidden, insufficient privileges
142+ * description: Unauthorized - invalid token
190143 * 404:
191144 * description: User not found
192- * 500:
193- * description: Server error
194145 */
195- router . delete ( '/:id' , authenticateToken , authorize ( 'admin' ) , userController . deleteUser ) ;
146+
147+ router . get ( '/' , auth , userController . getUsers ) ;
148+ router . post ( '/' , auth , upload . single ( 'picture' ) , userController . createUser ) ;
149+ router . get ( '/:id' , auth , userController . getUserById ) ;
150+ router . put ( '/:id' , auth , userController . updateUser ) ;
151+ router . delete ( '/:id' , auth , userController . deleteUser ) ;
196152
197153module . exports = router ;
0 commit comments