Code Monkey home page Code Monkey logo

py-api-serializers's Introduction

API Serializers

  • Read the guideline before starting.

  • Use the following command to load prepared data from fixture to test and debug your code:

    python manage.py loaddata cinema_serviсe_db_data.json

In this task you will implement serializers and views for the following models:

  1. Genre
  2. Actor
  3. CinemaHall
  4. Movie
  5. MovieSession

For every <entity> from actors, genres, cinema_halls, movies, movie_sessions such endpoints should be implemented:

  • GET api/cinema/<entity>/ - should return a list of the all entity items
  • POST api/cinema/<entity>/ - should create a new entity based on passed data
  • GET api/cinema/<entity>/<pk>/ - should return an entity with given id
  • PUT api/cinema/<entity>/<pk>/ - should update the entity with given id based on passed data
  • DELETE api/cinema/<entity>/<pk>/ - should delete the entity with given id

Additional requirements:

  1. For the list movie endpoint, genres and actors should be returned as lists of strings. "genres" list should contain names of the genres, and the "actors" list should contain full names of actors and actresses. Example:
GET api/cinema/movies/ 
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

[
    {
        "id": 1,
        "title": "Harry Potter and the Philosopher's Stone",
        "description": "The first movie about Harry Potter",
        "duration": 210,
        "genres": [
            "drama"
        ],
        "actors": [
            "Emma Watson",
            "Daniel Radcliffe"
        ]
    }
]
  1. At the same time movie detail endpoint should provide complete information about the genres and actors.

Example:

GET /api/cinema/movies/1/
HTTP 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1,
    "title": "Harry Potter and the Philosopher's Stone",
    "description": "The first movie about Harry Potter",
    "duration": 210,
    "genres": [
        {
            "id": 1,
            "name": "drama"
        }
    ],
    "actors": [
        {
            "id": 1,
            "first_name": "Emma",
            "last_name": "Watson",
            "full_name": "Emma Watson"
        },
        {
            "id": 2,
            "first_name": "Daniel",
            "last_name": "Radcliffe",
            "full_name": "Daniel Radcliffe"
        }
    ]
}
  1. For movies_session list endpoint you should return the following information:
    • "id" - the id of the movie session;
    • "show_time" - the start time of the session
    • "movie_title" - the title of the movie
    • "cinema_hall_name" - the name of the cinema hall for the session
    • "cinema_hall_capacity" - the capacity of the cinema hall for the session

Example:

GET /api/cinema/movie_sessions/
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

[
    {
        "id": 2,
        "show_time": "2023-07-22T12:15:00Z",
        "movie_title": "Harry Potter and the Prisoner of Azkaban",
        "cinema_hall_name": "Green",
        "cinema_hall_capacity": 150
    },
    {
        "id": 1,
        "show_time": "2022-06-15T12:25:00Z",
        "movie_title": "Harry Potter and the Philosopher's Stone",
        "cinema_hall_name": "Black",
        "cinema_hall_capacity": 300
    }
]
  1. At the same time for the movie session detail endpoint, complete information about the movie should be provided.

Example:

GET /api/cinema/movie_sessions/1/
HTTP 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1,
    "show_time": "2022-06-15T12:25:00Z",
    "movie": {
        "id": 1,
        "title": "Harry Potter and the Philosopher's Stone",
        "description": "The first movie about Harry Potter",
        "duration": 210,
        "genres": [
            "drama"
        ],
        "actors": [
            "Emma Watson",
            "Daniel Radcliffe"
        ]
    },
    "cinema_hall": {
        "id": 2,
        "name": "Black",
        "rows": 20,
        "seats_in_row": 15,
        "capacity": 300
    }
}

Hint: Use ModelViewSet to create views.

Note: Check your code using this checklist before pushing your solution.

py-api-serializers's People

Contributors

ivanramyk avatar dmytrosvirsa avatar danylott avatar abnormaltype avatar y-havryliv 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.