2024-08-19 13:37:15 -04:00
|
|
|
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Put, Query } from '@nestjs/common';
|
|
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
|
import { BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
|
|
|
import { StackCreateDto, StackResponseDto, StackSearchDto, StackUpdateDto } from 'src/dtos/stack.dto';
|
|
|
|
|
import { Permission } from 'src/enum';
|
|
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
|
|
|
|
import { StackService } from 'src/services/stack.service';
|
2025-07-22 22:17:06 -04:00
|
|
|
import { UUIDAssetIDParamDto, UUIDParamDto } from 'src/validation';
|
2024-08-19 13:37:15 -04:00
|
|
|
|
|
|
|
|
@ApiTags('Stacks')
|
|
|
|
|
@Controller('stacks')
|
|
|
|
|
export class StackController {
|
|
|
|
|
constructor(private service: StackService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackRead })
|
2024-08-19 13:37:15 -04:00
|
|
|
searchStacks(@Auth() auth: AuthDto, @Query() query: StackSearchDto): Promise<StackResponseDto[]> {
|
|
|
|
|
return this.service.search(auth, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackCreate })
|
2024-08-19 13:37:15 -04:00
|
|
|
createStack(@Auth() auth: AuthDto, @Body() dto: StackCreateDto): Promise<StackResponseDto> {
|
|
|
|
|
return this.service.create(auth, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete()
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackDelete })
|
2024-08-20 08:50:14 -04:00
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2024-08-19 13:37:15 -04:00
|
|
|
deleteStacks(@Auth() auth: AuthDto, @Body() dto: BulkIdsDto): Promise<void> {
|
|
|
|
|
return this.service.deleteAll(auth, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackRead })
|
2024-08-19 13:37:15 -04:00
|
|
|
getStack(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<StackResponseDto> {
|
|
|
|
|
return this.service.get(auth, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id')
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackUpdate })
|
2024-08-19 13:37:15 -04:00
|
|
|
updateStack(
|
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: StackUpdateDto,
|
|
|
|
|
): Promise<StackResponseDto> {
|
|
|
|
|
return this.service.update(auth, id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2025-07-15 14:50:13 -04:00
|
|
|
@Authenticated({ permission: Permission.StackDelete })
|
2024-08-19 13:37:15 -04:00
|
|
|
deleteStack(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
|
|
|
|
|
return this.service.delete(auth, id);
|
|
|
|
|
}
|
2025-07-22 22:17:06 -04:00
|
|
|
|
|
|
|
|
@Delete(':id/assets/:assetId')
|
|
|
|
|
@Authenticated({ permission: Permission.StackUpdate })
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
removeAssetFromStack(@Auth() auth: AuthDto, @Param() dto: UUIDAssetIDParamDto): Promise<void> {
|
|
|
|
|
return this.service.removeAsset(auth, dto);
|
|
|
|
|
}
|
2024-08-19 13:37:15 -04:00
|
|
|
}
|