"feat: add EventItem, EventReview models with seed data and mock files, update User and Event schemas"
This commit is contained in:
23
03_source/cms_backend/src/app/api/order/_GUIDELINES.md
Normal file
23
03_source/cms_backend/src/app/api/order/_GUIDELINES.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# GUIDELINE
|
||||
|
||||
- this is a helloworld api endpoint
|
||||
- this is a demo to handle helloworld record
|
||||
- use single file for single db table/collection only
|
||||
|
||||
## `route.ts`
|
||||
|
||||
handle `GET`, `POST`, `PUT`, `DELETE`
|
||||
|
||||
## `test.http`
|
||||
|
||||
store test request
|
||||
|
||||
## `../../services/helloworld.service.ts`
|
||||
|
||||
helloworld schema CRUD handler
|
||||
|
||||
`listHelloworlds` - list helloworld record
|
||||
`getHelloworld` - get helloworld record by id
|
||||
`createNewHelloworld` - create helloworld record
|
||||
`updateHelloworld` - update helloworld record by id
|
||||
`deleteHelloworld` - delete helloworld record by id
|
76
03_source/cms_backend/src/app/api/order/route.ts
Normal file
76
03_source/cms_backend/src/app/api/order/route.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { STATUS, response, handleError } from 'src/utils/response';
|
||||
|
||||
import { listOrders, deleteOrder, updateOrder, createOrder } from 'src/app/services/order.service';
|
||||
|
||||
/**
|
||||
**************************************
|
||||
* GET - Order
|
||||
***************************************
|
||||
*/
|
||||
export async function GET(req: NextRequest, res: NextResponse) {
|
||||
try {
|
||||
const orders = await listOrders();
|
||||
return response(orders, STATUS.OK);
|
||||
} catch (error) {
|
||||
return handleError('Order - Get list', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
***************************************
|
||||
* POST - Create Order
|
||||
***************************************
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
const { data } = await req.json();
|
||||
|
||||
try {
|
||||
const order = await createOrder(data);
|
||||
return response(order, STATUS.CREATED);
|
||||
} catch (error) {
|
||||
return handleError('Order - Create', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
***************************************
|
||||
* PUT - Update Order
|
||||
***************************************
|
||||
*/
|
||||
export async function PUT(req: NextRequest) {
|
||||
const { searchParams } = req.nextUrl;
|
||||
const orderId = searchParams.get('orderId');
|
||||
const { data } = await req.json();
|
||||
|
||||
try {
|
||||
if (!orderId) throw new Error('orderId cannot be null');
|
||||
const id: number = parseInt(orderId);
|
||||
|
||||
const updatedOrder = await updateOrder(id, data);
|
||||
return response(updatedOrder, STATUS.OK);
|
||||
} catch (error) {
|
||||
return handleError('Order - Update', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
***************************************
|
||||
* DELETE - Delete Order
|
||||
***************************************
|
||||
*/
|
||||
export async function DELETE(req: NextRequest) {
|
||||
const { searchParams } = req.nextUrl;
|
||||
const orderId = searchParams.get('orderId');
|
||||
|
||||
try {
|
||||
if (!orderId) throw new Error('orderId cannot be null');
|
||||
const id: number = parseInt(orderId);
|
||||
|
||||
await deleteOrder(id);
|
||||
return response({ success: true }, STATUS.OK);
|
||||
} catch (error) {
|
||||
return handleError('Order - Delete', error);
|
||||
}
|
||||
}
|
32
03_source/cms_backend/src/app/api/order/test.http
Normal file
32
03_source/cms_backend/src/app/api/order/test.http
Normal file
@@ -0,0 +1,32 @@
|
||||
###
|
||||
GET http://localhost:7272/api/order
|
||||
|
||||
###
|
||||
GET http://localhost:7272/api/order?orderId=1
|
||||
|
||||
###
|
||||
POST http://localhost:7272/api/order
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"product": "Sample Product",
|
||||
"quantity": 1,
|
||||
"price": 99.99
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
PUT http://localhost:7272/api/order?orderId=1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"product": "Updated Product",
|
||||
"quantity": 2,
|
||||
"price": 199.98
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
DELETE http://localhost:7272/api/order?orderId=1
|
Reference in New Issue
Block a user