Skip to content

Commit 78f5061

Browse files
committed
refactor: Move enhance audio to separate model
1 parent d99adde commit 78f5061

File tree

10 files changed

+61
-4
lines changed

10 files changed

+61
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Admin::EnhanceController < Admin::BaseController
2+
def index
3+
@enhance_audio_files = EnhanceAudioFile.order(created_at: :desc).page(params[:page])
4+
end
5+
end

app/controllers/enhance_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class EnhanceController < ApplicationController
22
def index; end
3+
4+
def upload_audio; end
35
end

app/models/enhance_audio_file.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class EnhanceAudioFile < ApplicationRecord
2+
belongs_to :user
3+
4+
has_many_attached :file, dependent: :destroy
5+
6+
validates :file, content_type: ["audio/mpeg", "audio/wav", "audio/ogg"], size: { less_than: 10.megabytes }
7+
end

app/models/project.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ class Project < ApplicationRecord
77

88
has_many :project_backups, -> { select(:uuid, :project_uuid, :created_at) }, class_name: "ProjectBackup", foreign_key: :project_uuid, dependent: :destroy
99

10-
has_many_attached :audio, dependent: :destroy
11-
1210
validates :user_id, presence: true
1311
validates :title, presence: true, length: { minimum: 1, maximum: 75 }
1412
validates :content, length: { maximum: PROJECT_CONTENT_LIMIT }

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class User < ApplicationRecord
5050
has_many :blocks
5151
has_many :visits, class_name: "Ahoy::Visit"
5252
has_many :projects, dependent: :destroy
53+
has_many :enhance_audio_files, dependent: :destroy
5354

5455
has_one_attached :profile_image, dependent: :destroy
5556
has_one_attached :banner_image, dependent: :destroy

app/views/admin/_navigation.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<%= link_to "emails", admin_email_notifications_path, data: { prefetch: false }, class: "button #{ "button--secondary" unless current_page?(admin_email_notifications_path) }" %>
1313
<%= link_to "activities", admin_activities_path, data: { prefetch: false }, class: "button #{ "button--secondary" unless current_page?(admin_activities_path) }" %>
1414
<%= link_to "reports", admin_reports_path, data: { prefetch: false }, class: "button #{ "button--secondary" unless current_page?(admin_reports_path) }" %>
15+
<%= link_to "enhance", admin_enhance_index_path, data: { prefetch: false }, class: "button #{ "button--secondary" unless current_page?(admin_enhance_index_path) }" %>
1516
</center>
1617

1718
<hr>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%= render "admin/navigation" %>
2+
3+
<p>Total enhance audio files: <strong><%= EnhanceAudioFile.all.size %></strong></p>
4+
5+
<hr>
6+
7+
<table>
8+
<tr>
9+
<th>ID</th>
10+
<th>User ID</th>
11+
<th>Name</th>
12+
<th>File</th>
13+
</tr>
14+
15+
<% @enhance_audio_files.each do |audio_file| %>
16+
<tr>
17+
<td><%= audio_file.id %></td>
18+
<td><%= audio_file.user_id %></td>
19+
<td><%= audio_file.name %></td>
20+
<td><%= audio_file.file %></td>
21+
</tr>
22+
<% end %>
23+
</table>
24+
25+
<%= paginate @enhance_audio_files %>

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def matches?(request)
3434
get "editor", to: "editor#index", as: "editor"
3535
get "editor/data", "editor#data"
3636
get "editor/user_projects", "editor#user_projects"
37-
get "enhance", to: "enhance#index", as: "enhance"
3837
get "workshop-ui", to: "editor#zez_ui", as: "zez_ui"
38+
get "enhance", to: "enhance#index", as: "enhance"
3939

4040
get "active_storage_blob_variant_url/:key", to: "application#active_storage_blob_variant_url"
4141

@@ -55,6 +55,7 @@ def matches?(request)
5555
resources :email_notifications, only: [:index]
5656
resources :activities, only: [:index]
5757
resources :reports, only: [:index, :show]
58+
resources :enhance, only: [:index]
5859
end
5960

6061
get "/auth/:provider/callback", to: "sessions#create", as: "oauth"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateEnhanceAudioFiles < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :enhance_audio_files do |t|
4+
t.integer :user_id
5+
t.string :name
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2023_10_07_201634) do
13+
ActiveRecord::Schema.define(version: 2024_06_19_004335) do
1414

1515
create_table "active_storage_attachments", force: :cascade do |t|
1616
t.string "name", null: false
@@ -177,6 +177,13 @@
177177
t.index ["post_id"], name: "index_email_notifications_on_post_id"
178178
end
179179

180+
create_table "enhance_audio_files", force: :cascade do |t|
181+
t.integer "user_id"
182+
t.string "name"
183+
t.datetime "created_at", precision: 6, null: false
184+
t.datetime "updated_at", precision: 6, null: false
185+
end
186+
180187
create_table "favorites", force: :cascade do |t|
181188
t.integer "user_id"
182189
t.integer "post_id"

0 commit comments

Comments
 (0)