1
1
const express = require ( 'express' ) ;
2
2
const userController = require ( '../controllers/userController' ) ;
3
- const authenticateToken = require ( '../middleware/auth' ) ;
4
- const authorize = require ( '../middleware/authorize' ) ;
3
+ const auth = require ( '../middleware/auth' ) ;
5
4
const multer = require ( 'multer' ) ;
6
5
const upload = multer ( { dest : 'uploads/' } ) ;
7
6
8
7
const router = express . Router ( ) ;
9
8
10
9
/**
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
+ *
12
31
* /users:
13
32
* get:
14
- * summary: Retrieve all users
15
- * description: Returns a list of all users
33
+ * tags:
34
+ * - Users
35
+ * summary: Get all users
16
36
* security:
17
37
* - bearerAuth: []
18
38
* responses:
19
39
* 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
34
41
* 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
+ *
82
44
* post:
45
+ * tags:
46
+ * - Users
83
47
* summary: Create a new user
84
- * description: Creates a new user in the system
48
+ * security:
49
+ * - bearerAuth: []
85
50
* requestBody:
86
51
* required: true
87
52
* content:
88
- * application/json :
53
+ * multipart/form-data :
89
54
* schema:
90
55
* type: object
91
56
* properties:
@@ -95,44 +60,46 @@ router.get('/:id', authenticateToken, userController.getUserById);
95
60
* type: string
96
61
* password:
97
62
* type: string
98
- * required:
99
- * - name
100
- * - email
101
- * - password
102
- * security:
103
- * - bearerAuth: []
63
+ * picture:
64
+ * type: string
65
+ * format: binary
104
66
* responses:
105
67
* 201:
106
68
* 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
118
69
* 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
+ *
127
72
* /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
+ *
128
93
* 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: []
131
99
* parameters:
132
- * - name: id
133
- * in: path
100
+ * - in: path
101
+ * name: id
134
102
* required: true
135
- * description: The ID of the user to update
136
103
* schema:
137
104
* type: integer
138
105
* requestBody:
@@ -146,52 +113,41 @@ router.post('/', authenticateToken, upload.single('picture'), userController.cre
146
113
* type: string
147
114
* email:
148
115
* type: string
149
- * required:
150
- * - name
151
- * - email
152
- * security:
153
- * - bearerAuth: []
116
+ * password:
117
+ * type: string
154
118
* responses:
155
119
* 200:
156
120
* description: User updated successfully
157
- * 400:
158
- * description: Bad request, validation error
159
121
* 401:
160
- * description: Unauthorized access
122
+ * description: Unauthorized - invalid token
161
123
* 404:
162
124
* 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
+ *
171
126
* 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: []
174
132
* parameters:
175
- * - name: id
176
- * in: path
133
+ * - in: path
134
+ * name: id
177
135
* required: true
178
- * description: The ID of the user to delete
179
136
* schema:
180
137
* type: integer
181
- * security:
182
- * - bearerAuth: []
183
138
* responses:
184
139
* 200:
185
140
* description: User deleted successfully
186
141
* 401:
187
- * description: Unauthorized access
188
- * 403:
189
- * description: Forbidden, insufficient privileges
142
+ * description: Unauthorized - invalid token
190
143
* 404:
191
144
* description: User not found
192
- * 500:
193
- * description: Server error
194
145
*/
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 ) ;
196
152
197
153
module . exports = router ;
0 commit comments