This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import dataProvider from './dataProvider'; | |
| import { Admin, Resource } from 'react-admin'; | |
| import NotesList from './components/NotesList'; | |
| import NotesEdit from './components/NotesEdit'; | |
| import NotesCreate from './components/NotesCreate'; | |
| function App() { | |
| return ( | |
| <Admin dataProvider={dataProvider}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Admin} from 'react-admin'; | |
| import dataProvider from './dataProvider'; | |
| function App() { | |
| return ( | |
| <Admin dataProvider={dataProvider} /> | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { fetchUtils } from 'react-admin'; | |
| import { stringify } from 'query-string'; | |
| const apiUrl = 'http://localhost:3000/api'; | |
| const httpClient = fetchUtils.fetchJson; | |
| export default { | |
| getList: (resource, params) => { | |
| const { page, perPage } = params.pagination; | |
| const { field, order } = params.sort; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| function App() { | |
| return <div className="App">Hello world</div> | |
| } | |
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mongoose = require('mongoose'); | |
| const { Schema } = mongoose; | |
| const noteSchema = new Schema({ | |
| text: { type: String, required: true }, | |
| }); | |
| const Note = mongoose.model('note', noteSchema); | |
| module.exports = Note; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = (app) => { | |
| // create a note | |
| app.post('/api/notes', (request, reply) => {}); | |
| // get the list of notes | |
| app.get('/api/notes', (request, reply) => {}); | |
| // get a single note | |
| app.get('/api/notes/:id', (request, reply) => {}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const notesController = require('../controllers/notesController'); | |
| module.exports = (app) => { | |
| //# create a note | |
| app.post('/api/notes', notesController.create); | |
| //#get the list of notes | |
| app.get('/api/notes', notesController.fetch); | |
| //#get a single note |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Note = require('../models/note'); | |
| module.exports = { | |
| //# create a note | |
| create: async (request, reply) => {}, | |
| //#get the list of notes | |
| fetch: async (request, reply) => {}, | |
| //#get a single note |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //#delete a note | |
| delete: async (request, reply) => { | |
| try { | |
| const noteId = request.params.id; | |
| const noteToDelete = await Note.findById(noteId); | |
| await Note.findByIdAndDelete(noteId); | |
| reply.code(200).send({ data: noteToDelete }); | |
| } catch (e) { | |
| reply.code(500).send(e); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //#update a note | |
| update: async (request, reply) => { | |
| try { | |
| const noteId = request.params.id; | |
| const updates = request.body; | |
| await Note.findByIdAndUpdate(noteId, updates); | |
| const noteToUpdate = await Note.findById(noteId); | |
| reply.code(200).send({ data: noteToUpdate }); | |
| } catch (e) { | |
| reply.code(500).send(e); |