2023-06-07 10:37:25 -04:00
|
|
|
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query } from '@nestjs/common';
|
2023-03-26 04:46:48 +02:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
2024-03-20 23:53:07 +01:00
|
|
|
import {
|
|
|
|
|
AddUsersDto,
|
|
|
|
|
AlbumCountResponseDto,
|
|
|
|
|
AlbumInfoDto,
|
|
|
|
|
AlbumResponseDto,
|
|
|
|
|
CreateAlbumDto,
|
|
|
|
|
GetAlbumsDto,
|
|
|
|
|
UpdateAlbumDto,
|
|
|
|
|
} from 'src/dtos/album.dto';
|
|
|
|
|
import { BulkIdResponseDto, BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2024-03-20 15:15:01 -05:00
|
|
|
import { Auth, Authenticated, SharedLinkRoute } from 'src/middleware/auth.guard';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { AlbumService } from 'src/services/album.service';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { ParseMeUUIDPipe, UUIDParamDto } from 'src/validation';
|
2023-03-26 04:46:48 +02:00
|
|
|
|
|
|
|
|
@ApiTags('Album')
|
|
|
|
|
@Controller('album')
|
|
|
|
|
@Authenticated()
|
|
|
|
|
export class AlbumController {
|
|
|
|
|
constructor(private service: AlbumService) {}
|
|
|
|
|
|
2023-06-16 11:48:48 -04:00
|
|
|
@Get('count')
|
2023-12-09 23:34:12 -05:00
|
|
|
getAlbumCount(@Auth() auth: AuthDto): Promise<AlbumCountResponseDto> {
|
|
|
|
|
return this.service.getCount(auth);
|
2023-06-16 11:48:48 -04:00
|
|
|
}
|
|
|
|
|
|
2023-03-26 04:46:48 +02:00
|
|
|
@Get()
|
2023-12-09 23:34:12 -05:00
|
|
|
getAllAlbums(@Auth() auth: AuthDto, @Query() query: GetAlbumsDto): Promise<AlbumResponseDto[]> {
|
|
|
|
|
return this.service.getAll(auth, query);
|
2023-05-24 22:10:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2024-03-20 19:32:04 +01:00
|
|
|
createAlbum(@Auth() auth: AuthDto, @Body() dto: CreateAlbumDto): Promise<AlbumResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.create(auth, dto);
|
2023-03-26 04:46:48 +02:00
|
|
|
}
|
2023-05-25 15:37:19 -04:00
|
|
|
|
2023-08-01 21:29:14 -04:00
|
|
|
@SharedLinkRoute()
|
|
|
|
|
@Get(':id')
|
2023-11-19 23:16:24 +01:00
|
|
|
getAlbumInfo(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-11-19 23:16:24 +01:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Query() dto: AlbumInfoDto,
|
|
|
|
|
): Promise<AlbumResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.get(auth, id, dto);
|
2023-08-01 21:29:14 -04:00
|
|
|
}
|
|
|
|
|
|
2023-05-25 15:37:19 -04:00
|
|
|
@Patch(':id')
|
2023-11-19 23:16:24 +01:00
|
|
|
updateAlbumInfo(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-11-19 23:16:24 +01:00
|
|
|
@Param() { id }: UUIDParamDto,
|
2024-03-20 19:32:04 +01:00
|
|
|
@Body() dto: UpdateAlbumDto,
|
2023-11-19 23:16:24 +01:00
|
|
|
): Promise<AlbumResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.update(auth, id, dto);
|
2023-05-25 15:37:19 -04:00
|
|
|
}
|
2023-05-26 09:04:09 -04:00
|
|
|
|
|
|
|
|
@Delete(':id')
|
2023-12-09 23:34:12 -05:00
|
|
|
deleteAlbum(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto) {
|
|
|
|
|
return this.service.delete(auth, id);
|
2023-05-26 09:04:09 -04:00
|
|
|
}
|
2023-06-07 10:37:25 -04:00
|
|
|
|
2023-08-01 21:29:14 -04:00
|
|
|
@SharedLinkRoute()
|
|
|
|
|
@Put(':id/assets')
|
|
|
|
|
addAssetsToAlbum(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-08-01 21:29:14 -04:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: BulkIdsDto,
|
|
|
|
|
): Promise<BulkIdResponseDto[]> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.addAssets(auth, id, dto);
|
2023-08-01 21:29:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id/assets')
|
|
|
|
|
removeAssetFromAlbum(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-08-01 21:29:14 -04:00
|
|
|
@Body() dto: BulkIdsDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
): Promise<BulkIdResponseDto[]> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.removeAssets(auth, id, dto);
|
2023-08-01 21:29:14 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-07 10:37:25 -04:00
|
|
|
@Put(':id/users')
|
2023-08-11 12:00:51 -04:00
|
|
|
addUsersToAlbum(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-08-11 12:00:51 -04:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: AddUsersDto,
|
|
|
|
|
): Promise<AlbumResponseDto> {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.addUsers(auth, id, dto);
|
2023-06-07 10:37:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id/user/:userId')
|
|
|
|
|
removeUserFromAlbum(
|
2023-12-09 23:34:12 -05:00
|
|
|
@Auth() auth: AuthDto,
|
2023-06-07 10:37:25 -04:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Param('userId', new ParseMeUUIDPipe({ version: '4' })) userId: string,
|
|
|
|
|
) {
|
2023-12-09 23:34:12 -05:00
|
|
|
return this.service.removeUser(auth, id, userId);
|
2023-06-07 10:37:25 -04:00
|
|
|
}
|
2023-03-26 04:46:48 +02:00
|
|
|
}
|