diff --git a/CNAME b/CNAME deleted file mode 100644 index 2698339..0000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -poet-app.onrender.com \ No newline at end of file diff --git a/PROJECT_STRUCTURE.md b/PROJECT_STRUCTURE.md deleted file mode 100644 index 39b80f5..0000000 --- a/PROJECT_STRUCTURE.md +++ /dev/null @@ -1,64 +0,0 @@ -# Project Structure - -## Directories - -- **models** - - poem.js: Defines the Poem schema using Mongoose. -- **routes** - - poems.js: Sets up routes for CRUD operations. -- **controllers** - - poemsController.js: Manages the logic of your application. -- **views** - - index.ejs: Renders the poems. -- **tests** - - app.test.js: Test the Express server. - - -## Files - -- **.env** - - Contains environment variables. -- **.gitignore** - - Contains the Git ignored files and directories. -- **jest.config.js** - - Test configuration are defined here. -- **jsconfig.json** - - Contains javascript environment configurations. -- **server.js** - - Sets up the Express server and connects to MongoDB. - - -## Example Structure - -```m -/poet-app -│ .env -│ .gitignore -│ jest.config.js -│ jsconfig.json -│ package-lock.json -│ package.json -│ README.md -│ PROJECT_STRUCTURE.md -│ server.js -| -└─── /models -│ └── poem.js -| -└─── /routes -│ └── poems.js -| -└─── /controllers -│ └── poemsController.js -| -└─── /views -│ ├── index.ejs -│ ├── edit.ejs -│ └── search.ejs -| -└─── /public -| └── styles.css -| -└─── /tests - └── app.test.js -``` diff --git a/Procfile b/Procfile deleted file mode 100644 index 6f86b16..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: node server.js \ No newline at end of file diff --git a/README.md b/README.md index 4f46deb..35a0f6c 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,87 @@ -# Quote | Poem Posting Web Application +# Poet App -[![CI](https://github.com/ramprasathmk/poet-app/actions/workflows/poet-app_test.yml/badge.svg)](https://github.com/ramprasathmk/poet-app/actions/workflows/poet-app_test.yml) +Poet App is a simple web application that allows users to post, edit, and delete quotes or poems. Built using Express.js and MongoDB, it provides a straightforward interface for managing literary entries. -## Description +[![CI Status](https://github.com/ramprasathmk/poet-app/actions/workflows/poet-app_test.yml/badge.svg)](https://github.com/ramprasathmk/poet-app/actions/workflows/poet-app_test.yml) -A simple web application that allows you to post, edit, and delete quotes. The application is built using Express and MongoDB. +## Table of Contents -## Features - -- Post new quotes -- Edit existing quotes -- Delete quotes -- View all posted quotes - -[node]: https://nodejs.org/en/download -[mongo]: https://www.mongodb.com/try/download/compass -[code]: https://code.visualstudio.com/download -[chrome]: https://www.google.com/chrome/ +- [Features](#features) +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Usage](#usage) +- [Project Structure](#project-structure) +- [Contributing](#contributing) +[//]: # (- [License](#license)) -## Prerequsites -| Tools | Version | -|-----------|-----------| -| [Node.js][node] | 20.10.0 | -| [MongoDB Compass][mongo] | 7.x | -| [Visual Studio Code][code] | latest | -| [Web Browser][chrome] | latest | - +## Features -## How To Run +- **Post Quotes/Poems**: Add new literary entries to the collection. +- **Edit Entries**: Modify existing quotes or poems. +- **Delete Entries**: Remove entries from the collection. +- **View All Entries**: Browse through all posted quotes and poems. -1. **Clone the repo:** - ```bash - git clone https://github.com/ramprasathmk/poet-app.git - cd poet-app - ``` +## Prerequisites -2. **Install dependencies:** - ```bash - npm install - ``` +Before you begin, ensure you have the following tools installed: -3. **Create .env file:** Create the `config.env` file in root directory. - ```text - MONGODB_URI=mongodb+srv://:@sandbox.abcde.mongodb.net/db_name - PORT=3000 - ``` +- **Node.js**: `>= 20.10.0` +- **MongoDB Compass**: `>= 7.x` +- **Visual Studio Code**: `latest` -4. **Check the MongoDB:** Ensure MongoDB is running locally. - ```bash - mongod - ``` +## Installation -5. **Start the Server:** - ```bash - npm run dev - ``` +1. **Clone the Repository**: -6. **Access the application:** Open your browser and navigate to http://localhost:3000 + ```bash + git clone https://github.com/ramprasathmk/poet-app.git + ``` +2. **Navigate to the Project Directory**: -## Deployment + ```bash + cd poet-app + ``` - - [Poet App](https://poet-app.onrender.com/) +3. **Install Dependencies**: + ```bash + npm install + ``` ## Usage -- Navigate to the home page to view all quotes. - -- Use the form to "**Add**" a new quote. +1. **Start the Application**: -- Click "**Edit**" to modify an existing quote. + ```bash + npm start + ``` -- Click "**Delete**" to remove a quote. +2. **Access the Application**: + Open your browser and navigate to `http://localhost:3000` to start using the Poet App. -## Technologies +## Project Structure -- Bootstrap CSS +The project follows a standard MVC (Model-View-Controller) architecture: -- Node.js +- `controllers/`: Contains the logic for handling requests and responses. +- `models/`: Defines the data schemas and interacts with the database. +- `routes/`: Manages the routing of HTTP requests. +- `views/`: Holds the EJS templates for rendering the frontend. +- `public/`: Includes static assets like CSS and JavaScript files. -- Express.js +## Contributing -- MongoDB +Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request. -- Mongoose +[//]: # (## License) -- EJS (Embedded JavaScript templates) +[//]: # () +[//]: # (This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.) --- -Feel free to modify this template to better suit your project’s specific needs. If you need further customization or have any questions, let me know! +Thank you for using Poet App! Feel free to explore, contribute, and share your favorite quotes and poems. \ No newline at end of file diff --git a/controllers/usersController.js b/controllers/usersController.js new file mode 100644 index 0000000..78cf740 --- /dev/null +++ b/controllers/usersController.js @@ -0,0 +1,10 @@ +const User = require('../models/user') + +/** + * Error handling middleware wrapper for `usersController` + */ +const asyncHandler = (fn) => { + return (req, res, next) => { + fn(req, res, next).catch(next) + } +} diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..81541c3 --- /dev/null +++ b/models/user.js @@ -0,0 +1,34 @@ +const mongoose = require('mongoose') +const arrType = mongoose.Types.Array + +/** + * User Schema { + * username: String, password: String, details: JSON | Object + * } + */ +const userSchema = new mongoose.Schema({ + username: { + type: String, + unique: true, + }, + password: { + type: String, + default: 'abc' + }, + details: { + type: JSON | Object, + default: {} + }, + poemId: { + type: arrType, + default: [] + }, + createdAt: { + type: Date, + default: Date.now + } +}) + +const User = mongoose.model('User', userSchema) + +module.exports = User