Skip to content

Commit 110a1b7

Browse files
committed
Handle full content lifecycle
1 parent d332ec5 commit 110a1b7

File tree

6 files changed

+77
-6
lines changed

6 files changed

+77
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
class ContentsController < ApplicationController
2+
before_action :load_content, only: [ :show, :destroy ]
3+
4+
def index
5+
@contents = Content.all
6+
end
7+
8+
def show
9+
end
10+
11+
def destroy
12+
@content.destroy
13+
14+
redirect_to contents_path, notice: t(".success")
15+
end
16+
17+
private
18+
19+
def load_content
20+
@content = Content.find(params[:id])
21+
end
222
end

debug_fasp/app/jobs/application_job.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ class ApplicationJob < ActiveJob::Base
44

55
# Most jobs are safe to ignore if the underlying records are no longer available
66
# discard_on ActiveJob::DeserializationError
7+
8+
private
9+
10+
def fetch_object(uri)
11+
FaspDataSharing::ActivityPubObject.new(uri:).fetch
12+
end
713
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class FaspDataSharing::ProcessContentDeletionJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
Content.where(uri:).destroy_all
6+
end
7+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class FaspDataSharing::ProcessContentUpdateJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
object = fetch_object(uri)
6+
content = Content.find_or_initialize_by(uri:, object_type: object["type"])
7+
content.update(full_object: object)
8+
end
9+
end

debug_fasp/app/jobs/fasp_data_sharing/process_new_content_job.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ def perform(uri)
1111
)
1212
end
1313
end
14-
15-
private
16-
17-
def fetch_object(uri)
18-
FaspDataSharing::ActivityPubObject.new(uri:).fetch
19-
end
2014
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<div class="flex gap-2 my-4 border-b border-blue-100">
2+
<%= link_to t(".subscriptions"), subscriptions_path, class: "hover:bg-blue-50 p-2" %>
3+
<span class="bg-blue-100 p-2">
4+
<%= t(".contents") %>
5+
</span>
6+
<%= link_to t(".accounts"), contents_path, class: "hover:bg-blue-50 p-2" %>
7+
</div>
8+
9+
<h1 class="text-2xl font-bold mb-4"><%= t(".contents") %></h1>
10+
11+
<table class="border-separate border-spacing-2">
12+
<thead>
13+
<tr>
14+
<th><%= Content.human_attribute_name(:uri) %></th>
15+
<th><%= Content.human_attribute_name(:object_type) %></th>
16+
<th><%= Content.human_attribute_name(:created_at) %></th>
17+
<th><%= Content.human_attribute_name(:updated_at) %></th>
18+
<th></th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<% @contents.each do |content| %>
23+
<tr class="even:bg-blue-50">
24+
<td><%= content.uri %></td>
25+
<td><%= content.object_type %></td>
26+
<td><%= content.created_at %></td>
27+
<td><%= content.updated_at %></td>
28+
<td>
29+
<%= link_to t(".show"), content_path(content), class: "font-bold text-sm hover:underline hover:text-red-400" %>
30+
<%= link_to t(".destroy"), content_path(content), data: {turbo_method: :delete}, class: "font-bold text-sm hover:underline hover:text-red-400" %>
31+
</td>
32+
</tr>
33+
<% end %>
34+
</tbody>
35+
</table>

0 commit comments

Comments
 (0)