@@ -11,50 +11,223 @@ const log = new Log('api:ctrl.UserController');
1111/**
1212 * UserController is in charge of the user resource and should
1313 * provide all crud actions.
14- *
15- * @export
16- * @class UserController
1714 */
1815@injectable ( )
1916@Controller ( '/v1/user' , authenticate )
2017export class UserController {
2118
2219 constructor ( @inject ( Types . UserService ) private userService : UserService ) { }
2320
21+ /**
22+ * @swagger
23+ * /user:
24+ * get:
25+ * tags:
26+ * - User
27+ * summary: List all users
28+ * description: Returns users
29+ * security:
30+ * - JWT: []
31+ * responses:
32+ * 200:
33+ * description: List of all users
34+ * schema:
35+ * type: object
36+ * title: UserResponse
37+ * properties:
38+ * success:
39+ * type: boolean
40+ * message:
41+ * type: string
42+ * data:
43+ * type: array
44+ * items:
45+ * $ref: "#/definitions/User"
46+ */
2447 @Get ( '/' )
2548 public async findAll ( @Response ( ) res : my . Response ) : Promise < any > {
2649 log . debug ( 'findAll' ) ;
2750 const users = await this . userService . findAll ( ) ;
2851 return res . found ( users . toJSON ( ) ) ;
2952 }
3053
54+ /**
55+ * @swagger
56+ * /user:
57+ * post:
58+ * tags:
59+ * - User
60+ * summary: Create new user
61+ * description: Creates new user and returns him
62+ * security:
63+ * - JWT: []
64+ * parameters:
65+ * - in: "body"
66+ * name: "body"
67+ * required: true
68+ * schema:
69+ * $ref: "#/definitions/NewUser"
70+ * responses:
71+ * 200:
72+ * description: New user
73+ * schema:
74+ * type: object
75+ * title: UserResponse
76+ * properties:
77+ * success:
78+ * type: boolean
79+ * message:
80+ * type: string
81+ * data:
82+ * $ref: "#/definitions/User"
83+ */
3184 @Post ( '/' )
3285 public async create ( @Response ( ) res : my . Response , @RequestBody ( ) body : any ) : Promise < any > {
3386 log . debug ( 'create ' , body ) ;
3487 const user = await this . userService . create ( body ) ;
3588 return res . created ( user . toJSON ( ) ) ;
3689 }
3790
91+ /**
92+ * @swagger
93+ * /user/me:
94+ * get:
95+ * tags:
96+ * - User
97+ * summary: Get logged in user
98+ * description: Returns logged in user
99+ * security:
100+ * - JWT: []
101+ * responses:
102+ * 200:
103+ * description: User
104+ * schema:
105+ * type: object
106+ * title: UserResponse
107+ * properties:
108+ * success:
109+ * type: boolean
110+ * message:
111+ * type: string
112+ * data:
113+ * type: object
114+ * $ref: "#/definitions/User"
115+ */
38116 @Get ( '/me' , populateUser )
39117 public async findMe ( @Request ( ) req : my . Request , @Response ( ) res : my . Response ) : Promise < any > {
40118 log . debug ( 'findMe' ) ;
41119 return res . found ( req . user ) ;
42120 }
43121
122+ /**
123+ * @swagger
124+ * /user/{id}:
125+ * get:
126+ * tags:
127+ * - User
128+ * summary: Get user
129+ * description: Returns a user
130+ * security:
131+ * - JWT: []
132+ * responses:
133+ * 200:
134+ * description: User
135+ * schema:
136+ * type: object
137+ * title: UserResponse
138+ * properties:
139+ * success:
140+ * type: boolean
141+ * message:
142+ * type: string
143+ * data:
144+ * type: object
145+ * $ref: "#/definitions/User"
146+ */
44147 @Get ( '/:id' )
45148 public async findOne ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string ) : Promise < any > {
46149 log . debug ( 'findOne ' , id ) ;
47150 const user = await this . userService . findOne ( parseInt ( id , 10 ) ) ;
48151 return res . found ( user . toJSON ( ) ) ;
49152 }
50153
154+ /**
155+ * @swagger
156+ * /user/{id}:
157+ * put:
158+ * tags:
159+ * - User
160+ * summary: Update user
161+ * description: Returns a user
162+ * security:
163+ * - JWT: []
164+ * parameters:
165+ * - name: "id"
166+ * in: "path"
167+ * description: "ID of user to return"
168+ * required: true
169+ * type: "integer"
170+ * format: "int64"
171+ * - in: "body"
172+ * name: "body"
173+ * description: "User object"
174+ * required: true
175+ * schema:
176+ * $ref: "#/definitions/NewUser"
177+ * responses:
178+ * 200:
179+ * description: User
180+ * schema:
181+ * type: object
182+ * title: UserResponse
183+ * properties:
184+ * success:
185+ * type: boolean
186+ * message:
187+ * type: string
188+ * data:
189+ * type: object
190+ * $ref: "#/definitions/User"
191+ */
51192 @Put ( '/:id' )
52193 public async update ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string , @RequestBody ( ) body : any ) : Promise < any > {
53194 log . debug ( 'update ' , body ) ;
54195 const user = await this . userService . update ( parseInt ( id , 10 ) , body ) ;
55196 return res . updated ( user . toJSON ( ) ) ;
56197 }
57198
199+ /**
200+ * @swagger
201+ * /user/{id}:
202+ * delete:
203+ * tags:
204+ * - User
205+ * summary: Delete user
206+ * description: Returns a user
207+ * security:
208+ * - JWT: []
209+ * parameters:
210+ * - name: "id"
211+ * in: "path"
212+ * description: "ID of user to return"
213+ * required: true
214+ * type: "integer"
215+ * format: "int64"
216+ * responses:
217+ * 200:
218+ * description: User
219+ * schema:
220+ * type: object
221+ * title: UserResponse
222+ * properties:
223+ * success:
224+ * type: boolean
225+ * message:
226+ * type: string
227+ * data:
228+ * type: object
229+ * example:
230+ */
58231 @Delete ( '/:id' )
59232 public async destroy ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string ) : Promise < any > {
60233 log . debug ( 'destroy ' , id ) ;
0 commit comments