Phase 3: move service layer, serializers and DTOs into WarpEngine + dummy-app test suite
- all catalog services (update/software/highlighted/builds/file/file-manager/ download/image + SoftwareResponseBuilder), the SoftwareUpdater platform services and their concerns, Blueprinter serializers (incl. TimestampFields) and the 4 DTOs now live in the engine under WarpEngine:: - constantize dispatch strings use absolute names (WarpEngine::SoftwareUpdater::<Platform>Service) - container paths read from WarpEngine.config everywhere (FileService, DownloadService, FileManagerService, ArchiveExtraction, ReleaseSerializer path rewriting); FileManagerService base path is now lazy - engine requires blueprinter itself; gemspec declares blueprinter + rubyzip - engine test suite: spec/dummy app (mysql warp_engine_test, catalog-only schema), rails_helper with engine-local factories; catalog model/service specs and factories moved from the host - host suite keeps TTG specs and loads catalog factories from the engine Verified: engine suite 40 green, host suite 14 green, /api/software and /api/builds byte-identical to baselines, admin OK. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
module WarpEngine
|
||||
module TimestampFields
|
||||
GO_ZERO_TIME = "0001-01-01T00:00:00Z"
|
||||
TS_FORMAT = "%Y-%m-%dT%H:%M:%S.%3NZ"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
module WarpEngine
|
||||
class ExternalLinkSerializer < Blueprinter::Base
|
||||
include TimestampFields
|
||||
|
||||
field(:id) { |el| el.id }
|
||||
field(:createdAt) { |el| el.created_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:updatedAt) { |el| el.updated_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:deletedAt) { |el| el.deleted_at&.utc&.strftime(TS_FORMAT) }
|
||||
field(:softwareId) { |el| el.software_id }
|
||||
field :label
|
||||
field :url
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
module WarpEngine
|
||||
class PlatformLinkSerializer < Blueprinter::Base
|
||||
field :name
|
||||
field :url
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
module WarpEngine
|
||||
class ReleaseSerializer < Blueprinter::Base
|
||||
include TimestampFields
|
||||
|
||||
FILE_PATH_TO = "/file/"
|
||||
|
||||
# A lemezen tárolt asset-útvonalak publikus /file/ URL-lé írása configból.
|
||||
def self.file_path_from
|
||||
"#{WarpEngine.config.file_container_path.chomp("/")}/"
|
||||
end
|
||||
|
||||
def self.assets_of(release)
|
||||
release.association(:release_assets).loaded? ? release.release_assets : release.release_assets.to_a
|
||||
end
|
||||
|
||||
def self.asset_path(release, kind)
|
||||
asset = assets_of(release).find { |a| a.kind == kind }
|
||||
asset ? asset.path.gsub(file_path_from, FILE_PATH_TO) : ""
|
||||
end
|
||||
|
||||
field(:id) { |r| r.id }
|
||||
field(:createdAt) { |r| r.created_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:updatedAt) { |r| r.updated_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:deletedAt) { |r| r.deleted_at&.utc&.strftime(TS_FORMAT) }
|
||||
field(:softwareId) { |r| r.software_id }
|
||||
field :version
|
||||
field(:cartridgePath) { |r| asset_path(r, "cartridge") }
|
||||
field(:sourcePath) { |r| asset_path(r, "source") }
|
||||
field(:htmlFolderPath) { |r| asset_path(r, "html") }
|
||||
field(:docsFolderPath) { |r| asset_path(r, "docs") }
|
||||
field(:assets) do |r|
|
||||
assets_of(r).map { |a| { kind: a.kind, path: a.path.gsub(file_path_from, FILE_PATH_TO) } }
|
||||
end
|
||||
field(:downloadCount) do |r, opts|
|
||||
counts = opts[:download_counts]
|
||||
counts ? counts.fetch(r.id, 0) : r.downloads.count
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
module WarpEngine
|
||||
class SoftwareDetailSerializer < Blueprinter::Base
|
||||
field(:software) { |sw, _| SoftwareSerializer.render_as_hash(sw) }
|
||||
field(:releases) { |_, opts| ReleaseSerializer.render_as_hash(opts[:releases], download_counts: opts[:download_counts]) }
|
||||
field(:latestRelease) { |_, opts| opts[:latest] ? ReleaseSerializer.render_as_hash(opts[:latest], download_counts: opts[:download_counts]) : nil }
|
||||
field(:webPlayableRelease) { |_, opts| opts[:web_playable] ? ReleaseSerializer.render_as_hash(opts[:web_playable], download_counts: opts[:download_counts]) : nil }
|
||||
field(:totalDownloads) { |_, opts| opts[:total_downloads] || 0 }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
module WarpEngine
|
||||
class SoftwareSerializer < Blueprinter::Base
|
||||
include TimestampFields
|
||||
|
||||
field(:id) { |sw| sw.id }
|
||||
field(:createdAt) { |sw| sw.created_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:updatedAt) { |sw| sw.updated_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
|
||||
field(:deletedAt) { |sw| sw.deleted_at&.utc&.strftime(TS_FORMAT) }
|
||||
field :name
|
||||
field :title
|
||||
field :author
|
||||
field(:desc) { |sw| sw.desc.to_s }
|
||||
field(:story) { |sw| sw.story.to_s }
|
||||
field(:license) { |sw| sw.license.to_s }
|
||||
field :platform
|
||||
field :status
|
||||
field(:highlighted) { |sw| sw.highlighted ? true : false }
|
||||
field(:externalLinks) { |sw| ExternalLinkSerializer.render_as_hash(sw.external_links) }
|
||||
field(:platformLinks) { |sw| PlatformLinkSerializer.render_as_hash(WarpEngine::PlatformLink.for_platform(sw.platform)) }
|
||||
field(:imageUrl) { |sw|
|
||||
si = sw.software_images.detect(&:is_default?) || sw.software_images.first
|
||||
si ? "/api/image/#{si.image_id}" : nil
|
||||
}
|
||||
field(:images) { |sw|
|
||||
sw.software_images.map { |si|
|
||||
{ url: "/api/image/#{si.image_id}", isDefault: si.is_default?, position: si.position }
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user