-
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.
Add an endpoint to fetch organization workers
- Loading branch information
Showing
10 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module REST | ||
class API | ||
module Helpers | ||
module Pagination | ||
include Validation | ||
|
||
def pagination_params!(params) | ||
validated = validate!(params, with: ::REST::Validation::Pagination) | ||
default_pagination_params.merge(validated) | ||
end | ||
|
||
def default_pagination_params | ||
{ | ||
page: 1, | ||
per_page: PER_PAGE_DEFAULT | ||
}.with_indifferent_access | ||
end | ||
|
||
def present_paginated(collection, with:, page:, per_page:) | ||
paginated = collection.page(page).per(per_page).order(created_at: :asc) | ||
{ | ||
items: paginated.map { |item| with.new(item).serializable_hash }, | ||
last_page: paginated.total_pages | ||
} | ||
end | ||
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
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module REST | ||
class API | ||
class Organizations | ||
class Workers < Base | ||
desc "Get organization workers" | ||
get do | ||
authorize! requested_organization, to: :view_workers, with: OrganizationPolicy | ||
pagination_params!(params) => { page:, per_page: } | ||
present_paginated(requested_organization.workers, page:, per_page:, with: Serialization::Worker) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module REST | ||
module Validation | ||
class Pagination < Dry::Validation::Contract | ||
params do | ||
optional(:page).filled(:integer, gteq?: 1) | ||
optional(:per_page).filled(:integer, gteq?: 1, lteq?: REST::API::PER_PAGE_LIMIT) | ||
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ def update? | |
end | ||
|
||
alias view_shifts? update? | ||
alias view_workers? update? | ||
alias delete? update? | ||
end |