Skip to content

Commit

Permalink
auction api for mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Oct 13, 2023
1 parent f707f93 commit fb7a1c4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 71 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ gem 'pagy', '~> 6.0'
gem 'faker'

gem 'noticed', '~> 1.6'
gem 'devise-jwt'
gem 'jsonapi-serializer'
21 changes: 21 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,21 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-jwt (0.11.0)
devise (~> 4.0)
warden-jwt_auth (~> 0.8)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dry-auto_inject (1.0.1)
dry-core (~> 1.0)
zeitwerk (~> 2.6)
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
erubi (1.12.0)
faker (3.2.0)
i18n (>= 1.8.11, < 2)
Expand Down Expand Up @@ -186,6 +198,8 @@ GEM
bindata
faraday (~> 2.0)
faraday-follow_redirects
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
jwt (2.7.1)
language_server-protocol (3.17.0.3)
listen (3.8.0)
Expand Down Expand Up @@ -405,6 +419,11 @@ GEM
rexml (>= 3.2, < 4.0)
warden (1.2.9)
rack (>= 2.0.9)
warden-jwt_auth (0.8.0)
dry-auto_inject (>= 0.8, < 2)
dry-configurable (>= 0.13, < 2)
jwt (~> 2.1)
warden (~> 1.2)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -449,12 +468,14 @@ DEPENDENCIES
delayed_job (~> 4.1.0)
delayed_job_active_record
devise
devise-jwt
directo!
faker
faraday
hotwire-rails (~> 0.1.3)
i18n-debug
jbuilder (~> 2.11)
jsonapi-serializer
jwt
listen (>= 3.0.5, < 3.9)
lograge
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module Auth
class SessionsController < Devise::SessionsController
include InvalidUserDataHelper
after_action :set_invalid_data_flag_in_session, only: [:create]

skip_before_action :verify_authenticity_token
respond_to :html, :json

def create
super
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class OffersController < ApplicationController
before_action :authorize_phone_confirmation
before_action :authorize_offer_for_user, except: %i[new index create]

respond_to :html, :json

include RecaptchaValidatable
recaptcha_action 'offer'

Expand Down Expand Up @@ -49,6 +51,11 @@ def index
.order('auctions.ends_at DESC')

@pagy, @offers = pagy(offers, items: params[:per_page] ||= 15)

respond_to do |format|
format.html
format.json { render json: @offers.as_json(include: [:auction, :billing_profile]) }
end
end

# GET /offers/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b
Expand Down
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class User < ApplicationRecord
include Bannable
include Devise::JWT::RevocationStrategies::JTIMatcher

PARTICIPANT_ROLE = 'participant'.freeze
ADMINISTATOR_ROLE = 'administrator'.freeze
ROLES = %w[administrator participant].freeze
Expand All @@ -10,7 +12,7 @@ class User < ApplicationRecord
TARA_PROVIDER = 'tara'.freeze

devise :database_authenticatable, :recoverable, :rememberable, :validatable, :confirmable,
:timeoutable
:timeoutable, :jwt_authenticatable, jwt_revocation_strategy: self

alias_attribute :country_code, :alpha_two_country_code

Expand Down
2 changes: 2 additions & 0 deletions config/customization.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ default: &default
vapid_public: "BGgFbsalgk-emt7f0f279JsxF15NOfEJKQ-7w04FmXseeWt4pRvCaD7EMl6PqS-BHrwO3QWsPUOGkAjNWNBOVLY="
vapid_private: "2xl1lvaQARjFHRCKrPo2B-MbTAc1IZ3UrfugDh6cJiE="

jwt_secret: ''

mailer:
# Host to which links from emails should redirect to
host: 'https://auction.example.test'
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def skip_format?

config.navigational_formats = ['*/*', :html, :turbo_stream]

config.jwt do |jwt|
jwt.secret = AuctionCenter::Application.config.customization[:jwt_secret]
jwt.dispatch_requests = [ ['POST', %r{^/login$}] ]
jwt.revocation_requests = [ ['DELETE', %r{^/logout$}] ]
jwt.expiration_time = 30.minutes.to_i
end

config.warden do |manager|
manager.failure_app = TurboFailureApp
# manager.intercept_401 = false
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20231013110924_add_jti_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddJtiToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :jti, :string
add_index :users, :jti, unique: true
end
end
86 changes: 16 additions & 70 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -912,38 +912,6 @@ CREATE SEQUENCE public.auctions_id_seq
ALTER SEQUENCE public.auctions_id_seq OWNED BY public.auctions.id;


--
-- Name: auto_bids; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.auto_bids (
id bigint NOT NULL,
wishlist_item_id bigint NOT NULL,
cents integer NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: auto_bids_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.auto_bids_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: auto_bids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.auto_bids_id_seq OWNED BY public.auto_bids.id;


--
-- Name: autobiders; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -953,9 +921,10 @@ CREATE TABLE public.autobiders (
user_id bigint,
domain_name character varying,
cents integer,
uuid uuid DEFAULT public.gen_random_uuid(),
uuid uuid DEFAULT gen_random_uuid(),
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
updated_at timestamp(6) without time zone NOT NULL,
enable boolean DEFAULT false
);


Expand Down Expand Up @@ -1586,7 +1555,7 @@ CREATE TABLE public.users (
uid character varying,
updated_by character varying,
daily_summary boolean DEFAULT false NOT NULL,
discarded_at timestamp without time zone,
jti character varying,
CONSTRAINT users_roles_are_known CHECK ((roles <@ ARRAY['participant'::character varying, 'administrator'::character varying]))
);

Expand Down Expand Up @@ -1770,13 +1739,6 @@ ALTER TABLE ONLY audit.wishlist_items ALTER COLUMN id SET DEFAULT nextval('audit
ALTER TABLE ONLY public.auctions ALTER COLUMN id SET DEFAULT nextval('public.auctions_id_seq'::regclass);


--
-- Name: auto_bids id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids ALTER COLUMN id SET DEFAULT nextval('public.auto_bids_id_seq'::regclass);


--
-- Name: autobiders id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2078,14 +2040,6 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);


--
-- Name: auto_bids auto_bids_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids
ADD CONSTRAINT auto_bids_pkey PRIMARY KEY (id);


--
-- Name: autobiders autobiders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2442,13 +2396,6 @@ CREATE UNIQUE INDEX index_auctions_on_remote_id ON public.auctions USING btree (
CREATE UNIQUE INDEX index_auctions_on_uuid ON public.auctions USING btree (uuid);


--
-- Name: index_auto_bids_on_wishlist_item_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_auto_bids_on_wishlist_item_id ON public.auto_bids USING btree (wishlist_item_id);


--
-- Name: index_autobiders_on_domain_name; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2729,6 +2676,13 @@ CREATE UNIQUE INDEX index_users_on_confirmation_token ON public.users USING btre
CREATE UNIQUE INDEX index_users_on_email ON public.users USING btree (email);


--
-- Name: index_users_on_jti; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX index_users_on_jti ON public.users USING btree (jti);


--
-- Name: index_users_on_provider_and_uid; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2770,6 +2724,7 @@ CREATE INDEX index_wishlist_items_on_domain_name ON public.wishlist_items USING

CREATE UNIQUE INDEX users_by_identity_code_and_country ON public.users USING btree (alpha_two_country_code, identity_code) WHERE ((alpha_two_country_code)::text = 'EE'::text);


--
-- Name: auctions process_auction_audit; Type: TRIGGER; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2886,14 +2841,6 @@ ALTER TABLE ONLY public.autobiders
ADD CONSTRAINT fk_rails_3d4f798ed7 FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: auto_bids fk_rails_473d19add3; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids
ADD CONSTRAINT fk_rails_473d19add3 FOREIGN KEY (wishlist_item_id) REFERENCES public.wishlist_items(id);


--
-- Name: wishlist_items fk_rails_5c10acf6bc; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3087,14 +3034,11 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191025092912'),
('20191028092316'),
('20191121162323'),
('20191129102035'),
('20191206123023'),
('20191209073454'),
('20191209083000'),
('20191209085222'),
('20191213082941'),
('20191220131845'),
('20200109093043'),
('20200110135003'),
('20200115145246'),
('20200205092158'),
Expand All @@ -3106,7 +3050,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220422094307'),
('20220422094556'),
('20220422095751'),
('20220422121056'),
('20220425103701'),
('20220426082102'),
('20220527064738'),
Expand All @@ -3125,8 +3068,11 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230419114412'),
('20230607092953'),
('20230705192353'),
('20230721102651'),
('20230925130405'),
('20230927114150'),
('20231006095158');
('20231002090548'),
('20231006095158'),
('20231013110924');


0 comments on commit fb7a1c4

Please sign in to comment.