package com.jiayue.ipfcst.fileupload.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.UploadURL;
import com.jiayue.ipfcst.fileupload.service.UploadURLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UploadURLController {
  @Autowired
  private UploadURLService uploadURLService;

  @GetMapping("/uploadURL/{uploadChannelId}")
  @Transactional
  public ResponseVO findByUploadChannelId(@PathVariable Integer uploadChannelId){
    List<UploadURL> byUploadCahnnelId = uploadURLService.findByUploadCahnnelId(uploadChannelId);

    return ResponseVO.success(byUploadCahnnelId);
  }

  @PostMapping("/uploadURL")
  @Transactional
  public ResponseVO save(@RequestBody UploadURL uploadURL){
    uploadURLService.save(uploadURL);
    return ResponseVO.success();
  }


  @DeleteMapping("/uploadURL/{id}")
  @Transactional
  public ResponseVO delete(@PathVariable Integer id){

    uploadURLService.deleteByChannelId(id);
    return ResponseVO.success();
  }


}
