Just few words about backend part of Evendy.ru project.
Nothing special here, I prefered to use some gems my previous post :
In my Gemfile:
...
gem 'active_model_serializers'
gem 'dry-validation'
gem 'dry-transaction'
...
I prefer to use devise with devise-jwt gem for jwt tokens auth.
You can find code samples in my repository .
Heme small part of our app - Events::ApplyCommand class, so we just call command from our EventsController like this:
def apply
run_command ( Events :: ApplyCommand , id: params [ :id ], user: current_user )
end
We use here AllocationService for checking empty slots for selected event add them to roster, and TelegramService to notify our users in special Telegram channel.
class Events::ApplyCommand < BaseCommand
step :check_limit
step :authorize
step :create_visit
def check_limit ( id :, user :)
event = Event . find ( id )
if AllocationService . new ( event , user ). empty_slots?
Right ( event: event , user: user )
else
Left ( error ( I18n . t ( 'errors.events.reached_limit' )))
end
end
def authorize ( event :, user :)
if user . is_banned?
Left ( error ( I18n . t ( 'errors.events.user_banned' )))
else
Right ( event: event , user: user )
end
end
def create_visit ( event :, user :)
visit = Visit . where ( event: event , user: user ). first_or_initialize
tg = TelegramService . new ( event , user )
if visit . persisted?
tg . call ( :no )
visit . destroy
else
tg . call ( :go )
visit . save
end
Right ( visit )
end
end
I think, at the end of this week I’ll add new posts about other parts of our system.
Please enable JavaScript to view the comments powered by Disqus.