-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* preload dataset * update to sql context * Create preload dataset and implement logic * Migrations * Revert migrations * schema * Update sample program file with ojt_app_type column * Revert "Update sample program file with ojt_app_type column" This reverts commit 27ed455. * Implement preload datasets * Update enriched id * Refactor * Add period * Remove period * revert Gemfile.lock * linting * Update specs --------- Co-authored-by: Vanson Samuel <[email protected]>
- Loading branch information
1 parent
3e7d40b
commit 5bac218
Showing
19 changed files
with
171 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module V1 | ||
class LcpeBaseController < ApiController | ||
class PreloadVersionStaleError < StandardError; end | ||
|
||
rescue_from PreloadVersionStaleError, with: :version_invalid | ||
|
||
private | ||
|
||
def validate_preload_version | ||
preload_version = params[:id].split('@').last | ||
raise PreloadVersionStaleError unless preload_version == fresh_preload.id.to_s | ||
end | ||
|
||
def preload_dataset | ||
return if bypass_versioning? | ||
|
||
set_etag(fresh_preload.id.to_s) | ||
JSON.parse(fresh_preload.body) | ||
end | ||
|
||
def fresh_preload | ||
@fresh_preload ||= ::Lcpe::PreloadDataset.fresh(lcpe_type) | ||
end | ||
|
||
def lcpe_type | ||
"Lcpe::#{controller_name.singularize.titleize}" | ||
end | ||
|
||
def set_etag(preload_version) | ||
response.set_header('ETag', preload_version) | ||
end | ||
|
||
# If additional filter params present, bypass versioning | ||
def bypass_versioning? | ||
scrubbed_params.present? | ||
end | ||
|
||
def scrubbed_params | ||
params.except(:format, :controller, :action, controller_name.singularize.to_sym) | ||
end | ||
|
||
def version_invalid | ||
render json: { error: 'Version invalid' }, status: :conflict | ||
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
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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class Lcpe::PreloadDataset < ApplicationRecord | ||
# ['Lcpe::Lac', 'Lcpe::Exam'] | ||
LCPE_TYPES = Lcpe::Feed.normalized_klasses.freeze | ||
|
||
validates :subject_class, presence: true, inclusion: { in: LCPE_TYPES } | ||
|
||
scope :of_type, ->(lcpe_type) { where(subject_class: lcpe_type).order(created_at: :desc) } | ||
scope :stale, ->(lcpe_type) { of_type(lcpe_type).offset(1) } | ||
|
||
def self.fresh(lcpe_type) | ||
of_type(lcpe_type).first | ||
end | ||
|
||
def self.build(lcpe_type) | ||
# wipe all exepct most recent preload for lcpe type | ||
stale(lcpe_type).destroy_all | ||
create(subject_class: lcpe_type).tap do |preload| | ||
dataset = preload.klass.with_enriched_id | ||
preload.update(body: dataset.to_json) | ||
end | ||
end | ||
|
||
def klass | ||
subject_class.constantize | ||
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :lcpe_preload_dataset, class: 'Lcpe::PreloadDataset' do | ||
body { 'MyText' } | ||
subject_class { 'MyString' } | ||
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
Oops, something went wrong.