build ok,
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase(`http://localhost:8090`);
|
||||
const COLLECTION_NAME = 'LessonsTypes';
|
||||
|
||||
interface LessonTypeCreate {
|
||||
name: string;
|
||||
type: string;
|
||||
pos: number;
|
||||
visible: string;
|
||||
}
|
||||
|
||||
interface ReqLessonTypeCreate {
|
||||
data: LessonTypeCreate;
|
||||
}
|
||||
|
||||
// POST - Create a new lesson type
|
||||
export async function POST(request: Request): Promise<Response> {
|
||||
const { data } = (await request.json()) as ReqLessonTypeCreate;
|
||||
const record = await pb.collection(COLLECTION_NAME).create(data);
|
||||
|
||||
return new Response(JSON.stringify(record), {
|
||||
status: 201,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
// please keep the comment and update to perform delete operation
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function DELETE(request: Request) {
|
||||
try {
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const { id } = await request.json();
|
||||
await pb.collection('LessonsTypes').delete(id);
|
||||
|
||||
return new Response('Record deleted successfully', {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new Response('Failed to delete record', { status: 500 });
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
// https://nextjs.org/blog/building-apis-with-nextjs
|
||||
import { NextRequest } from 'next/server';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const id = (await params).id;
|
||||
|
||||
const fields = ['id', 'name', 'type', 'visible', 'pos'].join(',');
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const lessonType = await pb.collection('LessonsTypes').getOne(id, { fields });
|
||||
|
||||
return new Response(JSON.stringify(lessonType), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
// Parse the request body
|
||||
const body = await request.json();
|
||||
const { name } = body;
|
||||
|
||||
// e.g. Insert new user into your DB
|
||||
const newUser = { id: Date.now(), name };
|
||||
|
||||
return new Response(JSON.stringify(newUser), {
|
||||
status: 201,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
###
|
||||
|
||||
GET http://localhost:3000/api/db/lesson_types/getById/e60v95892466775
|
||||
|
||||
###
|
@@ -0,0 +1,12 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
// const { PB_HOSTNAME } = process.env;
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
const pb = new PocketBase(`http://localhost:8090`);
|
||||
const resultList = await pb.collection('LessonsCategories').getList(1, 50, {});
|
||||
|
||||
// console.log(resultList);
|
||||
|
||||
return Response.json(resultList);
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
###
|
||||
|
||||
GET http://localhost:3000/api/db/lesson_categories/list
|
||||
|
||||
Content-Type: application/json
|
||||
cache: no-store
|
||||
cache-control: no-cache1
|
||||
|
||||
###
|
||||
|
||||
GET http://localhost:8090/api/collections/LessonsCategories/records
|
||||
|
||||
###
|
||||
|
||||
POST http://localhost:3000/api/lesson_categories/helloworld
|
||||
|
||||
Content-Type: application/json
|
@@ -0,0 +1,5 @@
|
||||
export async function GET(): Promise<Response> {
|
||||
const record = { hello: 'world' };
|
||||
|
||||
return Response.json(record);
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const { id, data } = await request.json();
|
||||
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const updatedRecord = await pb.collection('LessonsTypes').update(id, data);
|
||||
|
||||
return new Response(JSON.stringify(updatedRecord), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new Response('Failed to update record', { status: 500 });
|
||||
}
|
||||
}
|
26
002_source/cms/src/app/api/db/lesson_types/create/route.ts
Normal file
26
002_source/cms/src/app/api/db/lesson_types/create/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase(`http://localhost:8090`);
|
||||
const COLLECTION_NAME = 'LessonsTypes';
|
||||
|
||||
interface LessonTypeCreate {
|
||||
name: string;
|
||||
type: string;
|
||||
pos: number;
|
||||
visible: string;
|
||||
}
|
||||
|
||||
interface ReqLessonTypeCreate {
|
||||
data: LessonTypeCreate;
|
||||
}
|
||||
|
||||
// POST - Create a new lesson type
|
||||
export async function POST(request: Request): Promise<Response> {
|
||||
const { data } = (await request.json()) as ReqLessonTypeCreate;
|
||||
const record = await pb.collection(COLLECTION_NAME).create(data);
|
||||
|
||||
return new Response(JSON.stringify(record), {
|
||||
status: 201,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
19
002_source/cms/src/app/api/db/lesson_types/delete/route.ts
Normal file
19
002_source/cms/src/app/api/db/lesson_types/delete/route.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// please keep the comment and update to perform delete operation
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function DELETE(request: Request) {
|
||||
try {
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const { id } = await request.json();
|
||||
await pb.collection('LessonsTypes').delete(id);
|
||||
|
||||
return new Response('Record deleted successfully', {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new Response('Failed to delete record', { status: 500 });
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
// https://nextjs.org/blog/building-apis-with-nextjs
|
||||
import { NextRequest } from 'next/server';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const id = (await params).id;
|
||||
|
||||
const fields = ['id', 'name', 'type', 'visible', 'pos'].join(',');
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const lessonType = await pb.collection('LessonsTypes').getOne(id, { fields });
|
||||
|
||||
return new Response(JSON.stringify(lessonType), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
// Parse the request body
|
||||
const body = await request.json();
|
||||
const { name } = body;
|
||||
|
||||
// e.g. Insert new user into your DB
|
||||
const newUser = { id: Date.now(), name };
|
||||
|
||||
return new Response(JSON.stringify(newUser), {
|
||||
status: 201,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
###
|
||||
|
||||
GET http://localhost:3000/api/db/lesson_types/getById/e60v95892466775
|
||||
|
||||
###
|
12
002_source/cms/src/app/api/db/lesson_types/list/route.ts
Normal file
12
002_source/cms/src/app/api/db/lesson_types/list/route.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
// const { PB_HOSTNAME } = process.env;
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
const pb = new PocketBase(`http://localhost:8090`);
|
||||
const resultList = await pb.collection('LessonsTypes').getList(1, 50, {});
|
||||
|
||||
// console.log(resultList);
|
||||
|
||||
return Response.json(resultList);
|
||||
}
|
17
002_source/cms/src/app/api/db/lesson_types/list/test.http
Normal file
17
002_source/cms/src/app/api/db/lesson_types/list/test.http
Normal file
@@ -0,0 +1,17 @@
|
||||
###
|
||||
|
||||
GET http://localhost:3000/api/db/lesson_types/list
|
||||
|
||||
Content-Type: application/json
|
||||
cache: no-store
|
||||
cache-control: no-cache1
|
||||
|
||||
###
|
||||
|
||||
GET http://localhost:8090/api/collections/LessonsTypes/records
|
||||
|
||||
###
|
||||
|
||||
POST http://localhost:3000/api/lesson_types/helloworld
|
||||
|
||||
Content-Type: application/json
|
5
002_source/cms/src/app/api/db/lesson_types/test/route.ts
Normal file
5
002_source/cms/src/app/api/db/lesson_types/test/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function GET(): Promise<Response> {
|
||||
const record = { hello: 'world' };
|
||||
|
||||
return Response.json(record);
|
||||
}
|
20
002_source/cms/src/app/api/db/lesson_types/update/route.ts
Normal file
20
002_source/cms/src/app/api/db/lesson_types/update/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const { id, data } = await request.json();
|
||||
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const updatedRecord = await pb.collection('LessonsTypes').update(id, data);
|
||||
|
||||
return new Response(JSON.stringify(updatedRecord), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new Response('Failed to update record', { status: 500 });
|
||||
}
|
||||
}
|
9
002_source/cms/src/app/api/db/vocabularies/list/route.ts
Normal file
9
002_source/cms/src/app/api/db/vocabularies/list/route.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
const { PB_HOSTNAME } = process.env;
|
||||
const pb = new PocketBase(`http://${PB_HOSTNAME}:8090`);
|
||||
const resultList = await pb.collection('Vocabularies').getList(1, 50, {});
|
||||
|
||||
return Response.json(resultList);
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
###
|
||||
|
||||
GET http://localhost:3000/api/db/lesson_types/list
|
||||
|
||||
###
|
5
002_source/cms/src/app/api/helloworld/route.ts
Normal file
5
002_source/cms/src/app/api/helloworld/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const dynamic = 'force-static';
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
return Response.json({ hello: 'world' });
|
||||
}
|
Reference in New Issue
Block a user