forked from hngprojects/hng_boilerplate_expressjs
-
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.
Merge branch 'dev' of https://github.com/Emeriego/hng_boilerplate_exp…
…ressjs into feat/super-admin-delete-an-organisation
- Loading branch information
Showing
13 changed files
with
1,188 additions
and
20 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,180 @@ | ||
# Blog API Documentation | ||
|
||
This project provides an API for managing blog posts, including creating, editing, deleting, and retrieving blog posts. The API is documented using Swagger. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
Make sure you have the following installed on your machine: | ||
|
||
- Node.js (>=14.x) | ||
- Yarn (>=1.x) | ||
|
||
### Installation | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone repo | ||
cd repo | ||
``` | ||
|
||
2. Install dependencies: | ||
```bash | ||
yarn install | ||
``` | ||
|
||
### Running the Server | ||
|
||
To start the server, run: | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
## API Endpoints | ||
|
||
### Authentication | ||
|
||
Ensure that users are authenticated before accessing the endpoints that modify or delete resources. | ||
|
||
#### Login | ||
|
||
- **URL**: `/api/v1/auth/login` | ||
- **Method**: `POST` | ||
- **Request Body**: | ||
```json | ||
{ | ||
"username": "[email protected]", | ||
"password": "password123" | ||
} | ||
``` | ||
- **Responses**: | ||
- `200 OK`: Successfully authenticated | ||
- `401 Unauthorized`: Invalid credentials | ||
|
||
#### Register | ||
|
||
- **URL**: `/api/v1/auth/register` | ||
- **Method**: `POST` | ||
- **Request Body**: | ||
```json | ||
{ | ||
"username": "[email protected]", | ||
"password": "password123", | ||
"name": "John Doe" | ||
} | ||
``` | ||
- **Responses**: | ||
- `201 Created`: Successfully registered | ||
- `400 Bad Request`: Invalid input | ||
|
||
### Create a Blog Post | ||
|
||
- **URL**: `/api/v1/blog/create` | ||
- **Method**: `POST` | ||
- **Authentication**: Required | ||
- **Request Body**: | ||
```json | ||
{ | ||
"title": "Sample Blog Post", | ||
"content": "This is a sample blog post.", | ||
"author": "John Doe", | ||
"Imageurl": "http://example.com/image.jpg", | ||
"categories": ["Tech", "Programming"], | ||
"tags": ["Node.js", "Express"], | ||
"likes": [], | ||
"comments": [] | ||
} | ||
``` | ||
- **Responses**: | ||
- `201 Created`: Blog post created successfully | ||
- `400 Bad Request`: Invalid request body | ||
- `401 Unauthorized`: Authentication required | ||
- `500 Internal Server Error`: Server error | ||
|
||
### Get All Blog Posts with Pagination | ||
|
||
- **URL**: `/api/v1/blog` | ||
- **Method**: `GET` | ||
- **Query Parameters**: | ||
- `page`: Page number (default: 1) | ||
- `limit`: Number of posts per page (default: 10) | ||
- `offset`: Number of posts to skip (default: 0) | ||
- **Responses**: | ||
- `200 OK`: List of blog posts | ||
- `500 Internal Server Error`: Server error | ||
|
||
### Get a Single Blog Post by ID | ||
|
||
- **URL**: `/api/v1/blog/:id` | ||
- **Method**: `GET` | ||
- **Parameters**: | ||
- `id`: Blog post ID | ||
- **Responses**: | ||
- `200 OK`: Blog post details | ||
- `404 Not Found`: Blog post not found | ||
- `500 Internal Server Error`: Server error | ||
|
||
### Edit a Blog Post by ID | ||
|
||
- **URL**: `/api/v1/blog/:id` | ||
- **Method**: `PUT` | ||
- **Authentication**: Required | ||
- **Parameters**: | ||
- `id`: Blog post ID | ||
- **Request Body**: | ||
```json | ||
{ | ||
"title": "Updated Blog Post", | ||
"content": "This is an updated blog post.", | ||
"author": "John Doe", | ||
"Imageurl": "http://example.com/new-image.jpg", | ||
"categories": ["Tech", "Programming"], | ||
"tags": ["Node.js", "Express"] | ||
} | ||
``` | ||
- **Responses**: | ||
- `200 OK`: Blog post updated successfully | ||
- `400 Bad Request`: Invalid request body | ||
- `401 Unauthorized`: Authentication required | ||
- `404 Not Found`: Blog post not found | ||
- `500 Internal Server Error`: Server error | ||
|
||
### Delete a Blog Post by ID | ||
|
||
- **URL**: `/api/v1/blog/:id` | ||
- **Method**: `DELETE` | ||
- **Authentication**: Required | ||
- **Parameters**: | ||
- `id`: Blog post ID | ||
- **Responses**: | ||
- `204 No Content`: Blog post deleted successfully | ||
- `401 Unauthorized`: Authentication required | ||
- `404 Not Found`: Blog post not found | ||
- `500 Internal Server Error`: Server error | ||
|
||
## Project Structure | ||
|
||
``` | ||
├── src | ||
│ ├── models | ||
│ │ └── blog.ts | ||
│ ├── routes | ||
│ │ └── blog.ts | ||
│ ├── blogSwaggerConfig.ts | ||
│ └── server.ts | ||
├── .gitignore | ||
├── package.json | ||
├── tsconfig.json | ||
└── README.md | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
|
||
``` | ||
``` |
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 |
---|---|---|
|
@@ -13,9 +13,10 @@ export class OrgController { | |
* post: | ||
* summary: Create a new organisation | ||
* description: This endpoint allows a user to create a new organisation | ||
* tags: | ||
* - Organisation | ||
* tags: [Organisations] | ||
* operationId: createOrganisation | ||
* security: | ||
* - bearerAuth: [] | ||
* requestBody: | ||
* description: Organisation payload | ||
* required: true | ||
|
@@ -30,8 +31,29 @@ export class OrgController { | |
* description: | ||
* type: string | ||
* example: This is a sample organisation. | ||
* email: | ||
* type: string | ||
* example: [email protected] | ||
* industry: | ||
* type: string | ||
* example: entertainment | ||
* type: | ||
* type: string | ||
* example: music | ||
* country: | ||
* type: string | ||
* example: Nigeria | ||
* state: | ||
* type: string | ||
* example: Oyo | ||
* required: | ||
* - name | ||
* - description | ||
* - industry | ||
* - type | ||
* - country | ||
* - state | ||
* responses: | ||
* '201': | ||
* description: Organisation created successfully | ||
|
@@ -58,6 +80,27 @@ export class OrgController { | |
* description: | ||
* type: string | ||
* example: This is a sample organisation. | ||
* email: | ||
* type: string | ||
* example: [email protected] | ||
* industry: | ||
* type: string | ||
* example: entertainment | ||
* type: | ||
* type: string | ||
* example: music | ||
* country: | ||
* type: string | ||
* example: Nigeria | ||
* state: | ||
* type: string | ||
* example: Oyo | ||
* slug: | ||
* type: string | ||
* example: 86820688-fd94-4b58-9bdd-99a701714a77 | ||
* owner_id: | ||
* type: string | ||
* example: 86820688-fd94-4b58-9bdd-99a701714a76 | ||
* createdAt: | ||
* type: string | ||
* format: date-time | ||
|
@@ -99,7 +142,14 @@ export class OrgController { | |
* status_code: | ||
* type: integer | ||
* example: 500 | ||
* components: | ||
* securitySchemes: | ||
* bearerAuth: | ||
* type: http | ||
* scheme: bearer | ||
* bearerFormat: JWT | ||
*/ | ||
|
||
async createOrganisation(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
const payload = req.body; | ||
|
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
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
Oops, something went wrong.