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

1006/1007/1008 created new API endpoints for front end statistics #1059

Merged
merged 19 commits into from
Jul 3, 2024

Conversation

anagradova
Copy link
Contributor

@anagradova anagradova commented Jun 5, 2024

Description

This creates multiple new endpoints that are used to get statistical data:

/service/{{service_id}}/notifications/month
/service/{{service_id}}/notifications/{{user_id}}/month
/service/{{service_id}}/notifications/{{user_id}}/monthly
/service/{{service_id}}/statistics/{{start_date}}/{{day}}
/service/{{service_id}}/statistics/user/{{user_id}}/{{start_date}}/{{day}}

as well as updates to the test files to accommodate the new returned data structure in the monthly statistics return.

This PR also removes all usage of the deprecated datetime.utcnow() function and replaces it with the app.utils.utc_now() function.

This should include the following issues:

#1008
#1007
#1006

  • Dependency changes

No dependency changes

TODO (optional)

  • TODO test all new endpoints in Postman

Security Considerations

These are new endpoints that accept parameters from authorized clients. They should have additional security testing to make sure any SQL injection or other parameter risks are being handled by SQLAlchmey and the code properly.

@anagradova anagradova added engineering python Pull requests that update Python code labels Jun 5, 2024
NotificationAllTimeView which is a view created
to merge notifiations and notification_history
service, for a user, by a number of days
@anagradova anagradova changed the title 1006 created new API endpoints for front end statistics [DRAFT] 1006/1007 created new API endpoints for front end statistics Jun 7, 2024
Copy link
Contributor

@heyitsmebev heyitsmebev left a comment

Choose a reason for hiding this comment

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

✅ Thank you for your hard work in helping us get these endpoints!

@heyitsmebev
Copy link
Contributor

I want to make a note that the only endpoint that's missing is the month without user_id
{{base}}/service/{{service_id}}/notifications/month We don't need it now so it doesn't affect this PR to me. Something to note for us to add later.

Copy link
Contributor

@ccostino ccostino left a comment

Choose a reason for hiding this comment

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

Thank you, @anagradova, this is awesome and really nice progress on getting these endpoints together so quickly!

There are a couple of smaller things I noted in addition to a larger thing I wanted to check on, which is a possible optimization for how the day ranges are retrieved and returned. Please let me know if what I've noted is not clear and/or if you don't think it makes sense to incorporate, I'm definitely happy to sit down and talk through it all!

There is one other thing that I wanted to make sure we took a look at too, and that's using SQLAlchemy's newer (well, current!) style of querying the database: https://docs.sqlalchemy.org/en/20/tutorial/data_select.html

What you have here certainly works and is correct when working off of the db.session object, but it's relying on the older Query model that is going to be phased out in future releases of SQLAlchemy. This is an opportunity to start leveraging the current and newer approach now available to us with the 2.0.x upgrade! 🙂

Please take a look at the guide to see how to write the newer style queries with the select method syntax. The guide also includes documentation on how to add WHERE and GROUP BY clauses with the ORM as well, so all of the pieces are in place. Please let @xlorepdarkhelm or I know if you have any questions or are unsure how to approach this, we're happy to help!

Everything else looks good to me here. The endpoints all look great, there's error handling in place for the values being used as parameters, tests are updated, and everything is organized well. Thanks for working closely with @heyitsmebev on this, it's a great example of team collaboration! 🙂

app/service/rest.py Outdated Show resolved Hide resolved
app/dao/services_dao.py Outdated Show resolved Hide resolved
app/dao/services_dao.py Outdated Show resolved Hide resolved
app/service/rest.py Show resolved Hide resolved
app/service/rest.py Outdated Show resolved Hide resolved
@ccostino ccostino requested a review from xlorepdarkhelm June 8, 2024 04:05
app.utils utc_now() function. Added new endpoint
/service/{{service_id}}/notifications/month
@anagradova
Copy link
Contributor Author

I want to make a note that the only endpoint that's missing is the month without user_id {{base}}/service/{{service_id}}/notifications/month We don't need it now so it doesn't affect this PR to me. Something to note for us to add later.

This endpoint is now part of this PR.

for single database queries to improve
application performance.
app/service/rest.py Outdated Show resolved Hide resolved
app/service/rest.py Outdated Show resolved Hide resolved
app/service/rest.py Outdated Show resolved Hide resolved
standardized the SQLAlchemy calls
refactored the endpoints in service/rest.py
altered to use NotificationAllTimeView like
the other endpoints
@heyitsmebev
Copy link
Contributor

Making a note here that this PR also takes care of this issue: #1008

Copy link
Contributor

@xlorepdarkhelm xlorepdarkhelm left a comment

Choose a reason for hiding this comment

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

Just an optimization point and minor textual change I could see.

app/dao/date_util.py Outdated Show resolved Hide resolved
app/dao/date_util.py Show resolved Hide resolved
app/service/rest.py Outdated Show resolved Hide resolved
app/service/rest.py Outdated Show resolved Hide resolved
Copy link
Contributor

@xlorepdarkhelm xlorepdarkhelm left a comment

Choose a reason for hiding this comment

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

I forgot to mark "request changes" previously. Oops.

@ccostino ccostino changed the title 1006/1007 created new API endpoints for front end statistics 1006/1007/1008 created new API endpoints for front end statistics Jun 27, 2024
@ccostino
Copy link
Contributor

@anagradova will take a final look at the requested changes here. Thank you, and let us know if you need any help or need to hand things off! 🙂

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
Copy link
Contributor

@ccostino ccostino left a comment

Choose a reason for hiding this comment

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

Thank you, @anagradova! It's awesome seeing this all come together!

Thank you @xlorepdarkhelm for the assist at the end, too!

Copy link
Contributor

@xlorepdarkhelm xlorepdarkhelm left a comment

Choose a reason for hiding this comment

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

Forgot to approve the changes now.

@ccostino ccostino merged commit 9c39a92 into main Jul 3, 2024
7 checks passed
@ccostino ccostino deleted the 1006-new-api-failed-and-delivered-messages-7-days branch July 3, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engineering python Pull requests that update Python code
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

New API endpoint: number of failed and delivered messages in a service by day for a week (7 days)
5 participants