Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ def index
participants_limit: event.participants_limit,
event_owner: event.user.name,
start_date: event.start_date,
end_date: event.end_date
end_date: event.end_date,
recommendations: event.event_place_recommendations.map do |recommendation|
{
name: recommendation.name,
full_address: recommendation.full_address,
phone: recommendation.phone
}
end
}
end
}
Expand Down
2 changes: 2 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Event < ApplicationRecord
has_many :categories, through: :event_categories
has_many :schedules
has_many :announcements
has_many :place_recommendations
has_many :event_place_recommendations, through: :place_recommendations

enum :status, [ :draft, :published ]
enum :event_type, [ :inperson, :online, :hybrid ]
Expand Down
2 changes: 2 additions & 0 deletions app/models/event_place_recommendation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class EventPlaceRecommendation < ApplicationRecord
belongs_to :event_place
has_many :place_recommendations, dependent: :destroy
has_many :events, through: :place_recommendations

validates :name, :full_address, presence: true
validates :phone, numericality: true, length: { in: 10..11 }, allow_blank: true
Expand Down
4 changes: 4 additions & 0 deletions app/models/place_recommendation.rb

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que isso não faz sentido. Se não me engano event_place vai ser associado ao evento substituindo o campo address

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, é que essa substituição não estava descrita na issue. Então vou aproveitar esse PR para fazê-la.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PlaceRecommendation < ApplicationRecord
belongs_to :event
belongs_to :event_place_recommendation
end
10 changes: 10 additions & 0 deletions db/migrate/20250206184549_create_place_recommendations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreatePlaceRecommendations < ActiveRecord::Migration[8.0]
def change
create_table :place_recommendations do |t|
t.references :event, null: false, foreign_key: true
t.references :event_place_recommendation, null: false, foreign_key: true

t.timestamps
end
end
end
13 changes: 12 additions & 1 deletion db/schema.rb

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

6 changes: 6 additions & 0 deletions spec/factories/place_recommendation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :place_recommendation do
event { nil }
event_place_recommendation { nil }
end
end
28 changes: 28 additions & 0 deletions spec/requests/api/v1/event_api_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@
expect(response.parsed_body['events'][0]['end_date']).to eq event.end_date.iso8601(3)
expect(response.parsed_body['events'].count).to eq 1
end

it 'e há um local recomendado' do
user = create(:user)

event = build(
:event, name: 'Formação de Churrasqueiros', user: user, status: 'published',
address: 'Rua das Laranjeiras, 123', description: 'Aprenda a fazer churrasco como um profissional', participants_limit: 30,
start_date: (Time.now + 1.day).change(hour: 8, min: 0, sec: 0), end_date: (Time.now + 3.day).change(hour: 18, min: 0, sec: 0))


event.logo.attach(io: File.open('spec/support/images/logo.png'), filename: 'logo.png', content_type: 'img/png')
event.banner.attach(io: File.open('spec/support/images/banner.jpg'), filename: 'banner.png', content_type: 'img/jpg')

event.save

event_place = create(:event_place, user: user)
event_place_recommendation = create(:event_place_recommendation, event_place: event_place)
create(:place_recommendation, event: event, event_place_recommendation: event_place_recommendation)

get '/api/v1/events'

expect(response).to have_http_status :success
expect(response.content_type).to include('application/json')
expect(response.parsed_body['events'][0]['name']).to include(event.name)
expect(response.parsed_body['events'][0]['recommendations'][0]['name']).to include(event_place_recommendation.name)
expect(response.parsed_body['events'][0]['recommendations'][0]['full_address']).to include(event_place_recommendation.full_address)
expect(response.parsed_body['events'][0]['recommendations'][0]['phone']).to include(event_place_recommendation.phone)
end
end

context 'Usuário ve detalhes' do
Expand Down