-
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.
[AFA-5] Create API with Restful structure (#6)
* Create API with Restful structure * Fix lint issues * Update pull request template * Upgrade core version
- Loading branch information
1 parent
82a66a9
commit 678b3ed
Showing
14 changed files
with
135 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
> [!CAUTION] | ||
> Topics with :red_circle: are required. The rest are optional and can be removed. | ||
Issue number: resolves # | ||
|
||
## Summary :red_circle: | ||
|
||
## Proposed / Possible solution :red_circle: | ||
|
||
## how to test :policeman: | ||
|
||
Describe in details (preferred step by step). | ||
|
||
## Risks / Impacts :red_circle: | ||
|
||
Inform the risks/impacts that this PR is generating | ||
|
||
### Examples | ||
|
||
- Unavailability in API x/y/z | ||
- Downtime of x seconds in y environment | ||
- None anticipated | ||
|
||
## Requirements for deployment :red_circle: | ||
|
||
Provide the necessary requirements that are needed pre or post deployment. | ||
|
||
### Examples | ||
|
||
- Execute the deployment of changes in project X as a preliminary step before starting this deployment. | ||
- Execute the migrate command before starting the deployment process. | ||
- None anticipated |
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,5 @@ | ||
web: RUBYOPT="-W0" bundle exec rails s | ||
database: postgres | ||
redis: redis-server | ||
mailserver: maildev --hide-extensions STARTTLS | ||
background: bundle exec sidekiq | ||
background: RUBYOPT="-W0" bundle exec sidekiq |
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module V1 | ||
# Main class (Add doc) | ||
class AuctionsController < ApplicationController | ||
def index | ||
auctions = auction_relation.all(params[:page] || 1, params[:per_page] || 25).to_a | ||
|
||
render json: {auctions: auctions}, status: :ok | ||
end | ||
|
||
private | ||
|
||
def auction_relation | ||
AuctionFunCore::Application[:container].relations[:auctions] | ||
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
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,7 @@ | ||
AuctionFunCore::Application[:settings].database_url = ENV.fetch("DATABASE_URL") | ||
AuctionFunCore::Application[:settings].redis_url = ENV.fetch("REDIS_URL") | ||
|
||
# Import locales from gem | ||
I18n.load_path += Dir[Gem.loaded_specs["auction_fun_core"].full_gem_path + "/i18n/**/*.{rb,yml}"] | ||
|
||
AuctionFunCore::Application.finalize! |
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,10 +1,17 @@ | ||
Rails.application.routes.draw do | ||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html | ||
if Rails.env.development? | ||
require "sidekiq/web" | ||
|
||
Sidekiq::Web.use ActionDispatch::Cookies | ||
Sidekiq::Web.use ActionDispatch::Session::CookieStore, key: "_auctionfuncore_session" | ||
mount Sidekiq::Web => "/sidekiq" | ||
end | ||
|
||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. | ||
# Can be used by load balancers and uptime monitors to verify that the app is live. | ||
get "up" => "rails/health#show", :as => :rails_health_check | ||
|
||
# Defines the root path route ("/") | ||
# root "posts#index" | ||
namespace :v1, defaults: {format: :json} do | ||
resources :auctions, only: %i[index] | ||
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe V1::AuctionsController do | ||
describe "Routes", type: :routing do | ||
it { expect(get("/v1/auctions")).to route_to("v1/auctions#index", format: :json) } | ||
end | ||
|
||
describe "GET #index", type: :controller do | ||
context "when auctions are available" do | ||
let!(:auction) { Factory[:auction, :default_running_standard] } | ||
|
||
it "expect return http status ok with auctions" do | ||
get :index | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(response.body).to include(auction.title) | ||
end | ||
end | ||
|
||
context "when there are no auctions available" do | ||
it "expect return http status ok with empty results" do | ||
get :index | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(json_response["auctions"]).to be_blank | ||
end | ||
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
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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
DatabaseCleaner.strategy = :truncation |
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module ControllerHelpers | ||
def json_response | ||
return if response.body.blank? | ||
|
||
JSON.parse(response.body, symbolize_keys: true) | ||
end | ||
end | ||
|
||
RSpec.configure do |c| | ||
c.include ControllerHelpers, type: :controller | ||
end |