feat(api): implement DELETE endpoint for removing specific properties by URL
This commit is contained in:
parent
ff0f252389
commit
7b9977db6b
1 changed files with 44 additions and 0 deletions
44
src/app/api/urls/[encodedUrl]/properties/[property]/route.ts
Normal file
44
src/app/api/urls/[encodedUrl]/properties/[property]/route.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
//Handles DELETE requests for specific properties
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { deletePropertyByUrl } from '@/lib/database';
|
||||
|
||||
// DELETE /api/urls/[encodedUrl]/properties/[property] - Delete a property from a URL
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { encodedUrl: string; property: string } }
|
||||
) {
|
||||
const url = decodeURIComponent(params.encodedUrl);
|
||||
const property = decodeURIComponent(params.property);
|
||||
|
||||
console.log('[API] Deleting property', property, 'from URL', url);
|
||||
|
||||
try {
|
||||
if (!property) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Property name is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await deletePropertyByUrl(url, property);
|
||||
|
||||
console.log('[API] Successfully deleted property:', property);
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: 'Property deleted', property: property },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('[API] Delete error:', error);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Failed to delete property',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
property: property,
|
||||
url: url
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue