From ae01e85c8cf63991bd8e149805827fce5e22b565 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Thu, 15 Jun 2023 23:58:06 +0200 Subject: [PATCH] make agents routes work for /Agent and /agent --- controllers/agents_controller.rb | 51 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/controllers/agents_controller.rb b/controllers/agents_controller.rb index d547441c..f8ab687a 100644 --- a/controllers/agents_controller.rb +++ b/controllers/agents_controller.rb @@ -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) @@ -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 \ No newline at end of file