Skip to content

Commit

Permalink
Merge pull request #239 from praptisharma28/todo-react-django
Browse files Browse the repository at this point in the history
Added ToDo app made on react and django
  • Loading branch information
Kritika30032002 authored Jan 30, 2024
2 parents 9002585 + 55034d1 commit abb69cd
Show file tree
Hide file tree
Showing 60 changed files with 17,849 additions and 0 deletions.
4 changes: 4 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
node_modules/
db.sqlite3
venv
6 changes: 6 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__/
node_modules/
db.sqlite3
.env
venv
env
8 changes: 8 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.9-slim

WORKDIR /app
COPY . .

RUN pip install -r requirements.txt

CMD ["python","manage.py","runserver","0.0.0.0:8000"]
Empty file.
8 changes: 8 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin

# Register your models here.

from .models import Note


admin.site.register(Note)
6 changes: 6 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.7 on 2021-09-09 14:26

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField(blank=True, null=True)),
('updated', models.DateTimeField(auto_now=True)),
('created', models.DateTimeField(auto_now_add=True)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models

# Create your models here.


class Note(models.Model):
body = models.TextField(null=True, blank=True)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.body[0:50]
8 changes: 8 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework.serializers import ModelSerializer
from .models import Note


class NoteSerializer(ModelSerializer):
class Meta:
model = Note
fields = '__all__'
3 changes: 3 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
12 changes: 12 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import path
from . import views

urlpatterns = [
path('', views.getRoutes, name="routes"),
path('notes/', views.getNotes, name="notes"),
# path('notes/create/', views.createNote, name="create-note"),
#path('notes/<str:pk>/update/', views.updateNote, name="update-note"),
#path('notes/<str:pk>/delete/', views.deleteNote, name="delete-note"),

path('notes/<str:pk>/', views.getNote, name="note"),
]
40 changes: 40 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from rest_framework.response import Response
from .models import Note
from .serializers import NoteSerializer


def getNotesList(request):
notes = Note.objects.all().order_by('-updated')
serializer = NoteSerializer(notes, many=True)
return Response(serializer.data)


def getNoteDetail(request, pk):
notes = Note.objects.get(id=pk)
serializer = NoteSerializer(notes, many=False)
return Response(serializer.data)


def createNote(request):
data = request.data
note = Note.objects.create(
body=data['body']
)
serializer = NoteSerializer(note, many=False)
return Response(serializer.data)

def updateNote(request, pk):
data = request.data
note = Note.objects.get(id=pk)
serializer = NoteSerializer(instance=note, data=data)

if serializer.is_valid():
serializer.save()

return serializer.data


def deleteNote(request, pk):
note = Note.objects.get(id=pk)
note.delete()
return Response('Note was deleted!')
106 changes: 106 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from django.http import response
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework.serializers import Serializer
from .models import Note
from .serializers import NoteSerializer
from api import serializers
from .utils import updateNote, getNoteDetail, deleteNote, getNotesList, createNote
# Create your views here.


@api_view(['GET'])
def getRoutes(request):

routes = [
{
'Endpoint': '/notes/',
'method': 'GET',
'body': None,
'description': 'Returns an array of notes'
},
{
'Endpoint': '/notes/id',
'method': 'GET',
'body': None,
'description': 'Returns a single note object'
},
{
'Endpoint': '/notes/create/',
'method': 'POST',
'body': {'body': ""},
'description': 'Creates new note with data sent in post request'
},
{
'Endpoint': '/notes/id/update/',
'method': 'PUT',
'body': {'body': ""},
'description': 'Creates an existing note with data sent in post request'
},
{
'Endpoint': '/notes/id/delete/',
'method': 'DELETE',
'body': None,
'description': 'Deletes and exiting note'
},
]
return Response(routes)


# /notes GET
# /notes POST
# /notes/<id> GET
# /notes/<id> PUT
# /notes/<id> DELETE

@api_view(['GET', 'POST'])
def getNotes(request):

if request.method == 'GET':
return getNotesList(request)

if request.method == 'POST':
return createNote(request)


@api_view(['GET', 'PUT', 'DELETE'])
def getNote(request, pk):

if request.method == 'GET':
return getNoteDetail(request, pk)

if request.method == 'PUT':
return updateNote(request, pk)

if request.method == 'DELETE':
return deleteNote(request, pk)


# @api_view(['POST'])
# def createNote(request):
# data = request.data
# note = Note.objects.create(
# body=data['body']
# )
# serializer = NoteSerializer(note, many=False)
# return Response(serializer.data)


# @api_view(['PUT'])
# def updateNote(request, pk):
# data = request.data
# note = Note.objects.get(id=pk)
# serializer = NoteSerializer(instance=note, data=data)

# if serializer.is_valid():
# serializer.save()

# return Response(serializer.data)


# @api_view(['DELETE'])
# def deleteNote(request, pk):
# note = Note.objects.get(id=pk)
# note.delete()
# return Response('Note was deleted!')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions TODO_DjangoReact/Django-React-NotesApp/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"files": {
"main.css": "/static/css/main.138a22f4.chunk.css",
"main.js": "/static/js/main.5b159992.chunk.js",
"main.js.map": "/static/js/main.5b159992.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.4eab1d6a.js",
"runtime-main.js.map": "/static/js/runtime-main.4eab1d6a.js.map",
"static/js/2.bbb5d1f5.chunk.js": "/static/js/2.bbb5d1f5.chunk.js",
"static/js/2.bbb5d1f5.chunk.js.map": "/static/js/2.bbb5d1f5.chunk.js.map",
"index.html": "/index.html",
"static/css/main.138a22f4.chunk.css.map": "/static/css/main.138a22f4.chunk.css.map",
"static/js/2.bbb5d1f5.chunk.js.LICENSE.txt": "/static/js/2.bbb5d1f5.chunk.js.LICENSE.txt",
"static/media/add.3ceadee7.svg": "/static/media/add.3ceadee7.svg",
"static/media/arrow-left.a94dd897.svg": "/static/media/arrow-left.a94dd897.svg"
},
"entrypoints": [
"static/js/runtime-main.4eab1d6a.js",
"static/js/2.bbb5d1f5.chunk.js",
"static/css/main.138a22f4.chunk.css",
"static/js/main.5b159992.chunk.js"
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><link href="/static/css/main.138a22f4.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],i=r[1],a=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var i=t[l];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this.webpackJsonpfrontend=this.webpackJsonpfrontend||[],i=l.push.bind(l);l.push=r,l=l.slice();for(var a=0;a<l.length;a++)r(l[a]);var p=i;t()}([])</script><script src="/static/js/2.bbb5d1f5.chunk.js"></script><script src="/static/js/main.5b159992.chunk.js"></script></body></html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit abb69cd

Please sign in to comment.