Skip to content

Commit

Permalink
Merge pull request #61 from TreinaDev/fix/expor-categoria-de-trabalho…
Browse files Browse the repository at this point in the history
…-por-projeto

Adiciona categorias de trabalho no endpoint de listagem de projetos
  • Loading branch information
adoniranfranceh authored Feb 2, 2024
2 parents 53fae43 + 4568c9f commit a8d1d2e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
20 changes: 18 additions & 2 deletions api_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@ Retorna a lista de todos os projetos cadastradas. (Status: 200):
"id": 1,
"title": "Projeto Master",
"description": "Principal projeto criado",
"category": "Video"
"category": "Video",
"project_job_categories": [
{
"job_category_id": 1
},
{
"job_category_id": 2
}
]
},
{
"id": 2,
"title": "Projeto Website",
"description": "Um site de jogos",
"category": "Programação"
"category": "Programação",
"project_job_categories": [
{
"job_category_id": 1
},
{
"job_category_id": 2
}
]
}
]
```
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module Api
module V1
class ProjectsController < Api::V1::ApiController
def index
response = Project.all.as_json(only: %i[id title description category])
response = Project.all.as_json(
only: %i[id title description category],
include: { project_job_categories: { only: [:job_category_id] } }
)

response = { message: 'Nenhum projeto encontrado.' } if response.empty?

Expand Down
15 changes: 15 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@

ash_project = FactoryBot.create(:project, user: ash, title: 'Pousadaria', category: 'Aplicação WEB')
ash_project2 = FactoryBot.create(:project, user: ash, title: 'Portfoliorr', category: 'Aplicação WEB')
pokemon_project = FactoryBot.create(:project, user: brock, title: 'Líder de Ginásio',
description: 'Me tornar líder do estádio de pedra.')



first_project_job_category = FactoryBot.create(:project_job_category, project: pokemon_project, job_category_id: 1)

second_project_job_category = FactoryBot.create(:project_job_category, project: pokemon_project, job_category_id: 2)

third_project_job_category = FactoryBot.create(:project_job_category, project: encrenca_project, job_category_id: 1)



FactoryBot.create(:task, project: pokemon_project, title:'Pegar um geodude',
Expand Down
10 changes: 8 additions & 2 deletions spec/requests/api/v1/projects_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
context 'GET /api/v1/projects' do
it 'com sucesso' do
project_owner = create(:user)
create(:project, user: project_owner, title: 'Primeiro Projeto',
description: 'Esse é o primeiro projeto', category: 'Site')
project = create(:project, user: project_owner, title: 'Primeiro Projeto',
description: 'Esse é o primeiro projeto', category: 'Site')
create(:project, user: project_owner, title: 'Segundo Projeto',
description: 'Projeto de edição', category: 'Video')

create(:project_job_category, project:, job_category_id: 1)
create(:project_job_category, project:, job_category_id: 2)

get '/api/v1/projects'

expect(response.status).to eq 200
Expand All @@ -19,10 +22,13 @@
expect(json_response[0]['title']).to eq 'Primeiro Projeto'
expect(json_response[0]['description']).to eq 'Esse é o primeiro projeto'
expect(json_response[0]['category']).to eq 'Site'
expect(json_response[0]['project_job_categories'][0]['job_category_id']).to eq 1
expect(json_response[0]['project_job_categories'][1]['job_category_id']).to eq 2
expect(json_response[1]['id']).to eq 2
expect(json_response[1]['title']).to eq 'Segundo Projeto'
expect(json_response[1]['description']).to eq 'Projeto de edição'
expect(json_response[1]['category']).to eq 'Video'
expect(json_response[1]['project_job_categories'].any?).to eq false
end

it 'e não tem nenhum projeto' do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/profiles/user_edit_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
visit edit_profile_path user.profile
click_on 'Pular etapa'

expect(current_path).to eq root_path
expect(page).to have_current_path root_path
end

it 'e já tem informação registrada' do
Expand All @@ -79,7 +79,7 @@
visit edit_profile_path user.profile
click_on 'Voltar'

expect(current_path).to eq profile_path user.profile
expect(page).to have_current_path profile_path user.profile
end
end

Expand Down

0 comments on commit a8d1d2e

Please sign in to comment.