2023-10-17 18:02:55 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class NotificationSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
2024-02-23 21:08:51 +08:00
|
|
|
include BreadcrumbsHelper
|
2023-10-17 18:02:55 +08:00
|
|
|
|
|
|
|
attributes :id, :title, :message, :created_at, :read_at, :type, :breadcrumbs, :checked, :today
|
|
|
|
|
|
|
|
def title
|
|
|
|
object.to_notification.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def breadcrumbs
|
|
|
|
subject = object.to_notification.subject
|
|
|
|
generate_breadcrumbs(subject, []) if subject
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
object.to_notification.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full)
|
|
|
|
end
|
|
|
|
|
|
|
|
def today
|
|
|
|
object.created_at.today?
|
|
|
|
end
|
|
|
|
|
|
|
|
def checked
|
|
|
|
object.read_at.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|