Code Monkey home page Code Monkey logo

salary_service's Introduction

FastAPI User Management and Salary Service

This project is a REST API service built with FastAPI for viewing salary information. It includes authentication mechanisms to ensure that only authorized users can access sensitive salary data.

Features

  • User Authentication
  • Retrieve Current Salary
  • Retrieve Date of Next Salary Increase
  • Secure Endpoints with JWT Token

Getting Started

Prerequisites

  • GNU Make
  • Docker and Docker Compose
  • Python 3.12 with Poetry

Installation

  1. Clone the repository

  2. Set up the environment variables:

    Set variables in .env file if needed

    POSTGRES_DB=yourdbname
    POSTGRES_USER=yourdbuser
    POSTGRES_PASSWORD=yourdbpassword
    POSTGRES_SERVER=localhost
  3. Install dependencies:

    poetry install

Running the Application

  1. Build and start the Docker containers:

    make up
  2. Access the API:

    The API will be available at http://localhost:8000

Endpoints

Endpoint Description
POST /user Create new user
POST /login Get access token for a user
GET /salary Get salary information

User Registration

  • URL: /user
  • Method: POST
  • Request Body:
    {
        "username": "testuser",
        "email": "[email protected]",
        "password": "securepassword",
        "salary": 50000,
        "promotion_date": "2024-05-17T00:00:00"
    }
  • Response: 201 Created

User Authentication

  • URL: /login
  • Method: POST
  • Request Body:
    {
        "username": "testuser",
        "password": "securepassword"
    }
  • Response:
    {
        "access_token": "access_token",
        "token_type": "bearer"
    }

Retrieve Salary Information

  • URL: /salary
  • Method: GET
  • Headers:
    Authorization: Bearer access_token
  • Response:
    {
        "salary": 50000,
        "promotion_date": "2024-05-17T00:00:00"
    }

Template requests for quick copy and paste

curl -X POST "http://localhost:8000/user"      -H "Content-Type: application/json"      -d '{
    "username": "testuser",
    "email": "[email protected]",
    "password": "securepassword",
    "salary": 50000,
    "promotion_date": "2024-05-17T00:00:00"
}'
curl -X POST "http://localhost:8000/auth/login"      -H "Content-Type: application/json"      -d '{
    "username": "testuser",
    "password": "securepassword"
}'
curl -X GET "http://localhost:8000/salary" \
     -H "Authorization: Bearer <access_token>"

Makefile

You can find more useful commands if you run

make help

salary_service's People

Contributors

x-wheel-of-fortune avatar

Watchers

 avatar

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.