Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implement MOD-API routes #114

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions controllers/artefacts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class ArtefactsController < ApplicationController

namespace "/artefacts" do
# Get all Semantic Artefacts
get do
check_last_modified_collection(LinkedData::Models::SemanticArtefact)
options = {
also_include_views: params['also_include_views'] ||= false,
includes: LinkedData::Models::SemanticArtefact.goo_attrs_to_load([])
}
artefacts = LinkedData::Models::SemanticArtefact.all_artefacts(options)
reply artefacts
end

# Get one semantic artefact by ID
get "/:artefactID" do
artefact = LinkedData::Models::SemanticArtefact.find(params["artefactID"])
error 404, "You must provide a valid `artefactID` to retrieve an artefact" if artefact.nil?
check_last_modified(artefact)
artefact.bring(*LinkedData::Models::SemanticArtefact.goo_attrs_to_load(includes_param))
reply artefact
end

# Display latest distribution
get "/:artefactID/distributions/latest" do
artefact = LinkedData::Models::SemanticArtefact.find(params["artefactID"])
error 404, "You must provide a valid artefactID to retrieve an artefact" if artefact.nil?
include_status = params["include_status"] && !params["include_status"].empty? ? params["include_status"].to_sym : :any
latest_distribution = artefact.latest_distribution(status: include_status)

if latest_distribution
check_last_modified(latest_distribution)
latest_distribution.bring(*LinkedData::Models::SemanticArtefactDistribution.goo_attrs_to_load(includes_param))
end
reply latest_distribution
end

# Display a distribution
get '/:artefactID/distributions/:distributionID' do
artefact = LinkedData::Models::SemanticArtefact.find(params["artefactID"])
error 422, "Semantic Artefact #{params["artefactID"]} does not exist" unless artefact
check_last_modified_segment(LinkedData::Models::SemanticArtefactDistribution, [params["artefactID"]])
artefact_distribution = artefact.distribution(params["distributionID"])
error 404, "Distribuution with #{params['distributionID']} not found" if artefact_distribution.nil?
artefact_distribution.bring(*LinkedData::Models::SemanticArtefactDistribution.goo_attrs_to_load(includes_param))
reply artefact_distribution
end

# Display a distribution
get '/:artefactID/distributions' do
artefact = LinkedData::Models::SemanticArtefact.find(params["artefactID"])
error 404, "Semantic Artefact #{params["acronym"]} does not exist" unless artefact
check_last_modified_segment(LinkedData::Models::SemanticArtefactDistribution, [params["artefactID"]])
options = {
status: (params["include_status"] || "ANY"),
includes: LinkedData::Models::SemanticArtefactDistribution.goo_attrs_to_load([])
}
distros = artefact.all_distributions(options)
reply distros.sort {|a,b| b.distributionId.to_i <=> a.distributionId.to_i }
end

end

end
Loading