source: server/trunk/web/lib/Sophie/Controller/Maintainers.pm @ 379

Last change on this file since 379 was 367, checked in by misc, 13 years ago

add documentation for maintainers.search

File size: 4.1 KB
Line 
1package Sophie::Controller::Maintainers;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::Maintainers - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19=head2 maintainers.byrpm ( RPMNAME, [ DISTRIB ] )
20
21Return the list of maintainers for rpm source name C<RPMNAME>.
22
23The optional C<DISTRIB> filter the result to this specific distribution.
24
25Result example:
26
27    [
28        {
29            'owner' => 'rpmmaintainer',
30            'distribution' => 'Mandriva'
31            'vendor' => 'Mandriva'
32        }
33    ];
34
35=head2 Url: /maintainers/<RPM>/<DISTRIB>
36
37Return the list of maintainers for source rpm named C<RPM> for distribution
38C<DISTRIB>.
39
40Theses alternatives are supported:
41
42    /maintainers?rpm=<RPM>;distrib=<DISTRIB>
43
44    /maintainers/rpm?distrib=<DISTRIB>
45
46=cut
47
48sub byrpm :Path :XMLRPC {
49    my ($self, $c, $rpm, $distrib) = @_;
50    $rpm     ||= $c->req->param('rpm');
51    $distrib ||= $c->req->param('distrib');
52
53    $c->stash->{xmlrpc} = [ map { { $_->get_columns } } 
54    $c->model('Base::MaintRpm')->
55        search(
56            { rpm => $rpm },
57            { select => [ qw(owner) ] },
58        )->
59        search_related('MaintSources')->
60        search_related('MaintDistrib')->
61        search_related('Distribution',
62            $distrib ? {
63                '-or' => [
64                    { shortname => $distrib },
65                    { name => $distrib },
66                ],
67            } : (),
68        )->search({},
69            {
70                'select' => [ qw'owner name label' ],
71                'as'     => [ qw'owner distribution vendor' ],
72            }
73        )->all ];
74}
75
76=head2 maintainers.bymaintainer ( MAINT, [ DISTRIB ] )
77
78Return the list of rpms for maintainer C<MAINT>.
79
80The optional C<DISTRIB> filter the result to this specific distribution.
81
82Result example:
83
84    [
85        {
86            'rpm' => 'rpm package',
87            'distribution' => 'Mandriva'
88            'vendor' => 'Mandriva'
89        }
90    ];
91
92=cut
93
94
95sub bymaintainer : XMLRPC {
96    my ($self, $c, $maint, $distrib) = @_;
97    $c->stash->{xmlrpc} = [ map { { $_->get_columns } } 
98    $c->model('Base::MaintRpm')->
99        search(
100            { owner => $maint },
101            { select => [ qw(rpm) ] },
102        )->
103        search_related('MaintSources')->
104        search_related('MaintDistrib')->
105        search_related('Distribution',
106            $distrib ? {
107                '-or' => [
108                    { shortname => $distrib },
109                    { name => $distrib },
110                ],
111            } : (),
112        )->search({},
113            {
114                'select' => [ qw'rpm name label' ],
115                'as'     => [ qw'rpm distribution vendor' ],
116            }
117        )->all ];
118   
119}
120
121=head2 maintainers.search ( MAINT, [ DISTRIB ] )
122
123Search the database for a maintainer matching C<MAINT>.
124
125The optional C<DISTRIB> filter the result to this specific distribution.
126
127Result example:
128
129    [
130        {
131            'owner' => 'maintainer',
132            'distribution' => 'Mandriva'
133            'vendor' => 'Mandriva'
134        }
135    ];
136
137=cut
138
139sub search :XMLRPC {
140    my ($self, $c, $maint, $distrib) = @_;
141
142    $c->stash->{xmlrpc} = [ map { { $_->get_columns } }
143        $c->model('Base::MaintRpm')->search(
144            { owner => { 'LIKE' => "%$maint%" } }
145        )->search_related('MaintSources'
146        )->search_related('MaintDistrib'
147        )->search_related('Distribution',
148            $distrib ? {
149                '-or' => [
150                    { shortname => $distrib },
151                    { name => $distrib },
152                ],
153            } : (),
154        )->search({},
155            {
156                'select' => [ qw'owner name label' ],
157                'as'     => [ qw'owner distribution vendor' ],
158                'group_by' => [ qw'owner name label' ],
159                'order_by' => [ qw'owner name label' ],
160            }
161        )->all ];
162}
163
164=head1 AUTHOR
165
166Olivier Thauvin
167
168=head1 LICENSE
169
170This library is free software. You can redistribute it and/or modify
171it under the same terms as Perl itself.
172
173=cut
174
175__PACKAGE__->meta->make_immutable;
176
1771;
Note: See TracBrowser for help on using the repository browser.