Skip to content

bobbilichandu/phonebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHONEBOOK

A simple python api developed using fastapi to learn basic syntax and types and specially pydantic
Python version - 3.8
FastAPI - 0.63.0
sqlalchemy - 1.4.9
pydantic - 1.8.2

This api allows a user to create an account, and add contacts to his account.

How to use Phonebook?

  1. Clone the repository

    git clone https://github.com/chandu1263/phonebook.git

    cd phonebook

  2. Create a virtual environment with python3.8
    reference: https://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv

  3. pip install -r requirements.txt

  4. uvicorn main:phonebook --reload

Special Functionalities

  1. Token Auth: What is Token Auth?
          A very simple authorization using a unique string per user that is provided while creating one's account.
          Unique numeric string will be generated using a hash function, that will be provided via response for the user account creation request. That token has to provided whenever the user wants to make any changes to his/her data.

  2. Relational database Schema:
    User:
          id: int
          name: string
          mail: string
          phonenumber: string
          premium: bool
          contacts: list of Contacts
    Contact:
          id: int
          name: string
          mail: string
          phonenumber: string
          owner_id: int user_id

  3. SQLite database is used for this mini project, it is advisable to use postgres or other suitable databases for production purposes.

  4. Validation for mail and phone number.

Basic Functionalities

  1. Create user - POST
        http://ip:port/users/addUser/
    Request Body:
          {
                "name": "string",
                "email": "string",
                "phonenumber": "string"
          }

  2. Get user data - GET
          http://ip:port/users/{param}/
          param can be mail or phone number
          token is for authorization for the requested user
          Request Body:
          {
                "param": "string"
                "token": "string"
          }

  3. Add contact details - POST
          http://ip:port/users/{param}/addContact
          param can be mail or phone number
          token must be provided for authorization
          Request Body:
          {
                "name": "string",
                "email": "string",
                "phonenumber": "string"
                "token" : "string"
          }

  4. Get contacts of a user - GET
          http://ip:port/users/{param}/contacts
          param can be mail or phone number
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
          }

  5. Update user email - PUT
          http://ip:port/users/{param}/updateUserEmail
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
                "update_param" : "string" (to be updated email)
          }

  6. Update user phone number - PUT
          http://ip:port/users/{param}/updateUserPhonenumber
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
                "update_param" : "string" (to be updated phone number)
          }

  7. Delete user - DELETE
          http://ip:port/users/{param}/deleteUser
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
          }

  8. Update user contact email - PUT
          http://ip:port/users/{param}/updateContactEmail
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
                "email" : "string"
                "newmail" : "string"
          }

  9. Update user contact phone number - PUT
          http://ip:port/users/{param}/updateContactPhonenumber
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "token" : "string"
                "phonenumber" : "string"
                "newphonenumber" : "string"
          }

  10. Delete user contact - PUT
          http://ip:port/users/{param}/deleteUserContact
          param can be mail or phone number for identifying the user
          token must be provided for authorization
          contact_param can be mail or phone number for identifying contact of the user
          Request Body:
          {
                "param": "string"
                "token" : "string"
                "contact_param" : "string"
          }

  11. Make Premium User - PUT
          http://ip:port/admin/{param}/premiumUser
          param can be mail or phone number for identifying the user
          Admin token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "admin_token" : "string"
          }

  12. Get user (for premium users)- GET
          http://ip:port/premiumUser/getUser/{param}
          param can be mail or phone number for identifying the user
          Premium user param can be mail or phone number for identifying the premium user
          Premium token must be provided for authorization
          Request Body:
          {
                "param": "string"
                "premium_user_param" : "string"
                "premium_user_token" : "string"
          }

Http exceptions

Used Http Error Exceptions for error handling
(https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) 

Basic exceptions were used. 

About

Api to save, update and retrieve user's contacts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages