feat: 支持秒杀活动
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseGuards,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common'
|
||||
import { UserRole } from '@mp-pilates/shared'
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard'
|
||||
import { RolesGuard } from '../auth/roles.guard'
|
||||
import { Roles } from '../auth/roles.decorator'
|
||||
import { FlashSaleService } from './flash-sale.service'
|
||||
import { CreateFlashSaleDto } from './dto/create-flash-sale.dto'
|
||||
import { UpdateFlashSaleDto } from './dto/update-flash-sale.dto'
|
||||
|
||||
@Controller('admin/flash-sales')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
export class FlashSaleAdminController {
|
||||
constructor(private readonly flashSaleService: FlashSaleService) {}
|
||||
|
||||
/** POST /admin/flash-sales — create */
|
||||
@Post()
|
||||
create(
|
||||
@Body(new ValidationPipe({ whitelist: true })) dto: CreateFlashSaleDto,
|
||||
) {
|
||||
return this.flashSaleService.createFlashSale(dto)
|
||||
}
|
||||
|
||||
/** GET /admin/flash-sales — list (paginated) */
|
||||
@Get()
|
||||
list(
|
||||
@Query('page') page?: string,
|
||||
@Query('limit') limit?: string,
|
||||
) {
|
||||
return this.flashSaleService.getAdminFlashSales(
|
||||
page ? parseInt(page, 10) : 1,
|
||||
limit ? parseInt(limit, 10) : 20,
|
||||
)
|
||||
}
|
||||
|
||||
/** GET /admin/flash-sales/:id — detail */
|
||||
@Get(':id')
|
||||
detail(@Param('id') id: string) {
|
||||
return this.flashSaleService.getFlashSaleDetail(id)
|
||||
}
|
||||
|
||||
/** PUT /admin/flash-sales/:id — update */
|
||||
@Put(':id')
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body(new ValidationPipe({ whitelist: true })) dto: UpdateFlashSaleDto,
|
||||
) {
|
||||
return this.flashSaleService.updateFlashSale(id, dto)
|
||||
}
|
||||
|
||||
/** DELETE /admin/flash-sales/:id — delete (DRAFT only) */
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.flashSaleService.deleteFlashSale(id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user