package com.crm.custom.controller;

import com.crm.custom.service.CommonService;
import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: houn
 */
@RestController
@RequestMapping("/finance/file")
public class FinanceController extends BaseLoginController {
    @Autowired
    private CommonService commonService;

    @PostMapping("/upload")
    public BaseResultDto upload(@RequestParam(value = "file", required = false) MultipartFile file,
                                CustomInfoEntity infoEntity) throws Exception {
        String middlePath = "/" + infoEntity.getId() + "/finance/file";

        commonService.validated(file);
        String path = commonService.uploadFile(middlePath, file);

        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);
    }

}
