diff --git a/lib/Pooru/API/V0.pm b/lib/Pooru/API/V0.pm index 3b22fda..ba3dbcc 100644 --- a/lib/Pooru/API/V0.pm +++ b/lib/Pooru/API/V0.pm @@ -1,15 +1,12 @@ package Pooru::API::V0; use Mojo::Base "Mojolicious", -signatures; -use DBD::SQLite::Constants ":dbd_sqlite_string_mode"; +use DBI; use DBIx::Migration; -use Pooru::Schema; use Pooru::API::V0::Model::Media; use Pooru::API::V0::Model::Tags; -use DBI; - use constant { "Pooru::API::V0::Model::Media::ROWS" => 12, "Pooru::API::V0::Model::Media::SIMILAR_ROWS" => 6, @@ -17,33 +14,6 @@ use constant { "Pooru::API::V0::Model::Tags::SEARCH_ROWS" => 15, }; -sub _search_opts () -{ - return { - Media => { - order_by => {-desc => "id"}, - rows => 12, - }, - TagCountView => { - order_by => [ - {-desc => [qw(count kind_id)]}, - {-asc => "name"}, - ], - rows => 1000, - }, - TaggedMediaView_media => { - order_by => {-desc => "media_id"}, - rows => 12, - }, - TaggedMediaView_tags => { - order_by => [ - {-desc => "tag_kind_id"}, - {-asc => "tag_name"}, - ], - rows => 1000, - }, - }; -} sub startup ($self) { @@ -52,24 +22,6 @@ sub startup ($self) my $config = $self->plugin("Config"); $self->secrets($config->{secrets}); - $self->helper(schema => sub { - state $schema = Pooru::Schema->connect( - $config->{dsn}, - undef, - undef, - { - sqlite_string_mode => - DBD_SQLITE_STRING_MODE_UNICODE_STRICT, - on_connect_call => "use_foreign_keys", - } - ); - }); - $self->helper(pager => sub ($, $rs) { - return map +($_ => ($rs->pager->$_ and int($rs->pager->$_))), - qw(first_page previous_page current_page next_page - last_page); - }); - DBIx::Migration->new({ dsn => $config->{dsn}, dir => $self->app->home->child("migrations")->to_string, diff --git a/lib/Pooru/API/V0/Controller/Media.pm b/lib/Pooru/API/V0/Controller/Media.pm index 07a0627..741bb23 100644 --- a/lib/Pooru/API/V0/Controller/Media.pm +++ b/lib/Pooru/API/V0/Controller/Media.pm @@ -3,7 +3,6 @@ use Mojo::Base "Mojolicious::Controller", -signatures; use List::Util qw(uniq); -my %search_opts = Pooru::API::V0::_search_opts->%*; sub _list_no_tags ($self, $page) { diff --git a/lib/Pooru/API/V0/Controller/Tags.pm b/lib/Pooru/API/V0/Controller/Tags.pm index 0d1d0f4..6f7c278 100644 --- a/lib/Pooru/API/V0/Controller/Tags.pm +++ b/lib/Pooru/API/V0/Controller/Tags.pm @@ -1,7 +1,6 @@ package Pooru::API::V0::Controller::Tags; use Mojo::Base "Mojolicious::Controller", -signatures; -my %search_opts = Pooru::API::V0::_search_opts->%*; sub list ($self) { diff --git a/lib/Pooru/Schema/Result/Kind.pm b/lib/Pooru/Schema/Result/Kind.pm deleted file mode 100644 index 1ea36a3..0000000 --- a/lib/Pooru/Schema/Result/Kind.pm +++ /dev/null @@ -1,96 +0,0 @@ -use utf8; -package Pooru::Schema::Result::Kind; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::Kind - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("kind"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'text' - is_nullable: 0 - size: 32 - -=head2 name - - data_type: 'text' - is_nullable: 0 - size: 256 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "text", is_nullable => 0, size => 32 }, - "name", - { data_type => "text", is_nullable => 0, size => 256 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("id"); - -=head1 UNIQUE CONSTRAINTS - -=head2 C - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("name_unique", ["name"]); - -=head1 RELATIONS - -=head2 tags - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "tags", - "Pooru::Schema::Result::Tag", - { "foreign.kind_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, -); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ePfTpTOWY1H3Bky/bjA3iA - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/Result/Media.pm b/lib/Pooru/Schema/Result/Media.pm deleted file mode 100644 index e4bcf5a..0000000 --- a/lib/Pooru/Schema/Result/Media.pm +++ /dev/null @@ -1,136 +0,0 @@ -use utf8; -package Pooru::Schema::Result::Media; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::Media - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("media"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'integer' - is_auto_increment: 1 - is_nullable: 0 - -=head2 storage_id - - data_type: 'text' - is_nullable: 0 - size: 64 - -=head2 filename - - data_type: 'text' - is_nullable: 0 - size: 256 - -=head2 content_type - - data_type: 'text' - is_nullable: 1 - size: 256 - -=head2 upload_datetime - - data_type: 'text' - default_value: current_timestamp - is_nullable: 1 - size: 32 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "storage_id", - { data_type => "text", is_nullable => 0, size => 64 }, - "filename", - { data_type => "text", is_nullable => 0, size => 256 }, - "content_type", - { data_type => "text", is_nullable => 1, size => 256 }, - "upload_datetime", - { - data_type => "text", - default_value => \"current_timestamp", - is_nullable => 1, - size => 32, - }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("id"); - -=head1 UNIQUE CONSTRAINTS - -=head2 C - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("storage_id_unique", ["storage_id"]); - -=head1 RELATIONS - -=head2 media_tags - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "media_tags", - "Pooru::Schema::Result::MediaTag", - { "foreign.media_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, -); - -=head2 tags - -Type: many_to_many - -Composing rels: L -> tag - -=cut - -__PACKAGE__->many_to_many("tags", "media_tags", "tag"); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ODG4pqImG0JNc1YpUIVNFA - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/Result/MediaTag.pm b/lib/Pooru/Schema/Result/MediaTag.pm deleted file mode 100644 index c81d603..0000000 --- a/lib/Pooru/Schema/Result/MediaTag.pm +++ /dev/null @@ -1,99 +0,0 @@ -use utf8; -package Pooru::Schema::Result::MediaTag; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::MediaTag - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("media_tag"); - -=head1 ACCESSORS - -=head2 media_id - - data_type: 'integer' - is_foreign_key: 1 - is_nullable: 0 - -=head2 tag_id - - data_type: 'integer' - is_foreign_key: 1 - is_nullable: 0 - -=cut - -__PACKAGE__->add_columns( - "media_id", - { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, - "tag_id", - { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("media_id", "tag_id"); - -=head1 RELATIONS - -=head2 media - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "media", - "Pooru::Schema::Result::Media", - { id => "media_id" }, - { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" }, -); - -=head2 tag - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "tag", - "Pooru::Schema::Result::Tag", - { id => "tag_id" }, - { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" }, -); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vtbD/Q3h2FEwALyG3IAaEg - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/Result/Tag.pm b/lib/Pooru/Schema/Result/Tag.pm deleted file mode 100644 index b18d66e..0000000 --- a/lib/Pooru/Schema/Result/Tag.pm +++ /dev/null @@ -1,157 +0,0 @@ -use utf8; -package Pooru::Schema::Result::Tag; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::Tag - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("tag"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'integer' - is_auto_increment: 1 - is_nullable: 0 - -=head2 name - - data_type: 'text' - is_nullable: 0 - size: 256 - -=head2 kind_id - - data_type: 'text' - is_foreign_key: 1 - is_nullable: 1 - size: 32 - -=head2 display - - data_type: 'text ' - is_nullable: 1 - size: 289 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "name", - { data_type => "text", is_nullable => 0, size => 256 }, - "kind_id", - { data_type => "text", is_foreign_key => 1, is_nullable => 1, size => 32 }, - "display", - { data_type => "text ", is_nullable => 1, size => 289 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("id"); - -=head1 UNIQUE CONSTRAINTS - -=head2 C - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("display_unique", ["display"]); - -=head2 C - -=over 4 - -=item * L - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("name_kind_id_unique", ["name", "kind_id"]); - -=head1 RELATIONS - -=head2 kind - -Type: belongs_to - -Related object: L - -=cut - -__PACKAGE__->belongs_to( - "kind", - "Pooru::Schema::Result::Kind", - { id => "kind_id" }, - { - is_deferrable => 0, - join_type => "LEFT", - on_delete => "NO ACTION", - on_update => "CASCADE", - }, -); - -=head2 media_tags - -Type: has_many - -Related object: L - -=cut - -__PACKAGE__->has_many( - "media_tags", - "Pooru::Schema::Result::MediaTag", - { "foreign.tag_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, -); - -=head2 medias - -Type: many_to_many - -Composing rels: L -> media - -=cut - -__PACKAGE__->many_to_many("medias", "media_tags", "media"); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:XopZiRzgoNJuweuyFj9elA - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/Result/TagCountView.pm b/lib/Pooru/Schema/Result/TagCountView.pm deleted file mode 100644 index fae0c24..0000000 --- a/lib/Pooru/Schema/Result/TagCountView.pm +++ /dev/null @@ -1,76 +0,0 @@ -use utf8; -package Pooru::Schema::Result::TagCountView; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::TagCountView - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; -__PACKAGE__->table_class("DBIx::Class::ResultSource::View"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("tag_count_view"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'integer' - is_nullable: 1 - -=head2 name - - data_type: 'text' - is_nullable: 1 - size: 256 - -=head2 kind_id - - data_type: 'text' - is_nullable: 1 - size: 32 - -=head2 display - - data_type: 'text' - is_nullable: 1 - size: 289 - -=head2 count - - data_type: (empty string) - is_nullable: 1 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_nullable => 1 }, - "name", - { data_type => "text", is_nullable => 1, size => 256 }, - "kind_id", - { data_type => "text", is_nullable => 1, size => 32 }, - "display", - { data_type => "text", is_nullable => 1, size => 289 }, - "count", - { data_type => "", is_nullable => 1 }, -); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Z8o5//l7dE0oSJLzDguHFw - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/Result/TaggedMediaView.pm b/lib/Pooru/Schema/Result/TaggedMediaView.pm deleted file mode 100644 index 464dcae..0000000 --- a/lib/Pooru/Schema/Result/TaggedMediaView.pm +++ /dev/null @@ -1,115 +0,0 @@ -use utf8; -package Pooru::Schema::Result::TaggedMediaView; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pooru::Schema::Result::TaggedMediaView - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; -__PACKAGE__->table_class("DBIx::Class::ResultSource::View"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("tagged_media_view"); - -=head1 ACCESSORS - -=head2 media_id - - data_type: 'integer' - is_nullable: 1 - -=head2 media_storage_id - - data_type: 'text' - is_nullable: 1 - size: 64 - -=head2 media_filename - - data_type: 'text' - is_nullable: 1 - size: 256 - -=head2 media_content_type - - data_type: 'text' - is_nullable: 1 - size: 256 - -=head2 media_upload_datetime - - data_type: 'text' - is_nullable: 1 - size: 32 - -=head2 tag_id - - data_type: 'integer' - is_nullable: 1 - -=head2 tag_name - - data_type: 'text' - is_nullable: 1 - size: 256 - -=head2 tag_kind_id - - data_type: 'text' - is_nullable: 1 - size: 32 - -=head2 tag_display - - data_type: 'text' - is_nullable: 1 - size: 289 - -=head2 tag_count - - data_type: (empty string) - is_nullable: 1 - -=cut - -__PACKAGE__->add_columns( - "media_id", - { data_type => "integer", is_nullable => 1 }, - "media_storage_id", - { data_type => "text", is_nullable => 1, size => 64 }, - "media_filename", - { data_type => "text", is_nullable => 1, size => 256 }, - "media_content_type", - { data_type => "text", is_nullable => 1, size => 256 }, - "media_upload_datetime", - { data_type => "text", is_nullable => 1, size => 32 }, - "tag_id", - { data_type => "integer", is_nullable => 1 }, - "tag_name", - { data_type => "text", is_nullable => 1, size => 256 }, - "tag_kind_id", - { data_type => "text", is_nullable => 1, size => 32 }, - "tag_display", - { data_type => "text", is_nullable => 1, size => 289 }, - "tag_count", - { data_type => "", is_nullable => 1 }, -); - - -# Created by DBIx::Class::Schema::Loader v0.07052 @ 2025-04-26 09:36:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yihpYS6ccFg3BurhyxXqIw - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/Pooru/Schema/ResultSet/Media.pm b/lib/Pooru/Schema/ResultSet/Media.pm deleted file mode 100644 index 13f0770..0000000 --- a/lib/Pooru/Schema/ResultSet/Media.pm +++ /dev/null @@ -1,10 +0,0 @@ -package Pooru::Schema::ResultSet::Media; -use v5.40; -use base "DBIx::Class::ResultSet"; - -sub random ($self, $rows = 1) -{ - return $self->search(undef, {order_by => "random()", rows => $rows}); -} - -1; diff --git a/lib/Pooru/Schema/ResultSet/Tag.pm b/lib/Pooru/Schema/ResultSet/Tag.pm deleted file mode 100644 index 7b281fd..0000000 --- a/lib/Pooru/Schema/ResultSet/Tag.pm +++ /dev/null @@ -1,10 +0,0 @@ -package Pooru::Schema::ResultSet::Tag; -use v5.40; -use base "DBIx::Class::ResultSet"; - -sub random ($self, $rows = 1) -{ - return $self->search(undef, {order_by => "random()", rows => $rows}); -} - -1;