2023-06-16 11:48:48 -04:00
|
|
|
import {
|
|
|
|
|
AddUsersDto,
|
|
|
|
|
AlbumCountResponseDto,
|
|
|
|
|
AlbumService,
|
|
|
|
|
AuthUserDto,
|
|
|
|
|
CreateAlbumDto,
|
|
|
|
|
UpdateAlbumDto,
|
|
|
|
|
} from '@app/domain';
|
2023-03-26 04:46:48 +02:00
|
|
|
import { GetAlbumsDto } from '@app/domain/album/dto/get-albums.dto';
|
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';
|
2023-06-07 10:37:25 -04:00
|
|
|
import { ParseMeUUIDPipe } from '../api-v1/validation/parse-me-uuid-pipe';
|
2023-07-01 14:27:34 -04:00
|
|
|
import { Authenticated, AuthUser } from '../app.guard';
|
|
|
|
|
import { UseValidation } from '../app.utils';
|
2023-05-25 15:37:19 -04:00
|
|
|
import { UUIDParamDto } from './dto/uuid-param.dto';
|
2023-03-26 04:46:48 +02:00
|
|
|
|
|
|
|
|
@ApiTags('Album')
|
|
|
|
|
@Controller('album')
|
|
|
|
|
@Authenticated()
|
2023-04-03 06:24:18 +02:00
|
|
|
@UseValidation()
|
2023-03-26 04:46:48 +02:00
|
|
|
export class AlbumController {
|
|
|
|
|
constructor(private service: AlbumService) {}
|
|
|
|
|
|
2023-06-16 11:48:48 -04:00
|
|
|
@Get('count')
|
2023-06-16 15:39:53 -04:00
|
|
|
getAlbumCount(@AuthUser() authUser: AuthUserDto): Promise<AlbumCountResponseDto> {
|
2023-06-16 11:48:48 -04:00
|
|
|
return this.service.getCount(authUser);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 04:46:48 +02:00
|
|
|
@Get()
|
2023-06-16 15:39:53 -04:00
|
|
|
getAllAlbums(@AuthUser() authUser: AuthUserDto, @Query() query: GetAlbumsDto) {
|
2023-05-24 22:10:45 -04:00
|
|
|
return this.service.getAll(authUser, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2023-06-16 15:39:53 -04:00
|
|
|
createAlbum(@AuthUser() authUser: AuthUserDto, @Body() dto: CreateAlbumDto) {
|
2023-05-24 22:10:45 -04:00
|
|
|
return this.service.create(authUser, dto);
|
2023-03-26 04:46:48 +02:00
|
|
|
}
|
2023-05-25 15:37:19 -04:00
|
|
|
|
|
|
|
|
@Patch(':id')
|
2023-06-16 15:39:53 -04:00
|
|
|
updateAlbumInfo(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto, @Body() dto: UpdateAlbumDto) {
|
2023-05-25 15:37:19 -04:00
|
|
|
return this.service.update(authUser, id, dto);
|
|
|
|
|
}
|
2023-05-26 09:04:09 -04:00
|
|
|
|
|
|
|
|
@Delete(':id')
|
2023-06-16 15:39:53 -04:00
|
|
|
deleteAlbum(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto) {
|
2023-05-26 09:04:09 -04:00
|
|
|
return this.service.delete(authUser, id);
|
|
|
|
|
}
|
2023-06-07 10:37:25 -04:00
|
|
|
|
|
|
|
|
@Put(':id/users')
|
2023-06-16 15:39:53 -04:00
|
|
|
addUsersToAlbum(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto, @Body() dto: AddUsersDto) {
|
2023-06-07 10:37:25 -04:00
|
|
|
return this.service.addUsers(authUser, id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id/user/:userId')
|
|
|
|
|
removeUserFromAlbum(
|
2023-06-16 15:39:53 -04:00
|
|
|
@AuthUser() authUser: AuthUserDto,
|
2023-06-07 10:37:25 -04:00
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Param('userId', new ParseMeUUIDPipe({ version: '4' })) userId: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.service.removeUser(authUser, id, userId);
|
|
|
|
|
}
|
2023-03-26 04:46:48 +02:00
|
|
|
}
|