Repository: divanov11/Django-React-NotesApp Branch: master Commit: da0b3de9a7cf Files: 43 Total size: 205.9 KB Directory structure: gitextract_3ytdzvus/ ├── README.md ├── api/ │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations/ │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── serializers.py │ ├── tests.py │ ├── urls.py │ ├── utils.py │ └── views.py ├── db.sqlite3 ├── frontend/ │ ├── .gitignore │ ├── README.md │ ├── build/ │ │ ├── asset-manifest.json │ │ ├── index.html │ │ ├── manifest.json │ │ ├── robots.txt │ │ └── static/ │ │ ├── css/ │ │ │ └── main.138a22f4.chunk.css │ │ └── js/ │ │ ├── 2.bbb5d1f5.chunk.js │ │ ├── 2.bbb5d1f5.chunk.js.LICENSE.txt │ │ ├── main.5b159992.chunk.js │ │ └── runtime-main.4eab1d6a.js │ ├── package.json │ ├── public/ │ │ ├── index.html │ │ ├── manifest.json │ │ └── robots.txt │ └── src/ │ ├── App.css │ ├── App.js │ ├── components/ │ │ ├── AddButton.js │ │ ├── Header.js │ │ └── ListItem.js │ ├── index.js │ └── pages/ │ ├── NotePage.js │ └── NotesListPage.js ├── manage.py ├── mynotes/ │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── requirements.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================
# Django & React Notes App
### Cloning the repository --> Clone the repository using the command below : ```bash git clone https://github.com/divanov11/Django-React-NotesApp.git ``` --> Move into the directory where we have the project files : ```bash cd Django-React-NotesApp ``` --> Create a virtual environment : ```bash # If you are on Windows virtualenv env # If you are on Linux or Mac python -m venv env ``` --> Activate the virtual environment : ```bash # If you are on Windows .\env\Scripts\activate # If you are on Linux or Mac source env/bin/activate ``` # ### Running the App --> To run the Notes App, we use : ```bash python manage.py runserver ``` > ⚠ Then, the development server will be started at http://127.0.0.1:8000/ # ### App Preview :
# ================================================ FILE: api/__init__.py ================================================ ================================================ FILE: api/admin.py ================================================ from django.contrib import admin # Register your models here. from .models import Note admin.site.register(Note) ================================================ FILE: api/apps.py ================================================ from django.apps import AppConfig class ApiConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'api' ================================================ FILE: api/migrations/0001_initial.py ================================================ # 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)), ], ), ] ================================================ FILE: api/migrations/__init__.py ================================================ ================================================ FILE: api/models.py ================================================ 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] ================================================ FILE: api/serializers.py ================================================ from rest_framework.serializers import ModelSerializer from .models import Note class NoteSerializer(ModelSerializer): class Meta: model = Note fields = '__all__' ================================================ FILE: api/tests.py ================================================ from django.test import TestCase # Create your tests here. ================================================ FILE: api/urls.py ================================================ 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//update/', views.updateNote, name="update-note"), #path('notes//delete/', views.deleteNote, name="delete-note"), path('notes//', views.getNote, name="note"), ] ================================================ FILE: api/utils.py ================================================ 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!') ================================================ FILE: api/views.py ================================================ 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/ GET # /notes/ PUT # /notes/ 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!') ================================================ FILE: frontend/.gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.js # testing /coverage # production # misc .DS_Store .env.local .env.development.local .env.test.local .env.production.local npm-debug.log* yarn-debug.log* yarn-error.log* ================================================ FILE: frontend/README.md ================================================ # 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) ================================================ FILE: frontend/build/asset-manifest.json ================================================ { "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" ] } ================================================ FILE: frontend/build/index.html ================================================ React App
================================================ FILE: frontend/build/manifest.json ================================================ { "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" } ================================================ FILE: frontend/build/robots.txt ================================================ # https://www.robotstxt.org/robotstxt.html User-agent: * Disallow: ================================================ FILE: frontend/build/static/css/main.138a22f4.chunk.css ================================================ @import url(https://fonts.googleapis.com/css2?family=Lexend:wght@400;600;700&display=swap);:root{--color-text:#383a3f;--color-dark:#1f2124;--color-gray:#677;--color-bg:#f3f6f9;--color-light:#acb4bd;--color-lighter:#f9f9f9;--color-white:#fff;--color-border:#e0e3e6}.dark,:root{--color-main:#f68657}.dark{--color-text:#d6d1d1;--color-dark:#f5f6f7;--color-gray:#999;--color-bg:#1f2124;--color-lighter:#292a2c;--color-white:#2e3235;--color-border:#252629}*{margin:0;padding:0;box-sizing:border-box;font-family:"Lexend",sans-serif;color:inherit;font-size:inherit;scroll-behavior:smooth}body{line-height:1.8em;font-weight:400;font-size:16px}a{text-decoration:none}.container{width:100%;height:100vh;color:#383a3f;color:var(--color-text);background-color:#f3f6f9;background-color:var(--color-bg);display:flex;align-items:center}.app{width:100%;max-width:480px;height:88vh;margin:0 auto;background-color:#fff;background-color:var(--color-white);box-shadow:1px 1px 6px rgba(0,0,0,.05);position:relative}.app-header{display:flex;align-items:center;padding:16px;justify-content:space-between;background-color:#f9f9f9;background-color:var(--color-lighter);box-shadow:0 1px 3px rgba(0,0,0,.1)}.app-header h1{font-size:30px;color:#1f2124;color:var(--color-dark);font-weight:800;text-align:center}.app-header button{border:0;background:transparent;cursor:pointer}.app-header button>svg{fill:#1f2124;fill:var(--color-dark);height:25px;width:25px;object-fit:cover}.app-body{padding:16px}.notes-header{display:flex;align-items:center;justify-content:space-between;padding:10px 16px}.notes-count,.notes-title{color:#f68657;color:var(--color-main);font-size:24px;font-weight:600}.notes-count{font-size:18px;color:#677;color:var(--color-gray)}.notes-list{padding:0;margin:16px 0;height:70vh;overflow-y:auto;scrollbar-width:none}.notes-list::-webkit-scrollbar{display:none}.notes-list-item{border-bottom:1px solid #e0e3e6;border-bottom:1px solid var(--color-border);margin-bottom:12px;padding:8px 16px;transition:all .2s ease-in-out}.notes-list-item:hover{background-color:#f3f6f9;background-color:var(--color-bg);cursor:pointer}.notes-list-item h3,.notes-list-item p span{font-weight:600}.notes-list-item p span{color:#677;color:var(--color-gray);display:inline-block;margin-right:8px}.notes-list-item p{font-size:14px;color:#acb4bd;color:var(--color-light)}.floating-button{font-size:48px;position:absolute;bottom:24px;right:16px;background:#f68657;background:var(--color-main);border:none;width:60px;height:60px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:1px 1px 10px rgba(0,0,0,.2)}.floating-button>svg{fill:#f3f6f9;fill:var(--color-bg)}.note-header{justify-content:space-between;color:#f68657;color:var(--color-main);padding:10px}.note-header,.note-header h3{display:flex;align-items:center}.note-header h3{font-size:24px;cursor:pointer}.note-header h3 svg{fill:#f68657;fill:var(--color-main);width:20px;margin-right:8px}.note-header button{border:none;outline:none;font-weight:600;background-color:transparent;font-size:18px;cursor:pointer}.note textarea{background-color:#fff;background-color:var(--color-white);border:none;padding:16px 12px;width:100%;height:70vh;resize:none;scrollbar-width:none}.note textarea:active,.note textarea:focus{outline:none;border:none}.note textarea::-webkit-scrollbar{display:none} /*# sourceMappingURL=main.138a22f4.chunk.css.map */ ================================================ FILE: frontend/build/static/js/2.bbb5d1f5.chunk.js ================================================ /*! For license information please see 2.bbb5d1f5.chunk.js.LICENSE.txt */ (this.webpackJsonpfrontend=this.webpackJsonpfrontend||[]).push([[2],[function(e,t,n){"use strict";e.exports=n(21)},function(e,t,n){"use strict";e.exports=n(26)},function(e,t,n){"use strict";n.d(t,"a",(function(){return w})),n.d(t,"b",(function(){return v})),n.d(t,"c",(function(){return m})),n.d(t,"d",(function(){return b}));var r=n(6),a=n(0),o=n.n(a),l=(n(11),n(4)),i=n(19),u=n(5),c=n(3),s=n(15),f=n.n(s),d=(n(17),n(10)),p=(n(20),function(e){var t=Object(i.a)();return t.displayName=e,t}),h=p("Router-History"),m=p("Router"),v=function(e){function t(t){var n;return(n=e.call(this,t)||this).state={location:t.history.location},n._isMounted=!1,n._pendingLocation=null,t.staticContext||(n.unlisten=t.history.listen((function(e){n._isMounted?n.setState({location:e}):n._pendingLocation=e}))),n}Object(r.a)(t,e),t.computeRootMatch=function(e){return{path:"/",url:"/",params:{},isExact:"/"===e}};var n=t.prototype;return n.componentDidMount=function(){this._isMounted=!0,this._pendingLocation&&this.setState({location:this._pendingLocation})},n.componentWillUnmount=function(){this.unlisten&&(this.unlisten(),this._isMounted=!1,this._pendingLocation=null)},n.render=function(){return o.a.createElement(m.Provider,{value:{history:this.props.history,location:this.state.location,match:t.computeRootMatch(this.state.location.pathname),staticContext:this.props.staticContext}},o.a.createElement(h.Provider,{children:this.props.children||null,value:this.props.history}))},t}(o.a.Component);o.a.Component;o.a.Component;var y={},g=0;function b(e,t){void 0===t&&(t={}),("string"===typeof t||Array.isArray(t))&&(t={path:t});var n=t,r=n.path,a=n.exact,o=void 0!==a&&a,l=n.strict,i=void 0!==l&&l,u=n.sensitive,c=void 0!==u&&u;return[].concat(r).reduce((function(t,n){if(!n&&""!==n)return null;if(t)return t;var r=function(e,t){var n=""+t.end+t.strict+t.sensitive,r=y[n]||(y[n]={});if(r[e])return r[e];var a=[],o={regexp:f()(e,a,t),keys:a};return g<1e4&&(r[e]=o,g++),o}(n,{end:o,strict:i,sensitive:c}),a=r.regexp,l=r.keys,u=a.exec(e);if(!u)return null;var s=u[0],d=u.slice(1),p=e===s;return o&&!p?null:{path:n,url:"/"===n&&""===s?"/":s,isExact:p,params:l.reduce((function(e,t,n){return e[t.name]=d[n],e}),{})}}),null)}var w=function(e){function t(){return e.apply(this,arguments)||this}return Object(r.a)(t,e),t.prototype.render=function(){var e=this;return o.a.createElement(m.Consumer,null,(function(t){t||Object(u.a)(!1);var n=e.props.location||t.location,r=e.props.computedMatch?e.props.computedMatch:e.props.path?b(n.pathname,e.props):t.match,a=Object(c.a)({},t,{location:n,match:r}),l=e.props,i=l.children,s=l.component,f=l.render;return Array.isArray(i)&&function(e){return 0===o.a.Children.count(e)}(i)&&(i=null),o.a.createElement(m.Provider,{value:a},a.match?i?"function"===typeof i?i(a):i:s?o.a.createElement(s,a):f?f(a):null:"function"===typeof i?i(a):null)}))},t}(o.a.Component);function k(e){return"/"===e.charAt(0)?e:"/"+e}function E(e,t){if(!e)return t;var n=k(e);return 0!==t.pathname.indexOf(n)?t:Object(c.a)({},t,{pathname:t.pathname.substr(n.length)})}function S(e){return"string"===typeof e?e:Object(l.e)(e)}function x(e){return function(){Object(u.a)(!1)}}function _(){}o.a.Component;o.a.Component;o.a.useContext},function(e,t,n){"use strict";function r(){return(r=Object.assign||function(e){for(var t=1;t=0;d--){var p=l[d];"."===p?o(l,d):".."===p?(o(l,d),f++):f&&(o(l,d),f--)}if(!c)for(;f--;f)l.unshift("..");!c||""===l[0]||l[0]&&a(l[0])||l.unshift("");var h=l.join("/");return n&&"/"!==h.substr(-1)&&(h+="/"),h};function i(e){return e.valueOf?e.valueOf():Object.prototype.valueOf.call(e)}var u=function e(t,n){if(t===n)return!0;if(null==t||null==n)return!1;if(Array.isArray(t))return Array.isArray(n)&&t.length===n.length&&t.every((function(t,r){return e(t,n[r])}));if("object"===typeof t||"object"===typeof n){var r=i(t),a=i(n);return r!==t||a!==n?e(r,a):Object.keys(Object.assign({},t,n)).every((function(r){return e(t[r],n[r])}))}return!1},c=n(5);function s(e){return"/"===e.charAt(0)?e:"/"+e}function f(e){return"/"===e.charAt(0)?e.substr(1):e}function d(e,t){return function(e,t){return 0===e.toLowerCase().indexOf(t.toLowerCase())&&-1!=="/?#".indexOf(e.charAt(t.length))}(e,t)?e.substr(t.length):e}function p(e){return"/"===e.charAt(e.length-1)?e.slice(0,-1):e}function h(e){var t=e.pathname,n=e.search,r=e.hash,a=t||"/";return n&&"?"!==n&&(a+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(a+="#"===r.charAt(0)?r:"#"+r),a}function m(e,t,n,a){var o;"string"===typeof e?(o=function(e){var t=e||"/",n="",r="",a=t.indexOf("#");-1!==a&&(r=t.substr(a),t=t.substr(0,a));var o=t.indexOf("?");return-1!==o&&(n=t.substr(o),t=t.substr(0,o)),{pathname:t,search:"?"===n?"":n,hash:"#"===r?"":r}}(e)).state=t:(void 0===(o=Object(r.a)({},e)).pathname&&(o.pathname=""),o.search?"?"!==o.search.charAt(0)&&(o.search="?"+o.search):o.search="",o.hash?"#"!==o.hash.charAt(0)&&(o.hash="#"+o.hash):o.hash="",void 0!==t&&void 0===o.state&&(o.state=t));try{o.pathname=decodeURI(o.pathname)}catch(i){throw i instanceof URIError?new URIError('Pathname "'+o.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):i}return n&&(o.key=n),a?o.pathname?"/"!==o.pathname.charAt(0)&&(o.pathname=l(o.pathname,a.pathname)):o.pathname=a.pathname:o.pathname||(o.pathname="/"),o}function v(e,t){return e.pathname===t.pathname&&e.search===t.search&&e.hash===t.hash&&e.key===t.key&&u(e.state,t.state)}function y(){var e=null;var t=[];return{setPrompt:function(t){return e=t,function(){e===t&&(e=null)}},confirmTransitionTo:function(t,n,r,a){if(null!=e){var o="function"===typeof e?e(t,n):e;"string"===typeof o?"function"===typeof r?r(o,a):a(!0):a(!1!==o)}else a(!0)},appendListener:function(e){var n=!0;function r(){n&&e.apply(void 0,arguments)}return t.push(r),function(){n=!1,t=t.filter((function(e){return e!==r}))}},notifyListeners:function(){for(var e=arguments.length,n=new Array(e),r=0;rt?n.splice(t,n.length-t,a):n.push(a),f({action:r,location:a,index:t,entries:n})}}))},replace:function(e,t){var r="REPLACE",a=m(e,t,d(),w.location);s.confirmTransitionTo(a,r,n,(function(e){e&&(w.entries[w.index]=a,f({action:r,location:a}))}))},go:b,goBack:function(){b(-1)},goForward:function(){b(1)},canGo:function(e){var t=w.index+e;return t>=0&&t=0||(a[n]=e[n]);return a}n.d(t,"a",(function(){return r}))},function(e,t,n){e.exports=n(28)()},function(e,t,n){"use strict";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n