Coder Social home page Coder Social logo

jdiazromeral / django-ddd-quizs-demo Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 48 KB

Sample project for Django DDD package.

License: MIT License

Python 99.08% Dockerfile 0.71% JavaScript 0.21%
django domain-driven-design hexagonal-architecture demo clean-architecture

django-ddd-quizs-demo's Introduction

Quiz

To build the project

docker-compose up -d --build api

Considerations

This repo is a sample for the package Django-ddd (package here https://github.com/jdiazromeral/django-ddd). This package is a proof of concept to adapt Django apps folder structure to something more like hexagonal architecture.

Project is build using docker-compose, so we don't need to set a local environment; we can directly use the one provided by docker-compose and docker.

All the code is in the src folder, under the service context. You can find entities, repository definitions, exceptions and business validation rules under domain, application services for the different features under application and all infrastructure related stuff, mainly API controllers, in memory and mongodb repositories, under infrastructure.

Each endpoint is listed in config/urls.py file.

Domain Model

You can find all the domain definitions under service/domain. Main entities are:

  • Quiz
  • Question
  • Answers

Database

Added two samples:

  • In memory repository
  • MongoDB repository (sorry, a bit quick and dirty one) using PyMongo

In the future we will add one using Django models.

API

We can retrieve all quizs available with a get call to http://localhost:8000/all

We can create quizs with a post call to: http://localhost:8000/create

Sample calls:

curl --location --request GET 'http://localhost:8000/all
or 
curl --location --request GET 'http://localhost:8000/all_mongo

Response

[
    {
        "id": "d8a13304-d815-4db4-b801-efb3f91d55f3",
        "title": "quiz title",
        "description": "quiz description",
        "type": "quiz type",
        "time": 10,
        "questions": [
            {
                "id": "a201429b-35d9-469c-9af1-125359d7d76e",
                "text": "text question",
                "skill": "LISTENING",
                "answers": {
                    "ff83bc63-cd97-453a-b9b1-287522ad00b1": {
                        "id": "ff83bc63-cd97-453a-b9b1-287522ad00b1",
                        "text": "answer text",
                        "question_id": "a201429b-35d9-469c-9af1-125359d7d76e"
                    },
                    "f099b566-7615-40a8-8a7b-1f5c174083c1": {
                        "id": "f099b566-7615-40a8-8a7b-1f5c174083c1",
                        "text": "answer text",
                        "question_id": "a201429b-35d9-469c-9af1-125359d7d76e"
                    }
                },
                "correct_answer": [
                    "ff83bc63-cd97-453a-b9b1-287522ad00b1"
                ],
                "quiz": "d8a13304-d815-4db4-b801-efb3f91d55f3"
            }
        ]
    }
]

To create you can use create or create_mongo:

curl --location --request POST 'http://localhost:8000/create \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "d8a13304-d815-4db4-b801-efb3f91d55f3",
    "title": "quiz title",
    "description": "quiz description",
    "type": "quiz type",
    "time": 10,
    "questions": [
        {
            "id": "a201429b-35d9-469c-9af1-125359d7d76e",
            "text": "text question",
            "skill": "LISTENING",
            "answers": [
                {
                    "id": "ff83bc63-cd97-453a-b9b1-287522ad00b1",
                    "text": "answer text",
                    "question_id": "a201429b-35d9-469c-9af1-125359d7d76e"
                },
                {
                    "id": "f099b566-7615-40a8-8a7b-1f5c174083c1",
                    "text": "answer text",
                    "question_id": "a201429b-35d9-469c-9af1-125359d7d76e"
                }
            ],
            "correct_answer": ["ff83bc63-cd97-453a-b9b1-287522ad00b1"],
            "quiz_id": "d8a13304-d815-4db4-b801-efb3f91d55f3"
        }
    ]
}'

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.