import { Controller , Get , Query , Post , Put , Delete , Param , UseInterceptors , UploadedFiles , Logger , UploadedFile , Body } from "@nestjs/common" ; import { Tags } from "nest-swagger" ; import { MediaService } from "./media.service" ; import { CreateMediaDto , MediaRes , EditMediaDto , UploadRes , UploadMultipleRes , MediaFile } from "../dto" ; import { NullableParseIntPipe , ResultList , KeyValue } from "nestx-common" ; import { Media } from "../interfaces" ; import { FilesInterceptor , FileInterceptor } from "@nestjs/platform-express" ; @ Tags ( "cms" ) @ Controller ( "media" ) export class MediaController { constructor ( private readonly service ) { } @ Get ( "search" ) async search ( @ Query ( "keyword" ) keyword ? , @ Query ( "value" ) value ? ) { return this . service . search ( keyword , value ) ; } @ Post ( "upload" ) @ UseInterceptors ( FileInterceptor ( "file" ) ) async uploadFile ( @ UploadedFile ( ) file ) { return { ok : true , file : file . path } ; } @ Post ( "uploads" ) @ UseInterceptors ( FilesInterceptor ( "files" ) ) async uploadFiles ( @ UploadedFiles ( ) files ? ) { const fileNames = ( files || [ ] ) . map ( item => item . path ) ; return { ok : true , files : fileNames } ; } @ Post ( ) async create ( @ Body ( ) entry ) { return this . service . create ( entry ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . service . update ( entry ) ; } @ Get ( "query" ) async query ( @ Query ( "keyword" ) keyword ? , @ Query ( "page" , new NullableParseIntPipe ( ) ) page = 1 , @ Query ( "size" , new NullableParseIntPipe ( ) ) size = 10 , @ Query ( "sort" ) sort ? ) { return this . service . querySearch ( keyword , page , size , sort ) ; } @ Delete ( ":id" ) async remove ( @ Param ( "id" ) id ) { return this . service . remove ( id ) ; } @ Get ( ":id" ) async findOne ( @ Param ( "id" ) id ) { return this . service . findById ( id ) ; } }