first commit
This commit is contained in:
32
src/app/api/hosts/[id]/route.ts
Normal file
32
src/app/api/hosts/[id]/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { hostsService } from '@/modules/hosts';
|
||||
import { handleError, noContent, notFound, ok } from '@/lib/api/response';
|
||||
|
||||
export async function GET(_req: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const host = await hostsService.get(params.id);
|
||||
if (!host) return notFound('Host not found');
|
||||
return ok(host);
|
||||
} catch (err) {
|
||||
return handleError(err);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const host = await hostsService.update(params.id, body);
|
||||
return ok(host);
|
||||
} catch (err) {
|
||||
return handleError(err);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_req: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
await hostsService.delete(params.id);
|
||||
return noContent();
|
||||
} catch (err) {
|
||||
return handleError(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user