line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RESTApp::User; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
433
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Raisin::API; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
387
|
use UseCase::User; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Types::Standard qw(Int Str); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
desc 'Operations about user'; |
12
|
|
|
|
|
|
|
resource users => sub { |
13
|
|
|
|
|
|
|
summary 'List users'; |
14
|
|
|
|
|
|
|
params( |
15
|
|
|
|
|
|
|
optional('start', type => Int, default => 0, desc => 'Pager start'), |
16
|
|
|
|
|
|
|
optional('count', type => Int, default => 10, desc => 'Pager count'), |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
get sub { |
19
|
|
|
|
|
|
|
my $params = shift; |
20
|
|
|
|
|
|
|
my @users = UseCase::User::list(%$params); |
21
|
|
|
|
|
|
|
{ data => RESTApp::paginate(\@users, $params) } |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
summary 'List all users'; |
25
|
|
|
|
|
|
|
get 'all' => sub { |
26
|
|
|
|
|
|
|
my $params = shift; |
27
|
|
|
|
|
|
|
my @users = UseCase::User::list(%$params); |
28
|
|
|
|
|
|
|
{ data => \@users } |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
summary 'Create a new user'; |
32
|
|
|
|
|
|
|
params( |
33
|
|
|
|
|
|
|
requires('name', type => Str, desc => 'User name'), |
34
|
|
|
|
|
|
|
requires('password', type => Str, desc => 'User password'), |
35
|
|
|
|
|
|
|
optional('email', type => Str, default => undef, desc => 'User email'), |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
post sub { |
38
|
|
|
|
|
|
|
my $params = shift; |
39
|
|
|
|
|
|
|
{ success => UseCase::User::create(%$params) } |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
params( |
43
|
|
|
|
|
|
|
requires('id', type => Int, desc => 'User ID'), |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
route_param id => sub { |
46
|
|
|
|
|
|
|
summary 'Show a user'; |
47
|
|
|
|
|
|
|
get sub { |
48
|
|
|
|
|
|
|
my $params = shift; |
49
|
|
|
|
|
|
|
{ data => UseCase::User::show($params->{id}) } |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
summary 'Edit a user'; |
53
|
|
|
|
|
|
|
params( |
54
|
|
|
|
|
|
|
optional('password', type => Str, desc => 'User password'), |
55
|
|
|
|
|
|
|
optional('email', type => Str, desc => 'User email'), |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
put sub { |
58
|
|
|
|
|
|
|
my $params = shift; |
59
|
|
|
|
|
|
|
{ data => UseCase::User::edit($params->{id}, %$params) } |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
summary 'Edit a user'; |
62
|
|
|
|
|
|
|
params( |
63
|
|
|
|
|
|
|
optional('password', type => Str, desc => 'User password'), |
64
|
|
|
|
|
|
|
optional('email', type => Str, desc => 'User email'), |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
patch sub { |
67
|
|
|
|
|
|
|
my $params = shift; |
68
|
|
|
|
|
|
|
{ data => UseCase::User::edit($params->{id}, %$params) } |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
desc 'Bump a user'; |
72
|
|
|
|
|
|
|
resource bump => sub { |
73
|
|
|
|
|
|
|
summary 'Get bumps count'; |
74
|
|
|
|
|
|
|
tags 'users', 'bump'; |
75
|
|
|
|
|
|
|
get sub { |
76
|
|
|
|
|
|
|
my $params = shift; |
77
|
|
|
|
|
|
|
{ data => UseCase::User::show($params->{id})->{bumped} } |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
summary 'Bump a user'; |
81
|
|
|
|
|
|
|
tags 'users', 'bump'; |
82
|
|
|
|
|
|
|
put sub { |
83
|
|
|
|
|
|
|
my $params = shift; |
84
|
|
|
|
|
|
|
{ success => UseCase::User::bump($params->{id}) } |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
summary 'Bump a user'; |
87
|
|
|
|
|
|
|
tags 'users', 'bump'; |
88
|
|
|
|
|
|
|
patch sub { |
89
|
|
|
|
|
|
|
my $params = shift; |
90
|
|
|
|
|
|
|
{ success => UseCase::User::bump($params->{id}) } |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
summary 'Delete a user'; |
95
|
|
|
|
|
|
|
del sub { |
96
|
|
|
|
|
|
|
my $params = shift; |
97
|
|
|
|
|
|
|
{ success => UseCase::User::remove($params->{id}) } |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |