Skip to content

Commit 619f412

Browse files
committed
Add DELETE method for report and update UI handling for report deletion
1 parent 0395275 commit 619f412

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

backend/src/iac/backend-stack.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,18 @@ export class BackendStack extends cdk.Stack {
454454
},
455455
});
456456

457+
const deleteReportIntegration = new apigateway.Integration({
458+
type: apigateway.IntegrationType.HTTP_PROXY,
459+
integrationHttpMethod: 'DELETE',
460+
uri: `${serviceUrl}/api/reports/{id}`,
461+
options: {
462+
...integrationOptions,
463+
requestParameters: {
464+
'integration.request.path.id': 'method.request.path.id',
465+
},
466+
},
467+
});
468+
457469
const patchReportStatusIntegration = new apigateway.Integration({
458470
type: apigateway.IntegrationType.HTTP_PROXY,
459471
integrationHttpMethod: 'PATCH',
@@ -517,6 +529,13 @@ export class BackendStack extends cdk.Stack {
517529
},
518530
});
519531

532+
reportIdResource.addMethod('DELETE', deleteReportIntegration, {
533+
...methodOptions,
534+
requestParameters: {
535+
'method.request.path.id': true,
536+
},
537+
});
538+
520539
reportStatusResource.addMethod('PATCH', patchReportStatusIntegration, {
521540
...methodOptions,
522541
requestParameters: {

backend/src/reports/reports.controller.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
UnauthorizedException,
1111
Post,
1212
NotFoundException,
13+
Delete,
1314
} from '@nestjs/common';
1415
import {
1516
ApiTags,
@@ -192,6 +193,25 @@ export class ReportsController {
192193
return this.reportsService.saveReport(filePath, userId, originalFilename, fileSize);
193194
}
194195

196+
@ApiOperation({ summary: 'Delete a report' })
197+
@ApiResponse({
198+
status: 200,
199+
description: 'Report deleted successfully',
200+
})
201+
@ApiResponse({
202+
status: 404,
203+
description: 'Report not found',
204+
})
205+
@ApiParam({
206+
name: 'id',
207+
description: 'Report ID',
208+
})
209+
@Delete(':id')
210+
async deleteReport(@Param('id') id: string, @Req() request: RequestWithUser): Promise<void> {
211+
const userId = this.extractUserId(request);
212+
await this.reportsService.deleteReport(id, userId);
213+
}
214+
195215
private extractUserId(request: RequestWithUser): string {
196216
// The user object is attached to the request by our middleware
197217
const user = request.user;

frontend/src/pages/Reports/ReportDetailPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ const ReportDetailPage: React.FC = () => {
8080

8181
// Handle close button
8282
const handleClose = () => {
83-
history.goBack();
83+
history.push('/tabs/home');
8484
};
8585

8686
// Handle action buttons
87-
const handleDiscard = () => {
88-
history.goBack();
87+
const handleDiscard = async () => {
88+
await axios.delete(`${API_URL}/api/reports/${reportId}`, await getAuthConfig());
89+
history.push('/tabs/home');
8990
};
9091

9192
const handleNewUpload = () => {

frontend/src/pages/Reports/components/AiAnalysisTab.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ const AiAnalysisTab: React.FC<AiAnalysisTabProps> = ({
4545
{isLowConfidence && <LowConfidenceNotice />}
4646

4747
{/* Flagged values section */}
48-
<FlaggedValuesSection
49-
flaggedValues={flaggedValues}
50-
isExpanded={flaggedValuesExpanded}
51-
onToggle={toggleFlaggedValues}
52-
/>
48+
{flaggedValues && (
49+
<FlaggedValuesSection
50+
flaggedValues={flaggedValues}
51+
isExpanded={flaggedValuesExpanded}
52+
onToggle={toggleFlaggedValues}
53+
/>
54+
)}
5355

5456
{/* Normal values section */}
5557
<NormalValuesSection

0 commit comments

Comments
 (0)