2025-08-08 15:56:37 -04:00
|
|
|
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
|
2025-11-13 08:18:43 -05:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
|
import { Endpoint, HistoryBuilder } from 'src/decorators';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2025-02-21 09:58:25 -06:00
|
|
|
import {
|
|
|
|
|
AssetFaceCreateDto,
|
|
|
|
|
AssetFaceDeleteDto,
|
|
|
|
|
AssetFaceResponseDto,
|
|
|
|
|
FaceDto,
|
|
|
|
|
PersonResponseDto,
|
|
|
|
|
} from 'src/dtos/person.dto';
|
2025-11-11 17:01:14 -05:00
|
|
|
import { ApiTag, Permission } from 'src/enum';
|
2024-03-20 15:15:01 -05:00
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { PersonService } from 'src/services/person.service';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { UUIDParamDto } from 'src/validation';
|
2023-12-05 16:43:15 +01:00
|
|
|
|
2025-11-11 17:01:14 -05:00
|
|
|
@ApiTags(ApiTag.Faces)
|
2024-05-22 13:24:57 -04:00
|
|
|
@Controller('faces')
|
2023-12-05 16:43:15 +01:00
|
|
|
export class FaceController {
|
|
|
|
|
constructor(private service: PersonService) {}
|
|
|
|
|
|
2025-02-21 09:58:25 -06:00
|
|
|
@Post()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.FaceCreate })
|
2025-11-13 08:18:43 -05:00
|
|
|
@Endpoint({
|
2025-11-11 17:01:14 -05:00
|
|
|
summary: 'Create a face',
|
|
|
|
|
description:
|
|
|
|
|
'Create a new face that has not been discovered by facial recognition. The content of the bounding box is considered a face.',
|
2025-11-13 08:18:43 -05:00
|
|
|
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
|
2025-11-11 17:01:14 -05:00
|
|
|
})
|
2025-02-21 09:58:25 -06:00
|
|
|
createFace(@Auth() auth: AuthDto, @Body() dto: AssetFaceCreateDto) {
|
|
|
|
|
return this.service.createFace(auth, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 16:43:15 +01:00
|
|
|
@Get()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.FaceRead })
|
2025-11-13 08:18:43 -05:00
|
|
|
@Endpoint({
|
2025-11-11 17:01:14 -05:00
|
|
|
summary: 'Retrieve faces for asset',
|
|
|
|
|
description: 'Retrieve all faces belonging to an asset.',
|
2025-11-13 08:18:43 -05:00
|
|
|
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
|
2025-11-11 17:01:14 -05:00
|
|
|
})
|
2023-12-09 23:34:12 -05:00
|
|
|
getFaces(@Auth() auth: AuthDto, @Query() dto: FaceDto): Promise<AssetFaceResponseDto[]> {
|
|
|
|
|
return this.service.getFacesById(auth, dto);
|
2023-12-05 16:43:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.FaceUpdate })
|
2025-11-13 08:18:43 -05:00
|
|
|
@Endpoint({
|
2025-11-11 17:01:14 -05:00
|
|
|
summary: 'Re-assign a face to another person',
|
|
|
|
|
description: 'Re-assign the face provided in the body to the person identified by the id in the path parameter.',
|
2025-11-13 08:18:43 -05:00
|
|
|
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
|
2025-11-11 17:01:14 -05:00
|
|
|
})
|
2023-12-05 16:43:15 +01:00
|
|
|
reassignFacesById(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-12-05 16:43:15 +01:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: FaceDto,
|
|
|
|
|
): Promise<PersonResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.reassignFacesById(auth, id, dto);
|
2023-12-05 16:43:15 +01:00
|
|
|
}
|
2025-02-21 09:58:25 -06:00
|
|
|
|
|
|
|
|
@Delete(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.FaceDelete })
|
2025-08-08 15:56:37 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2025-11-13 08:18:43 -05:00
|
|
|
@Endpoint({
|
2025-11-11 17:01:14 -05:00
|
|
|
summary: 'Delete a face',
|
|
|
|
|
description: 'Delete a face identified by the id. Optionally can be force deleted.',
|
2025-11-13 08:18:43 -05:00
|
|
|
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
|
2025-11-11 17:01:14 -05:00
|
|
|
})
|
2025-08-08 15:56:37 -04:00
|
|
|
deleteFace(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto, @Body() dto: AssetFaceDeleteDto): Promise<void> {
|
2025-02-21 09:58:25 -06:00
|
|
|
return this.service.deleteFace(auth, id, dto);
|
|
|
|
|
}
|
2023-12-05 16:43:15 +01:00
|
|
|
}
|