-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c464d06
Showing
722 changed files
with
225,496 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Import the PetRecord model | ||
import PetRecord from '../model.js/record.model.js'; | ||
|
||
// Controller to handle adding a new pet record | ||
export const addPetRecord = async (req, res) => { | ||
try { | ||
// Extracting data from the request body | ||
const { petName, ownerName, petBreed, petAge, specialNotes } = req.body; | ||
|
||
// Creating a new pet record instance | ||
const newPetRecord = new PetRecord({ | ||
petName, | ||
ownerName, | ||
petBreed, | ||
petAge, | ||
specialNotes | ||
}); | ||
|
||
// Saving the new pet record to the database | ||
await newPetRecord.save(); | ||
|
||
// Sending a success response | ||
res.status(201).json({ message: 'Pet record added successfully' }); | ||
} catch (error) { | ||
// Handling errors | ||
res.status(500).json({ message: 'Failed to add pet record', error: error.message }); | ||
} | ||
}; | ||
|
||
// Controller to handle fetching all pet records | ||
export const getAllPetRecords = async (req, res) => { | ||
try { | ||
// Fetching all pet records from the database | ||
const petRecords = await PetRecord.find(); | ||
|
||
// Sending the pet records as a response | ||
res.status(200).json(petRecords); | ||
} catch (error) { | ||
// Handling errors | ||
res.status(500).json({ message: 'Failed to fetch pet records', error: error.message }); | ||
} | ||
}; | ||
|
||
// Controller to handle fetching a single pet record | ||
|
||
export const getSinglePetRecord = async (req, res) => { | ||
try { | ||
// Extracting the pet record ID from the request parameters | ||
const { id } = req.params; | ||
|
||
// Fetching the pet record from the database | ||
const petRecord = await PetRecord.findById(id); | ||
|
||
// Sending the pet record as a response | ||
res.status(200).json(petRecord); | ||
} catch (error) { | ||
// Handling errors | ||
res.status(500).json({ message: 'Failed to fetch pet record', error: error.message }); | ||
} | ||
}; | ||
|
||
// Controller to handle updating a pet record | ||
|
||
export const updatePetRecord = async (req, res) => { | ||
try { | ||
// Extracting the pet record ID from the request parameters | ||
const { id } = req.params; | ||
|
||
// Extracting data from the request body | ||
const { petName, ownerName, petBreed, petAge, specialNotes } = req.body; | ||
|
||
// Updating the pet record in the database | ||
await PetRecord.findByIdAndUpdate(id, { | ||
petName, | ||
ownerName, | ||
petBreed, | ||
petAge, | ||
specialNotes | ||
}); | ||
|
||
// Sending a success response | ||
res.status(200).json({ message: 'Pet record updated successfully' }); | ||
} catch (error) { | ||
// Handling errors | ||
res.status(500).json({ message: 'Failed to update pet record', error: error.message }); | ||
} | ||
} | ||
|
||
// Controller to handle deleting a pet record | ||
|
||
export const deletePetRecord = async (req, res) => { | ||
try { | ||
// Extracting the pet record ID from the request parameters | ||
const { id } = req.params; | ||
|
||
// Deleting the pet record from the database | ||
await PetRecord.findByIdAndDelete(id); | ||
|
||
// Sending a success response | ||
res.status(200).json({ message: 'Pet record deleted successfully' }); | ||
} catch (error) { | ||
// Handling errors | ||
res.status(500).json({ message: 'Failed to delete pet record', error: error.message }); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import express from "express"; | ||
import mongoose from "mongoose"; | ||
import recordRouter from "./routes/record.route.js" | ||
import cors from "cors"; | ||
import bodyParser from "body-parser"; | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
app.listen(3000, () => { | ||
console.log("Server is running on port 3000"); | ||
}); | ||
|
||
mongoose.connect("mongodb+srv://nekanayake789:Naveen%[email protected]/?retryWrites=true&w=majority&appName=furrypets").then(() => { | ||
console.log("Connected to the database"); | ||
}).catch((err) => { | ||
|
||
console.log("Could not connect to the database. Exiting now...", err); | ||
process.exit(); | ||
}); | ||
|
||
app.use("/api/records", recordRouter); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
// Define the schema for the pet record | ||
const petRecordSchema = new mongoose.Schema({ | ||
petName: { | ||
type: String, | ||
required: true | ||
}, | ||
ownerName: { | ||
type: String, | ||
required: true | ||
}, | ||
petBreed: { | ||
type: String | ||
}, | ||
petAge: { | ||
type: Number | ||
}, | ||
specialNotes: { | ||
type: String | ||
} | ||
}); | ||
|
||
// Create a model from the schema | ||
const PetRecord = mongoose.model('PetRecord', petRecordSchema); | ||
|
||
export default PetRecord; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import express from 'express'; | ||
import { addPetRecord, deletePetRecord, getAllPetRecords, getSinglePetRecord, updatePetRecord } from '../controller.js/record.controller.js'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/petRecords', addPetRecord); | ||
|
||
router.get('/petRecords', getAllPetRecords); | ||
|
||
router.put('/petRecords/:id', updatePetRecord); | ||
|
||
router.delete('/petRecords/:id', deletePetRecord); | ||
|
||
router.get('/petRecords/:id', getSinglePetRecord); | ||
|
||
export default router; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, | ||
settings: { react: { version: '18.2' } }, | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# React + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.