|
1 |
| -# expressjs-mongodb-mrc-blogging-api-demo |
| 1 | +# Model-Router-Controller Pattern Express.js Blogging Platform Website API |
2 | 2 |
|
3 |
| -## Description |
| 3 | +A RESTful API built with Express.js, following the Model-Router-Controller (MRC) pattern, for a mock blogging platform. This application handles user authentication, blogging, commenting, and message-sending functionality. |
4 | 4 |
|
5 | 5 | ## Features
|
6 | 6 |
|
7 |
| -## Sample Registered Credentials |
| 7 | +- **User Management:** Registration, login, and profile updates |
| 8 | +- **Blog Management:** Create, update, delete, and comment on blog posts |
| 9 | +- **Admin Dashboard:** Admin users can moderation messages and comments. |
| 10 | +- **Messaging System:** Users can send messages to the admin via a contact form |
| 11 | +- **Logging & Testing:** Integrated logging and testing functionalities |
| 12 | +- **Role-based Authorization:** Specific routes are accessible only to authorized roles |
8 | 13 |
|
9 |
| -# How to Run |
| 14 | +## Installation |
10 | 15 |
|
11 |
| -## API Routes Overview |
| 16 | +1. Clone the repository: |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://github.com/ronnmabunga/expressjs-mongodb-mrc-blogging-api-demo.git |
| 20 | +cd blogging-platform-api |
| 21 | +``` |
| 22 | + |
| 23 | +2. Install dependencies: |
| 24 | + |
| 25 | +```bash |
| 26 | +npm install |
| 27 | +``` |
| 28 | + |
| 29 | +3. Run the application: |
| 30 | + |
| 31 | +```bash |
| 32 | +npm run start |
| 33 | +``` |
| 34 | + |
| 35 | +## Testing |
| 36 | + |
| 37 | +To run tests: |
| 38 | + |
| 39 | +```bash |
| 40 | +npm test |
| 41 | +``` |
| 42 | + |
| 43 | +All tests are located in test/test.js. |
| 44 | + |
| 45 | +## Models |
| 46 | + |
| 47 | +- **User**: Stores user account information. |
| 48 | +- **Blog**: Stores blog information and associated comments. |
| 49 | +- **Message**: Stores messages sent by users to the admin (reviews, suggestions, etc.). |
12 | 50 |
|
13 | 51 | ## Dependencies
|
14 | 52 |
|
15 |
| -# License |
| 53 | +### Core Dependencies |
| 54 | + |
| 55 | +- **express**: Web application framework for Node.js, used to build RESTful APIs. |
| 56 | +- **mongoose**: MongoDB object modeling tool, providing schema-based data modeling and connection management. |
| 57 | +- **bcrypt**: Library for hashing passwords, enhancing security by encrypting sensitive data. |
| 58 | +- **cors**: Middleware to enable Cross-Origin Resource Sharing, allowing your API to handle requests from different origins. |
| 59 | +- **dotenv**: Loads environment variables from a .env file, helping manage configuration securely. |
| 60 | +- **jsonwebtoken**: Implements JSON Web Tokens (JWT) for user authentication. |
| 61 | +- **morgan**: HTTP request logger middleware, used for logging request details. |
| 62 | +- **winston**: Logging library providing various transport options for log management. |
| 63 | + |
| 64 | +### Dev Dependencies |
| 65 | + |
| 66 | +- **mocha**: Test framework for Node.js, used to run unit and integration tests. |
| 67 | +- **chai**: Assertion library to support a variety of test assertions. |
| 68 | +- **chai-http**: Extends Chai for HTTP integration tests, used to test API endpoints. |
| 69 | + |
| 70 | +## API Routes Overview |
| 71 | + |
| 72 | +### User Routes |
| 73 | + |
| 74 | +- **GET /** - Retrieve logged-in user details. |
| 75 | +- **PATCH /** - Update logged-in user details. |
| 76 | +- **POST /register** - Register a new user. |
| 77 | +- **POST /login** - Login an existing user. |
| 78 | + |
| 79 | +### Message Routes |
| 80 | + |
| 81 | +- **GET /** - Admin access to retrieve all messages. |
| 82 | +- **POST /** - Send a "Contact Us" message. |
| 83 | +- **PATCH /:messageId** - Mark a message as read (admin only). |
| 84 | + |
| 85 | +### Blog Routes |
| 86 | + |
| 87 | +- **GET /** - Retrieve blogs created by the logged-in user. |
| 88 | +- **POST /** - Create a new blog post. |
| 89 | +- **GET /all** - Retrieve all blogs. |
| 90 | +- **GET /:blogId** - Retrieve a specific blog by ID. |
| 91 | +- **POST /:blogId** - Add a comment to a blog post. |
| 92 | +- **PATCH /:blogId** - Update a blog post. |
| 93 | +- **DELETE /:blogId** - Delete a blog post. |
| 94 | +- **PATCH /:blogId/:commentId** - Update a comment. |
| 95 | +- **DELETE /:blogId/:commentId** - Delete a comment |
| 96 | + |
| 97 | +## Sample Registered Credentials |
| 98 | + |
| 99 | +Use these sample users to test the API: |
| 100 | + |
| 101 | +- **Non-admin User**: |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + |
| 106 | + "password": "pAs$w0rd" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +- **Admin User**: |
| 111 | + |
| 112 | +```json |
| 113 | +{ |
| 114 | + |
| 115 | + "password": "pAs$w0rd" |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +## Continuous Integration |
| 120 | + |
| 121 | +A GitHub Actions workflow using Docker is set up for continuous integration. |
| 122 | + |
| 123 | +## License |
16 | 124 |
|
17 | 125 | This project is licensed under the GNU GENERAL PUBLIC LICENSE.
|
0 commit comments