forked from PhillipTaylor/Wardrobe
/
Tags.pm
98 lines (63 loc) · 2.02 KB
/
Tags.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package Wardrobe::Controller::Tags;
use Moose;
use namespace::autoclean;
use Wardrobe::Model::Outfit;
use Wardrobe::TemplateUtil (qw/cln/);
BEGIN {extends 'Catalyst::Controller'; }
=head1 NAME
Wardrobe::Controller::Tags - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
=head2 index
=cut
sub tag_root :Chained('/root') :PathPart('tags') :CaptureArgs(0) {
my ($self, $c) = @_;
my $breadcrumbs = $c->stash->{'breadcrumb'};
$breadcrumbs->push('tags', 'tags');
}
sub index :Chained('tag_root') :PathPart('') :Args(0) {
my ( $self, $c ) = @_;
my @outfits = Wardrobe::Model::Outfit->get_all_outfits();
$c->stash(
"template" => 'tags/list.tt',
"outfits" => \@outfits
);
}
sub tag :Chained('tag_root') :PathPart('tag') :Args(2) {
my ($self, $c, $outfit_id, $outfit_name) = @_;
my $outfit = Wardrobe::Model::Outfit->get_outfit_by_id($outfit_id);
my $breadcrumbs = $c->stash->{'breadcrumb'};
$breadcrumbs->push('tag', "tag/$outfit_id/$outfit_name");
$c->stash(
"template" => 'tags/tag.tt',
"outfit" => $outfit
);
}
sub add :Chained('tag_root') :PathPart('add') :Args(0) {
my ( $self, $c ) = @_;
if (lc $c->req->method ne 'post') {
## forward to error page.
$c->log->debug('not a post');
}
my $clothing_id = $c->req->params->{"clothing_id"};
my $outfit_name = $c->req->params->{"tag"};
if ($outfit_name eq '') {
$c->log->warn('User attempted to tag against an empty string');
$c->res->redirect($c->uri_for($c->controller('Clothes')->action_for('clothing'), $clothing_id, 'x'));
return;
}
my $outfit = Wardrobe::Model::Outfit->find_or_create_outfit($outfit_name);
Wardrobe::Model::Outfit->tag_clothing_to_outfit($outfit->outfit_id, $clothing_id);
my $cln_name = Wardrobe::TemplateUtil::cln($outfit_name);
$c->res->redirect($c->uri_for('tag', $outfit->outfit_id, $cln_name));
}
=head1 AUTHOR
PTaylor,,,
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;