Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 22 additions & 3 deletions app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ def index
code: event.code,
name: event.name,
description: event.description.body ? event.description.body.to_html : "",
address: event.address,
address: { name: event.event_place.name,
street: event.event_place.street,
number: event.event_place.number,
neighborhood: event.event_place.neighborhood,
city: event.event_place.city,
zip_code: event.event_place.zip_code,
state: event.event_place.state },
logo_url: event.logo.attached? ? url_for(event.logo) : nil,
banner_url: event.banner.attached? ? url_for(event.banner) : nil,
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.event_place_recommendations.map do |recommendation|
{
name: recommendation.name,
full_address: recommendation.full_address,
phone: recommendation.phone
}
end
}
end
}
Expand All @@ -31,7 +44,13 @@ def show
code: event.code,
name: event.name,
description: event.description.body ? event.description.body.to_html : "",
address: event.address,
address: { name: event.event_place.name,
street: event.event_place.street,
number: event.event_place.number,
neighborhood: event.event_place.neighborhood,
city: event.event_place.city,
zip_code: event.event_place.zip_code,
state: event.event_place.state },
logo_url: event.logo.attached? ? url_for(event.logo) : nil,
banner_url: event.banner.attached? ? url_for(event.banner) : nil,
participants_limit: event.participants_limit,
Expand Down
16 changes: 14 additions & 2 deletions app/controllers/api/v1/speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def events
name: event.name,
event_type: event.event_type,
description: event.description.body ? event.description.body.to_html : "",
address: event.address,
address: { name: event.event_place.name,
street: event.event_place.street,
number: event.event_place.number,
neighborhood: event.event_place.neighborhood,
city: event.event_place.city,
zip_code: event.event_place.zip_code,
state: event.event_place.state },
logo_url: event.logo.attached? ? url_for(event.logo) : nil,
banner_url: event.banner.attached? ? url_for(event.banner) : nil,
participants_limit: event.participants_limit,
Expand All @@ -44,7 +50,13 @@ def event
name: event.name,
event_type: event.event_type,
description: event.description.body ? event.description.body.to_html : "",
address: event.address,
address: { name: event.event_place.name,
street: event.event_place.street,
number: event.event_place.number,
neighborhood: event.event_place.neighborhood,
city: event.event_place.city,
zip_code: event.event_place.zip_code,
state: event.event_place.state },
logo_url: event.logo.attached? ? url_for(event.logo) : nil,
banner_url: event.banner.attached? ? url_for(event.banner) : nil,
participants_limit: event.participants_limit,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def history
private

def event_params
params.require(:event).permit(:name, :address, :event_type, :participants_limit, :url, :logo, :banner, :description, :start_date, :end_date, category_ids: [])
params.require(:event).permit(:name, :event_type, :participants_limit, :url, :logo, :banner, :description, :start_date, :end_date, :event_place_id, category_ids: [])
end

def authorize_event_access
Expand Down
7 changes: 6 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Event < ApplicationRecord
default_scope -> { kept }

belongs_to :user
belongs_to :event_place

has_one_attached :logo
has_one_attached :banner
Expand All @@ -19,13 +20,13 @@ class Event < ApplicationRecord

validates :code, uniqueness: true
validates :name, :participants_limit, :url, :status, :start_date, :end_date, presence: true
validates :address, presence: true, if: -> { inperson? || hybrid? }
validates :logo, content_type: { in: [ "image/png", "image/jpeg", "image/jpg" ], message: "deve ser uma imagem do tipo PNG, JPG ou JPEG" }
validates :banner, content_type: { in: [ "image/png", "image/jpeg", "image/jpg" ], message: "deve ser uma imagem do tipo PNG, JPG ou JPEG" }
validates :start_date, :end_date, comparison: { greater_than: Time.now, message: "não pode ser depois da data atual" }
validates :start_date, comparison: { less_than: :end_date, message: "não pode ser depois da data de fim", if: -> { end_date.present? } }
validate :participants_limit_for_unverified_user
validate :should_have_at_least_one_category
# validate :should_have_an_event_place

after_create :set_schedules

Expand All @@ -50,6 +51,10 @@ def should_have_at_least_one_category
errors.add(:categories, "deve ter ao menos uma categoria") if categories.empty?
end

# def should_have_an_event_place
# errors.add(:event_place, "deve ter um local de evento") if self.inperson? || self.hybrid? && event_place.nil?
# end

def generate_code
loop do
self.code = SecureRandom.alphanumeric(8).upcase
Expand Down
1 change: 1 addition & 0 deletions app/models/event_place.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class EventPlace < ApplicationRecord
belongs_to :user
has_many :events

has_one_attached :photo

Expand Down
20 changes: 10 additions & 10 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@
<% end %>
</div>

<div class="input_container" data-event-target="address">
<%= f.label :address, class: 'input_label' %>
<%= f.text_field :address, class: "input"%>
<% if event.errors[:address].any? %>
<% event.errors.full_messages_for(:address).each do |e| %>
<span class="form_error"><%= e %></span>
<% end %>
<% end %>
</div>

<div class="input_container">
<%= f.label :participants_limit, class: 'input_label' %>
<%= f.number_field :participants_limit,class: "input"%>
Expand Down Expand Up @@ -95,6 +85,16 @@
<% end %>
</div>

<div class="input_container">
<%= f.label :event_place_id, "Local do Evento", class: 'input_label' %>
<%= f.collection_select :event_place_id, current_user.event_places.all, :id, :name, { prompt: 'Escolha um local de evento' }, { class: 'input' } %>
<% if event.errors[:event_places].any? %>
<% event.errors.full_messages_for(:event_places).each do |e| %>
<span class='form_error'><%= e %></span>
<% end %>
<% end %>
</div>

<div class="input_container">
<%= f.label :categories, class: 'input_label' %>
<%= f.collection_checkboxes(:category_ids, Category.all, :id, :name) do |b| %>
Expand Down
10 changes: 8 additions & 2 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@
<%= @event.url %>
</p>

<% if @event.address %>
<% if @event.event_place %>
<p class="font-light text-textSecondary">
<span class="font-bold text-textPrimary">Endereço:</span>
<%= @event.address %>
<%= @event.event_place.name %>
<%= @event.event_place.street %>
<%= @event.event_place.number %>
<%= @event.event_place.neighborhood %>
<%= @event.event_place.city %>
<%= @event.event_place.zip_code %>
<%= @event.event_place.state %>
</p>
<% end %>
</article>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250207190453_remove_address_from_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveAddressFromEvent < ActiveRecord::Migration[8.0]
def change
remove_column :events, :address, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20250207190710_add_event_place_ref_to_event_.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEventPlaceRefToEvent < ActiveRecord::Migration[8.0]
def change
add_reference :events, :event_place, foreign_key: true
end
end
6 changes: 4 additions & 2 deletions db/schema.rb

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

18 changes: 12 additions & 6 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
ruby_event = FactoryBot.create(:event,
name: 'Conferencia Ruby',
event_type: :online,
address: 'Sem endereço',
participants_limit: 25,
url: 'confruby.com.br',
status: :draft,
Expand All @@ -57,28 +56,30 @@
ruby_event.banner.attach(io: File.open(Rails.root.join('spec/support/images/banner_ruby.png')), filename: 'banner_ruby.png')

puts 'Criando evento CONFERENCIA JAVASCRIPT...'

javascript_event = FactoryBot.create(:event,
name: 'Conferencia JS',
event_type: :inperson,
address: 'Rua dos Computadores, 125',
participants_limit: 30,
url: 'confjs.com.br',
status: :published,
user: joao_user,
categories: [ javascript_category ],
start_date: 2.weeks.from_now,
end_date: 3.weeks.from_now,
description: 'Um evento maneiro de Java escrito'
description: 'Um evento maneiro de Java escrito',
)

javascript_event.logo.attach(io: File.open(Rails.root.join('spec/support/images/javascript.png')), filename: 'javascript.png')
sleep(5)
javascript_event.banner.attach(io: File.open(Rails.root.join('spec/support/images/banner_javascript.png')), filename: 'banner_javascript.png')


puts 'Criando evento TROPICAL ON RAILS...'

tropical_event = FactoryBot.create(:event,
name: 'Tropical on Rails 2025',
event_type: :hybrid,
address: 'Auditório Hotel Pullman - Vila Olímpia, São Paulo - SP',
participants_limit: 30,
url: 'www.evento.com',
status: :published,
Expand All @@ -88,15 +89,18 @@
end_date: 1.weeks.from_now,
description: "O Tropical on Rails 2025 é a Conferência Latam de Rails e tem como objetivo fortalecer a comunidade de Rails da América Latina para que ela continue sendo uma parte integral do presente e do futuro do Ruby on Rails. O que antes era bom como Tropical.rb agora ficou melhor ainda sendo Tropical On Rails, nossa estrutura também cresceu e nessa edição vamos ter 700 com palestrantes incríveis estarão no nosso palco: Xavier Noria, Chris Oliver, Rosa Gutiérrez, Irina Nazarova, Rafael França, Vinicius Stock e muitos outros."
)


tropical_event.logo.attach(io: File.open(Rails.root.join('spec/support/images/logo.jpg')), filename: 'logo.jpg')
sleep(5)
tropical_event.banner.attach(io: File.open(Rails.root.join('spec/support/images/banner.png')), filename: 'banner.png')


puts 'Criando evento RUBY SUMMIT BRASIL 2025...'

ruby_summit_event = FactoryBot.create(:event,
name: 'Ruby Summit Brasil 2025',
event_type: :inperson,
address: 'Teatro Renaissance - São Paulo, SP',
participants_limit: 30,
url: 'www.rubysummitbr.com',
status: :published,
Expand All @@ -106,14 +110,16 @@
end_date: (1.month.from_now + 1.day),
description: "O Ruby Summit Brasil 2025 reúne a comunidade Ruby brasileira em um evento repleto de palestras, painéis e workshops com os melhores especialistas do mercado. Com keynotes internacionais e espaço para networking, é a oportunidade ideal para aprender e compartilhar conhecimento sobre Ruby e suas tecnologias relacionadas."
)


ruby_summit_event.logo.attach(io: File.open(Rails.root.join('spec/support/images/ruby-summit-brasil.png')), filename: 'ruby-summit-brasil.png')
sleep(5)

puts 'Criando evento FULL STACK CONF 2025...'

full_stack_conf_event = FactoryBot.create(:event,
name: 'Full Stack Conf 2025',
event_type: :online,
address: nil,
participants_limit: 30,
url: 'www.fullstackconf.com',
status: :published,
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/event_places.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryBot.define do
factory :event_place do
name { "Arena de Grêmio" }
sequence(:name) { |n| "Arena de Grêmio #{n}" }
street { "Av. Padre Leopoldo Brentano" }
number { "110" }
sequence(:number) { |n| "#{110 + n}" }
neighborhood { "Farrapos" }
city { "Porto Alegre" }
zip_code { "90250590" }
Expand Down
3 changes: 1 addition & 2 deletions spec/factories/events.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
FactoryBot.define do
factory :event do
name { "Lollapalooza" }
event_type { :inperson }
address { "Av dos Bancos" }
participants_limit { 30 }
url { "http://Lollapalooza.com" }
association :user
start_date { (Time.now + 4.weeks) }
end_date { (Time.now + 5.weeks) }
banner { File.open(Rails.root.join('spec/support/images/no_banner.png'), filename: 'no_banner.png') }
logo { File.open(Rails.root.join('spec/support/images/no_logo.png'), filename: 'no_logo.png') }
event_place { create :event_place }

categories { [ create(:category) ] }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory(:user) do
email { 'alice@email.com' }
sequence(:email) { |n| "user#{n}@example.com" }
password { 'password123' }
password_confirmation { 'password123' }
name { 'Alice' }
Expand Down
8 changes: 4 additions & 4 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
end

it 'falso quando endereço não está preenchido' do
event = FactoryBot.build(:event, address: '')
event = FactoryBot.build(:event, event_place: nil)
event.valid?

expect(event.errors[:address]).to include 'não pode ficar em branco'
expect(event.errors[:event_place]).to include 'é obrigatório(a)'
expect(event).not_to be_valid
end

Expand Down Expand Up @@ -109,10 +109,10 @@
end

it 'endereço deve ser obrigatório somente quando o evento for presencial ou hibrido' do
event = FactoryBot.build(:event, event_type: :online, address: '')
event = FactoryBot.build(:event, event_type: :online)
event.valid?

expect(event.errors).not_to include(:address)
expect(event.errors).not_to include(:event_place)
expect(event).to be_valid
end

Expand Down
Loading