package me.zhengjie.modules.dm.video.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.domain.LocalStorage;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.dm.video.domain.DmVideo;
import me.zhengjie.modules.dm.video.service.DmVideoService;
import me.zhengjie.modules.dm.video.service.dto.DmVideoQueryCriteria;
import me.zhengjie.utils.FileUtil;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
@Api(tags = "IOT餐饮系统-首页视频管理")
@RequestMapping("/api/dmVideo")
public class DmVideoController {
    private final DmVideoService dmVideoService;

    @GetMapping(value = "getVideo")
    @Log("查询video")
    @ApiOperation("查询video")
    public ResponseEntity<Object> query(){
        return new ResponseEntity<>(dmVideoService.queryAll(null), HttpStatus.OK);
    }

    @PostMapping("/pictures")
    @ApiOperation("上传图片")
    public ResponseEntity<Object> upload(@RequestParam MultipartFile file){
        // 判断文件是否为图片
        String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
        if(!FileUtil.VIDEO.equals(FileUtil.getFileType(suffix))){
            throw new BadRequestException("只能上传视频");
        }
        DmVideo video = dmVideoService.create(null, file);
        return new ResponseEntity<>(video, HttpStatus.OK);
    }

}
