package com.template.controller;


import com.template.api.ActivityImageControllerAPI;
import com.template.common.utils.paramUtils;
import com.template.model.pojo.AlumniNews;
import com.template.model.request.updateAlumniNewsRequest;
import com.template.model.result.CommonResult;
import com.template.services.AlumniNewsService;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ceshi
 * @since 2024-11-27
 */
@RestController
public class ActivityImageController implements ActivityImageControllerAPI {

    @Autowired
    private AlumniNewsService alumniNewsService;

    @Override
    public CommonResult updateAlumniImages(updateAlumniNewsRequest uanr, BindingResult bindingResult) {
        if (uanr == null) {
            return CommonResult.fail("参数不能为空");
        }

        if (bindingResult.hasErrors()) {
            String st = paramUtils.getParamError(bindingResult);
            return CommonResult.fail(st);
        }

        AlumniNews an = alumniNewsService.queryDataById(uanr.getId());
        an.setTheme(uanr.getTheme());
        String content = StringEscapeUtils.escapeHtml4(uanr.getContent());
        an.setContent(content);
        an.setCategoryId(uanr.getCategoryId());
        an.setCategoryName(uanr.getCategoryName());
        an.setUserId(uanr.getUserId());
        an.setUserName(uanr.getUserName());

        int result = alumniNewsService.updateAlumniNews(an);
        if (result <= 0) {
            return CommonResult.fail("新闻编辑失败");
        }

        return CommonResult.ok("新闻编辑成功");
    }
}

