Giter VIP home page Giter VIP logo

fast-api-v1's Introduction

Fast-api-v1

rewriting enterprise level fast-api

commands used for setup

  • Setup

    • py -3 -m venv venv

    • . venv/Scripts/activate

    • pip install fastapi

    • pip install uvicorn

    • pip freeze > requirements.txt

  • Pytest

    • pip install pytest

    • pip install httpx

  • Sqlalchemy

    pip install sqlalchemy

01. Initial commit

is to have the venv installed and updated readme


02. Added requirements.txt

adding a file called requirements.txt for dependency management


03. Created main.py file

created main.py file to run endpoint and test to make sure our code runs

hello world


04. Swagger spec documentation

swagger ui is included in FastAPI meaning we don't have to write it out from scratch like Flask

FastAPI swagger title


05. Created app_test.py in tests folder

testing welcome path op

test_tc0001_welcome

06. Created health enpoint and created a test for this endpoint

health

health_test


07. Installed sqlalchemy dependency and created a db_config file for database connection


08. Creating users data table

id column is generated after the other 2 fields are entered primary key makes it easier for us to find the user string(#) will alow how many characters are entered unique ensuring there is one 1 particular value in the database nullable meaning this field is required

health_test


09. Created schema.py

this is for when someone is entering data, the data will be bumped against the schema to make sure all fields are present before interacting with the database

orm stands for object realational mapping

user_model


10. Created user_repository.py file

this file will have the functions we need to interact with the database this will also have a test data function for testing

user_repository


11. Created a create_db function

this function is for creating our db file in db/local_sqlite

this will drop_all data at first then create the data and add the test data

create_db


12. Moved welcome and health endpoint to app_router.py located in the router folder


13. Created get_all_users function in user_repository.py

this code allows us to retrieve all the users in the database also added a function in the users_router.py for users to access

get_all_users


14. Created get_all_users test in users_test.py

this test is will be testing the first data in our test.db making sure all the values are present

test_get_all_users


15. Created get_by_username function in user_repository.py and get_by_username path operation in users_router

these codes will allow us to get information from a single user by their username

test_get_all_users

test_get_all_users


16. Created get_by_username test in users_test.py file testing the 200 and 404 response codes and return messages


17. Created add_user function in users_router.py file and created a CreateUserModel in schemas.py prompting the user to enter in the required fields before creating user to the database


18. Created add_user function to users_test.py file

this test will test our post operation in users_router.py and will also preform a get call to check the user information that is created in test.db file


19. Created different scenario tests for add_user function in users_router.py

testing different fields to make sure a status_code of 400 is responded to user when not entering all fields for post request


20. Added update_user function to users_repository.py

this code will udpate the fields if values are given by the user. We do not want the user to be able to update the username but email and role fields can be updated

update_user


21. Created update_user function in users_router.py file

this function check if there is a value in the email and role fields, then check to for the username within our database, will check there are values entered by the user in both email and role otherwise the fields will not be updated, also checks if both fields are empty

If email or role values are added or both, this will give a 204 status_code and will commit these changes in our database


22. Added put user test in users_test.py

testing different areas for put request such as updating both fields or email and role and testing if put request works if we only have 1 field being changed

added more put test by testing the bad scenarios if they body is empty, username not found, and if there is no body in the request


23. Added delete user function in users_repository.py and users_router.py

our functino in users_router.py will also include an if statement to check for the user in our database. If user is not found then we will raise a HTTPException of 404

Also added response headers in all of our user functions in users_router.py


24. Added additional function to check if username already exists in our post request function

is the post request function in users_router.py, we added an additonal check to take the username_request variable from the user and checked to see if it exists in our database already. If so, this will raise an HTTPException of 409 - conflict


25. Added get_by_email function in users_repository.py and added checking for existing email field in the post request function in users_router.py file

like earlier we were checking if the username already exists in the database, we are checking if the email already exists as well and if it does, we raise a 409 Conflict


Added 2 delete test function to users_test.py

the first function will create a test user then delete them and will also 'get' user as well to check if user is truly deleted

the second delete function will check if the user does not exist when trying to delete by username


fast-api-v1's People

Contributors

johnnypham7496 avatar

Watchers

 avatar

fast-api-v1's Issues

Activity dashboard

DashList

๐Ÿ‘‹ This dashboard summarizes my activity on the repository, including available improvement opportunities.

Recommendations

Last analysis: Feb 13 | Next scheduled analysis: Feb 20

Open

โœ… Nice work, you're all caught up!

Available

โœ… Nothing yet, but I'm continuing to monitor your PRs.

Metrics

What would you like to see here? Let us know!

Resources

๐Ÿ“š Quick links
Pixee Docs | Codemodder by Pixee

๐Ÿงฐ Tools I work with
Sonar, CodeQL, Semgrep

๐Ÿš€ Pixee CLI
The power of my codemods in your local development environment. Learn more

๐Ÿ’ฌ Reach out
Feedback | Support


โค๏ธ Follow, share, and engage with Pixee: GitHub | LinkedIn | Slack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.