package org.springblade.app.controller;

import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.estate.dto.NoticeDTO;
import org.springblade.estate.entity.Feedback;
import org.springblade.estate.entity.Notice;
import org.springblade.estate.feign.IFeedbackClient;
import org.springblade.estate.feign.INoticeClient;
import org.springblade.system.expand.feign.IConfClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;


/**
 * @author cy-computer
 */
@RestController
@RequestMapping("/app/feedback")
@RequiredArgsConstructor
public class FeedbackController {


	private final IFeedbackClient feedbackClient;
	private final IConfClient confClient;


	@PostMapping(value = "/submit")
	public R submit(@RequestBody Feedback feedback){
		String images = feedback.getImages();
		if (StrUtil.isNotBlank(images)) {
			List<String> urls = Arrays.asList(images.split(","));
			for (int i = 0; i < urls.size(); i++) {
				String url = urls.get(i);
				url = confClient.removePrefix(url);
				urls.set(i, url);
			}
		}
		return R.status(feedbackClient.submit(feedback));
	}
}
