-
Notifications
You must be signed in to change notification settings - Fork 11
feat(api): expose sync status #1635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6150e1e
feat(api): expose sync status
JSONbored 8a4c6ce
fix(api): harden sync status review paths
JSONbored e85a43f
fix(api): address sync status review
JSONbored afcec79
fix(api): tighten sync status review fixes
JSONbored b938e38
fix(api): address sync status review
JSONbored 979dad3
test(api): avoid secret-like sync fixture key
JSONbored e05c8f8
test(api): reuse sync status fixture key
JSONbored 82aca49
fix(api): align sync route helpers
JSONbored 3fa7df3
fix(api): tighten sync status scoping
JSONbored 1188b2d
chore(sync): merge upstream main into sync status API
JSONbored e02fe3a
Merge branch 'main' into codex/feat-api-sync-status
JSONbored 9bc4c7f
fix(api): make sync status schema nullable-compliant
JSONbored File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Api::V1::SyncsController < Api::V1::BaseController | ||
| include Pagy::Backend | ||
|
|
||
| before_action :ensure_read_scope | ||
| before_action :set_sync, only: [ :show ] | ||
|
|
||
| def index | ||
| @per_page = safe_per_page_param | ||
| @pagy, @syncs = pagy( | ||
| family_syncs_query.preload(:syncable, :children).ordered, | ||
| page: safe_page_param, | ||
| limit: @per_page | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| render :index | ||
| end | ||
|
|
||
| def latest | ||
| @sync = family_syncs_query.preload(:syncable, :children).ordered.first | ||
| return render json: { data: nil } unless @sync | ||
|
|
||
| render :show | ||
| end | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| def show | ||
| render :show | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_sync | ||
| raise ActiveRecord::RecordNotFound unless valid_uuid?(params[:id]) | ||
|
|
||
| @sync = family_syncs_query.preload(:syncable, :children).find(params[:id]) | ||
|
JSONbored marked this conversation as resolved.
|
||
| end | ||
|
|
||
| def ensure_read_scope | ||
| authorize_scope!(:read) | ||
| end | ||
|
|
||
| def family_syncs_query | ||
| Sync.for_family(Current.family, resource_owner: Current.user) | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| syncable = sync.syncable | ||
|
|
||
| json.id sync.id | ||
| json.status sync.status | ||
| json.in_progress sync.in_progress? | ||
| json.terminal sync.terminal? | ||
| json.syncable do | ||
| json.type sync.syncable_type | ||
| json.id sync.syncable_id | ||
| json.name syncable&.try(:name) | ||
| end | ||
| json.parent_id sync.parent_id | ||
| json.children_count sync.children.size | ||
| json.window_start_date sync.window_start_date | ||
| json.window_end_date sync.window_end_date | ||
| json.pending_at sync.pending_at | ||
| json.syncing_at sync.syncing_at | ||
| json.completed_at sync.completed_at | ||
| json.failed_at sync.failed_at | ||
| json.error sync.api_error_payload | ||
| json.created_at sync.created_at | ||
| json.updated_at sync.updated_at |
This file contains hidden or 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 | ||
|
|
||
| json.data do | ||
| json.array! @syncs, partial: "api/v1/syncs/sync", as: :sync | ||
| end | ||
|
|
||
| json.meta do | ||
| json.page @pagy.page | ||
| json.per_page @per_page | ||
| json.total_count @pagy.count | ||
| json.total_pages @pagy.pages | ||
| end |
This file contains hidden or 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,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| json.data do | ||
| if @sync | ||
| json.partial! "api/v1/syncs/sync", sync: @sync | ||
| else | ||
| json.nil! | ||
| end | ||
|
JSONbored marked this conversation as resolved.
|
||
| end | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.