Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ressjs into feat/super-admin-delete-an-organisation
  • Loading branch information
Emeriego committed Jul 25, 2024
2 parents 517b870 + adba118 commit c5f00ac
Show file tree
Hide file tree
Showing 13 changed files with 1,188 additions and 20 deletions.
180 changes: 180 additions & 0 deletions docs/blog.md
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.

```
```
54 changes: 52 additions & 2 deletions src/controllers/OrgController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
* - email
* - industry
* - type
* - country
* - state
* responses:
* '201':
* description: Organisation created successfully
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 64 additions & 0 deletions src/controllers/PaymentLemonSqueezyController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
/**
* @swagger
* tags:
* name: Payments
* description: Payment management with LemonSqueezy
*/

import { Request, Response } from "express";
import crypto from "crypto";
import config from "../config";
import { Payment } from "../models/payment";
import AppDataSource from "../data-source";


/**
* @swagger
* /api/v1/payments/lemonsqueezy/initiate:
* get:
* summary: Initiates a payment using LemonSqueezy
* tags: [Payments]
* responses:
* 200:
* description: Payment initiation link
* content:
* text/html:
* schema:
* type: string
* example: <a href="https://ifeoluwa-hng-stage-5.lemonsqueezy.com/buy/bf9fee27-d226-4637-a32f-013bd717c3b3?embed=1" class="lemonsqueezy-button">Make Payments</a><script src="https://assets.lemonsqueezy.com/lemon.js" defer></script>
* 500:
* description: An error occurred while processing the payment
* content:
* application/json:
* schema:
* type: object
* properties:
* error:
* type: string
* example: An error occurred while processing the payment
*/

export const makePaymentLemonSqueezy = async (req: Request, res: Response) => {
try {
return res.send(
Expand All @@ -17,6 +51,36 @@ export const makePaymentLemonSqueezy = async (req: Request, res: Response) => {
}
};


/**
* @swagger
* /api/v1/payments/lemonsqueezy/webhook:
* post:
* summary: Handles LemonSqueezy webhook notifications
* tags: [Payments]
* requestBody:
* required: true
* content:
* text/plain:
* schema:
* type: string
* responses:
* 200:
* description: Webhook received successfully
* content:
* text/plain:
* schema:
* type: string
* example: Webhook received
* 400:
* description: Webhook verification failed
* content:
* text/plain:
* schema:
* type: string
* example: Webhook verification failed
*/

export const LemonSqueezyWebhook = async (req: Request, res: Response) => {
try {
const secret = config.LEMONSQUEEZY_SIGNING_KEY;
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/ProductController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ export class ProductController {
* message:
* type: string
* example: "Valid product ID, name, description, price, and stock must be provided."
* 401:
* description: Unauthorized
* 500:
* description: Server error
* content:
Expand Down
Loading

0 comments on commit c5f00ac

Please sign in to comment.