2023-05-17 13:07:17 -04:00
|
|
|
import {
|
|
|
|
|
AssetResponseDto,
|
|
|
|
|
AuthUserDto,
|
2023-07-11 16:52:41 -05:00
|
|
|
BulkIdResponseDto,
|
2023-05-17 13:07:17 -04:00
|
|
|
ImmichReadStream,
|
2023-07-11 16:52:41 -05:00
|
|
|
MergePersonDto,
|
2023-07-18 20:09:43 +02:00
|
|
|
PeopleResponseDto,
|
2023-05-17 13:07:17 -04:00
|
|
|
PersonResponseDto,
|
2023-07-18 20:09:43 +02:00
|
|
|
PersonSearchDto,
|
2023-05-17 13:07:17 -04:00
|
|
|
PersonService,
|
|
|
|
|
PersonUpdateDto,
|
|
|
|
|
} from '@app/domain';
|
2023-07-18 20:09:43 +02:00
|
|
|
import { Body, Controller, Get, Param, Post, Put, Query, StreamableFile } from '@nestjs/common';
|
2023-07-06 17:25:56 -05:00
|
|
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
2023-07-01 14:27:34 -04:00
|
|
|
import { Authenticated, AuthUser } from '../app.guard';
|
|
|
|
|
import { UseValidation } from '../app.utils';
|
2023-05-17 13:07:17 -04:00
|
|
|
import { UUIDParamDto } from './dto/uuid-param.dto';
|
|
|
|
|
|
|
|
|
|
function asStreamableFile({ stream, type, length }: ImmichReadStream) {
|
|
|
|
|
return new StreamableFile(stream, { type, length });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiTags('Person')
|
|
|
|
|
@Controller('person')
|
|
|
|
|
@Authenticated()
|
|
|
|
|
@UseValidation()
|
|
|
|
|
export class PersonController {
|
|
|
|
|
constructor(private service: PersonService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2023-07-18 20:09:43 +02:00
|
|
|
getAllPeople(@AuthUser() authUser: AuthUserDto, @Query() withHidden: PersonSearchDto): Promise<PeopleResponseDto> {
|
|
|
|
|
return this.service.getAll(authUser, withHidden);
|
2023-05-17 13:07:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
2023-06-16 15:39:53 -04:00
|
|
|
getPerson(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<PersonResponseDto> {
|
2023-05-17 13:07:17 -04:00
|
|
|
return this.service.getById(authUser, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id')
|
|
|
|
|
updatePerson(
|
2023-06-16 15:39:53 -04:00
|
|
|
@AuthUser() authUser: AuthUserDto,
|
2023-05-17 13:07:17 -04:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: PersonUpdateDto,
|
|
|
|
|
): Promise<PersonResponseDto> {
|
|
|
|
|
return this.service.update(authUser, id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id/thumbnail')
|
2023-07-08 16:07:56 -04:00
|
|
|
@ApiOkResponse({
|
|
|
|
|
content: {
|
|
|
|
|
'image/jpeg': { schema: { type: 'string', format: 'binary' } },
|
|
|
|
|
},
|
|
|
|
|
})
|
2023-06-16 15:39:53 -04:00
|
|
|
getPersonThumbnail(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto) {
|
2023-05-17 13:07:17 -04:00
|
|
|
return this.service.getThumbnail(authUser, id).then(asStreamableFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id/assets')
|
2023-06-16 15:39:53 -04:00
|
|
|
getPersonAssets(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<AssetResponseDto[]> {
|
2023-05-17 13:07:17 -04:00
|
|
|
return this.service.getAssets(authUser, id);
|
|
|
|
|
}
|
2023-07-11 16:52:41 -05:00
|
|
|
|
|
|
|
|
@Post(':id/merge')
|
|
|
|
|
mergePerson(
|
|
|
|
|
@AuthUser() authUser: AuthUserDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: MergePersonDto,
|
|
|
|
|
): Promise<BulkIdResponseDto[]> {
|
|
|
|
|
return this.service.mergePerson(authUser, id, dto);
|
|
|
|
|
}
|
2023-05-17 13:07:17 -04:00
|
|
|
}
|