-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,658 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ruby-3.3.0 | ||
3.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby 3.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::API | ||
private def pagination_params | ||
params.permit(:limit, :offset) | ||
end | ||
private def limit | ||
pagination_params[:limit] || 2 | ||
end | ||
|
||
private def offset | ||
pagination_params[:offset] || 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Drivers | ||
class SelectableRidesController < ApplicationController | ||
def index | ||
rides = Rides::Commands::RankRides.call(driver:)[offset, limit] | ||
opts = { include: %i[from_address to_address] } | ||
render json: RidePojoSerializer.new(rides, opts) | ||
end | ||
|
||
private def driver | ||
@driver ||= Driver.find(ride_params[:driver_id]) | ||
end | ||
|
||
private def ride_params | ||
params.permit(:driver_id, :limit, :offset) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class DriversController < ApplicationController | ||
def index | ||
drivers = Driver.limit(limit).offset(offset) | ||
render json: DriverSerializer.new(drivers, is_collection: true) | ||
end | ||
|
||
private def pagination_params | ||
params.permit(:limit, :offset) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddressSerializer | ||
include JSONAPI::Serializer | ||
set_type :address | ||
attributes :id, :line_1, :line_2, :city, :state, :zip_code, :full_address | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class DriverSerializer | ||
include JSONAPI::Serializer | ||
set_type :driver | ||
attributes :id, :full_name | ||
has_one :current_address, serializer: AddressSerializer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class RidePojoSerializer | ||
include JSONAPI::Serializer | ||
extend ActionView::Helpers::DateHelper | ||
extend ActionView::Helpers::NumberHelper | ||
|
||
set_id do |struct, _params| | ||
struct.ride_id | ||
end | ||
|
||
set_type "pre-ride" | ||
|
||
attribute :distance do |struct, _params| | ||
number_to_human((struct.distance_meters / 1609.34).round(2), units: :distance) | ||
end | ||
|
||
attribute :duration do |struct, _params| | ||
distance_of_time_in_words(struct.duration.to_f) | ||
end | ||
|
||
attribute :commute_duration do |struct, _params| | ||
distance_of_time_in_words(struct.commute_duration.to_f) | ||
end | ||
|
||
attribute :ride_earnings do |struct, _params| | ||
struct.ride_amount.format | ||
end | ||
|
||
belongs_to :from_address, serializer: AddressSerializer | ||
belongs_to :to_address, serializer: AddressSerializer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,10 @@ | |
|
||
en: | ||
hello: "Hello world" | ||
distance: | ||
centi: | ||
one: "foot" | ||
other: "feet" | ||
unit: | ||
one: "mile" | ||
other: "miles" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddMaxRadiusToDriver < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :drivers, :max_radius, :integer, default: 10 | ||
add_index :drivers, :max_radius | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.