Skip to content

Commit

Permalink
Merge pull request #130 from TreinaDev/feature/configuracoes-de-aplic…
Browse files Browse the repository at this point in the history
…acao

Configurações de aplicação
  • Loading branch information
oLucasAguilar authored Feb 16, 2024
2 parents e9324d7 + 0dbd194 commit 637a31c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn watch:css
worker: bundle exec rake solid_queue:start
9 changes: 5 additions & 4 deletions app/models/job_category.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
class JobCategory
attr_accessor :id, :name, :description

URL = Rails.configuration.portfoliorrr_api[:base_url] +
Rails.configuration.portfoliorrr_api[:job_endpoint]

def initialize(id:, name:, description: nil)
@id = id
@name = name
@description = description
end

def self.all
url = 'http://localhost:4000/api/v1/job_categories'
fetch_job_categories(url)
fetch_job_categories(URL)
end

def self.fetch_job_categories_by_project(project_job_categories)
Expand All @@ -22,8 +24,7 @@ def self.fetch_job_categories_by_project(project_job_categories)
end

def self.find(id)
url = "http://localhost:4000/api/v1/job_categories/#{id}"
response = Faraday.get(url)
response = Faraday.get(URL + id.to_s)

return {} unless response.success?

Expand Down
14 changes: 8 additions & 6 deletions app/models/portfoliorrr_profile.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
class PortfoliorrrProfile
attr_accessor :id, :name, :email, :job_categories, :cover_letter

URL = Rails.configuration.portfoliorrr_api[:base_url] +
Rails.configuration.portfoliorrr_api[:profiles_endpoint]
SEARCH_URL = Rails.configuration.portfoliorrr_api[:base_url] +
Rails.configuration.portfoliorrr_api[:profiles_search_endpoint]

def initialize(id:, name:, job_categories:)
@id = id
@name = name
@job_categories = job_categories
end

def self.all
url = 'http://localhost:4000/api/v1/profiles'
fetch_portfoliorrr_profiles(url)
fetch_portfoliorrr_profiles(URL)
end

def self.search(query)
url = "http://localhost:4000/api/v1/profiles?search=#{CGI.escape query}"
fetch_portfoliorrr_profiles(url)
fetch_portfoliorrr_profiles(SEARCH_URL + CGI.escape(query))
end

def self.find(id)
url = "http://localhost:4000/api/v1/profiles/#{id}"
response = Faraday.get(url)
response = Faraday.get(URL + id.to_s)

return {} unless response.success?

Expand Down
10 changes: 5 additions & 5 deletions app/services/invitation_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module InvitationService
PORTFOLIORRR_BASE_URL = 'http://localhost:4000'.freeze
PORTFOLIORRR_INVITATION_URL = '/api/v1/invitations/'.freeze
URL = Rails.configuration.portfoliorrr_api[:base_url] +
Rails.configuration.portfoliorrr_api[:invitation_endpoint]

class PortfoliorrrPost
def self.send(invitation)
@invitation = invitation
Expand Down Expand Up @@ -31,9 +32,8 @@ def set_json

def post_connection
headers = { 'Content-Type': 'application/json' }
url = "#{PORTFOLIORRR_BASE_URL}#{PORTFOLIORRR_INVITATION_URL}"

@response = Faraday.post(url, set_json.to_json, headers)
@response = Faraday.post(URL, set_json.to_json, headers)
end

def post_success
Expand All @@ -53,9 +53,9 @@ def post_fail
class PortfoliorrrPatch
def self.send(invitation, status)
headers = { 'Content-Type': 'application/json' }
url = "#{PORTFOLIORRR_BASE_URL}#{PORTFOLIORRR_INVITATION_URL}#{invitation.portfoliorrr_invitation_id}"
json = { status: }

url = URL + invitation.id.to_s
response = Faraday.patch(url, json.to_json, headers)

return true if response.success?
Expand Down
6 changes: 3 additions & 3 deletions app/services/proposal_service.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module ProposalService
PORTFOLIORRR_BASE_URL = 'http://localhost:4000'.freeze
PORTFOLIORRR_PROPOSAL_URL = '/api/v1/invitation_request/'.freeze
URL = Rails.configuration.portfoliorrr_api[:base_url] +
Rails.configuration.portfoliorrr_api[:proposal_endpoint]

class Decline
def self.send(proposal)
return unless proposal.processing?

url = PORTFOLIORRR_BASE_URL + PORTFOLIORRR_PROPOSAL_URL + proposal.portfoliorrr_proposal_id.to_s
url = URL + proposal.portfoliorrr_proposal_id.to_s
header = { 'Content-Type': 'application/json' }

return proposal.declined! if Faraday.patch(url, header).success?
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ class Application < Rails::Application

# Don't generate system test files.
config.generators.system_tests = nil

# Configuration for the Portfolio API endpoint
config.portfoliorrr_api = config_for(:portfoliorrr_api)
end
end
7 changes: 7 additions & 0 deletions config/portfoliorrr_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
shared:
base_url: http://localhost:4000
invitation_endpoint: /api/v1/invitations/
proposal_endpoint: /api/v1/invitation_request/
job_endpoint: /api/v1/job_categories/
profiles_endpoint: /api/v1/profiles/
profiles_search_endpoint: "/api/v1/profiles?search="
8 changes: 4 additions & 4 deletions spec/models/job_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe JobCategory, type: :model do
context '#all' do
it 'API retorna todos os resultados' do
url = 'http://localhost:4000/api/v1/job_categories'
url = 'http://localhost:4000/api/v1/job_categories/'
json = File.read(Rails.root.join('spec/support/json/job_categories.json'))
fake_response = double('faraday_response', status: 200, body: json, success?: true)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)
Expand All @@ -18,7 +18,7 @@
end

it 'API retorna vazio' do
url = 'http://localhost:4000/api/v1/job_categories'
url = 'http://localhost:4000/api/v1/job_categories/'
fake_response = double('faraday_response', status: 200, body: '{ "data": [] }', success?: true)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)

Expand All @@ -29,7 +29,7 @@
end

it 'API retorna erro interno' do
url = 'http://localhost:4000/api/v1/job_categories'
url = 'http://localhost:4000/api/v1/job_categories/'
fake_response = double('faraday_response', status: 500, body: '{ "error": ["Erro interno"] }', success?: false)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)

Expand All @@ -40,7 +40,7 @@
end

it 'e não consegue se conectar na API' do
url = 'http://localhost:4000/api/v1/job_categories'
url = 'http://localhost:4000/api/v1/job_categories/'
allow(Faraday).to receive(:get).with(url).and_raise(Faraday::ConnectionFailed)

job_categories = JobCategory.all
Expand Down
8 changes: 4 additions & 4 deletions spec/models/portfoliorrr_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe PortfoliorrrProfile, type: :model do
context '#all' do
it 'API retorna todos os resultados' do
url = 'http://localhost:4000/api/v1/profiles'
url = 'http://localhost:4000/api/v1/profiles/'
json = File.read(Rails.root.join('spec/support/json/portfoliorrr_profiles_data.json'))
fake_response = double('faraday_response', status: 200, body: json, success?: true)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)
Expand All @@ -20,7 +20,7 @@
end

it 'API retorna vazio' do
url = 'http://localhost:4000/api/v1/profiles'
url = 'http://localhost:4000/api/v1/profiles/'
fake_response = double('faraday_response', status: 200, body: '{ "data": [] }', success?: true)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)

Expand All @@ -31,7 +31,7 @@
end

it 'API retorna erro interno' do
url = 'http://localhost:4000/api/v1/profiles'
url = 'http://localhost:4000/api/v1/profiles/'
fake_response = double('faraday_response', status: 500, body: '{ "error": ["Erro interno"] }', success?: false)
allow(Faraday).to receive(:get).with(url).and_return(fake_response)

Expand All @@ -42,7 +42,7 @@
end

it 'e não consegue se conectar na API' do
url = 'http://localhost:4000/api/v1/profiles'
url = 'http://localhost:4000/api/v1/profiles/'
allow(Faraday).to receive(:get).with(url).and_raise(Faraday::ConnectionFailed)

portfliorrr_profiles = PortfoliorrrProfile.all
Expand Down

0 comments on commit 637a31c

Please sign in to comment.