Skip to content

Commit

Permalink
make agents routes work for /Agent and /agent
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 15, 2023
1 parent 76db662 commit ae01e85
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions controllers/agents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
class AgentsController < ApplicationController

##
# Ontology agents
get "/ontologies/:acronym/agents" do
end

namespace "/agents" do
def agents_routes
# Display all agents
get do
check_last_modified_collection(LinkedData::Models::Agent)
Expand Down Expand Up @@ -65,27 +60,35 @@ class AgentsController < ApplicationController
agent.delete
halt 204
end
end

private
private
def create_agent
params ||= @params
acronym = params["id"]
agent = nil
agent = LinkedData::Models::Agent.find(acronym).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first if acronym

def create_agent
params ||= @params
acronym = params["id"]
agent = nil
agent = LinkedData::Models::Agent.find(acronym).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first if acronym

if agent.nil?
agent = instance_from_params(LinkedData::Models::Agent, params)
else
error 400, "Agent exists, please use HTTP PATCH to update"
end
if agent.nil?
agent = instance_from_params(LinkedData::Models::Agent, params)
else
error 400, "Agent exists, please use HTTP PATCH to update"
end

if agent.valid?
agent.save
else
error 400, agent.errors
end
reply 201, agent
if agent.valid?
agent.save
else
error 400, agent.errors
end
reply 201, agent
end


namespace "/agents" do
agents_routes
end

namespace "/Agents" do
agents_routes
end
end

0 comments on commit ae01e85

Please sign in to comment.