|
1
|
|
|
""" |
|
2
|
|
|
Define the REST verbs relative to the users |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
from flasgger import swag_from |
|
6
|
|
|
from flask.ext.restful import Resource |
|
7
|
|
|
from flask.ext.restful.reqparse import Argument |
|
8
|
|
|
from flask.json import jsonify |
|
9
|
|
|
|
|
10
|
|
|
from repositories import UserRepository |
|
11
|
|
|
from util import parse_params |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class UserResource(Resource): |
|
15
|
|
|
""" Verbs relative to the users """ |
|
16
|
|
|
|
|
17
|
|
|
@staticmethod |
|
18
|
|
|
@swag_from('../swagger/user/GET.yml') |
|
19
|
|
|
def get(last_name, first_name): |
|
20
|
|
|
""" Return an user key information based on his name """ |
|
21
|
|
|
user = UserRepository.get(last_name=last_name, first_name=first_name) |
|
22
|
|
|
return jsonify({'user': user.json}) |
|
23
|
|
|
|
|
24
|
|
|
@staticmethod |
|
25
|
|
|
@parse_params( |
|
26
|
|
|
Argument( |
|
27
|
|
|
'age', |
|
28
|
|
|
location='json', |
|
29
|
|
|
required=True, |
|
30
|
|
|
help='The age of the user.' |
|
31
|
|
|
), |
|
32
|
|
|
) |
|
33
|
|
|
@swag_from('../swagger/user/POST.yml') |
|
34
|
|
|
def post(last_name, first_name, age): |
|
35
|
|
|
""" Create an user based on the sent information """ |
|
36
|
|
|
user = UserRepository.create( |
|
37
|
|
|
last_name=last_name, |
|
38
|
|
|
first_name=first_name, |
|
39
|
|
|
age=age |
|
40
|
|
|
) |
|
41
|
|
|
return jsonify({'user': user.json}) |
|
42
|
|
|
|
|
43
|
|
|
@staticmethod |
|
44
|
|
|
@parse_params( |
|
45
|
|
|
Argument( |
|
46
|
|
|
'age', |
|
47
|
|
|
location='json', |
|
48
|
|
|
required=True, |
|
49
|
|
|
help='The age of the user.' |
|
50
|
|
|
), |
|
51
|
|
|
) |
|
52
|
|
|
@swag_from('../swagger/user/PUT.yml') |
|
53
|
|
|
def put(last_name, first_name, age): |
|
54
|
|
|
""" Update an user based on the sent information """ |
|
55
|
|
|
repository = UserRepository() |
|
56
|
|
|
user = repository.update( |
|
57
|
|
|
last_name=last_name, |
|
58
|
|
|
first_name=first_name, |
|
59
|
|
|
age=age |
|
60
|
|
|
) |
|
61
|
|
|
return jsonify({'user': user.json}) |
|
62
|
|
|
|