Skip to content
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

feat: support total_count param for GET /submissions #1481

Closed
wants to merge 3 commits into from

Conversation

MounirDhahri
Copy link
Member

This PR adds support to a new param to GET /submissions endpoint in order to return the total count of submission.
This might not be the best approach because we might need to support the same param in other endpoints, It would be interesting to investigate how to support that everywhere - but maybe that's not possible.

Why did we add this?
This was important in order to return the totalCount of submissions for a user in the submissionsConnection interface.

Co-authored-by: Ole <ole.richter91@gmail.com>
Co-authored-by: Daria Kozlova <Nargle30@gmail.com>
Co-authored-by: Tam <kis.tamara91@gmail.com>
@MounirDhahri MounirDhahri self-assigned this Jun 25, 2024
@MounirDhahri MounirDhahri changed the title feat: support total_count param feat: support total_count param for GET /submissions Jun 25, 2024
@@ -24,6 +24,10 @@ def update
end

def index
# Return x-total-count header if total_count param is present
if params[:total_count].present?
headers["X-Total-Count"] = Submission.count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This would always return the total number of Submissions in the database. We should push this further down below any scopes/filters, if we need it. What UI would this support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would always return the total number of Submissions in the database. We should push this further down below any scopes/filters

Good catch, will update

What UI would this support?

I added this to keep the API the same as we do with Gravity for connections
Screenshot 2024-06-25 at 14 00 55

@MounirDhahri MounirDhahri marked this pull request as draft June 25, 2024 12:27

# Return x-total-count header if total_count param is present. Keep this last
if params[:total_count].present?
headers["X-Total-Count"] = Submission.count
Copy link
Contributor

@nickskalkin nickskalkin Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return a total number of user's submissions? In this case use can do user.submissions.count

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually just submissions.count, because there are other filters above and it is already filtered by user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - thanks!

@MounirDhahri MounirDhahri force-pushed the feat/support-total-count-param branch from e98510f to 02822f1 Compare June 26, 2024 10:01
Copy link
Contributor

@nickskalkin nickskalkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, left 2 small comments

@@ -34,6 +34,12 @@ def index
end

submissions = submissions.order(created_at: :desc).page(page).per(size)

# Return x-total-count header if total_count param is present. Keep this last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this last - was this sentence incomplete?

@@ -57,6 +57,18 @@
expect(body.first["id"]).to eq submission.id
end

fit "returns total count when total_count param is present" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove fit!

@MounirDhahri
Copy link
Member Author

Closing this for now - we can bring it again if we decide to support save and continue in the backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants