Skip to content

markobozic1245/python-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weekly Schedule API

A Django REST API for managing weekly schedules with time slots and associated IDs.

Features

  • CRUD operations for time slots
  • JWT Authentication
  • Swagger documentation
  • Weekly schedule endpoint

Setup

  1. Clone the repository
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Run migrations:
    python manage.py makemigrations
    python manage.py migrate
    
  4. Create a superuser:
    python manage.py createsuperuser
    
  5. Run the server:
    python manage.py runserver
    

API Endpoints

  • /api/timeslots/ - CRUD operations for time slots
  • /api/schedule/ - Get the complete weekly schedule
  • /api/token/ - Get JWT token
  • /api/token/refresh/ - Refresh JWT token
  • /swagger/ - Swagger UI
  • /redoc/ - ReDoc UI

JWT Authentication Implementation

This project uses djangorestframework-simplejwt for JWT authentication. Here's how it's implemented:

  1. Install the package:

    pip install djangorestframework-simplejwt
    
  2. Add to INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        # ...
        'rest_framework',
        'rest_framework_simplejwt',
    ]
  3. Configure REST framework to use JWT authentication:

    REST_FRAMEWORK = {
        'DEFAULT_AUTHENTICATION_CLASSES': [
            'rest_framework_simplejwt.authentication.JWTAuthentication',
        ],
    }
  4. Add JWT URLs to urls.py:

    from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
    
    urlpatterns = [
        # ...
        path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
        path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    ]
  5. To use JWT authentication:

    • Get a token by sending a POST request to /api/token/ with username and password
    • Include the token in the Authorization header of your requests:
      Authorization: Bearer <your_token>
      
    • Refresh the token by sending a POST request to /api/token/refresh/ with the refresh token

Example Usage

Get JWT Token

curl -X POST "http://localhost:8000/api/token/" -H "Content-Type: application/json" -d '{"username":"your_username","password":"your_password"}'

Create a Time Slot

curl -X POST "http://localhost:8000/api/timeslots/" -H "Authorization: Bearer <your_token>" -H "Content-Type: application/json" -d '{"day_of_week":"monday","start":"09:00","stop":"11:00","ids":[1,2,3]}'

Get Weekly Schedule

curl -X GET "http://localhost:8000/api/schedule/" -H "Authorization: Bearer <your_token>"

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages