package cc.mrbird.febs.mall.controller;
|
|
import cc.mrbird.febs.common.annotation.ControllerEndpoint;
|
import cc.mrbird.febs.common.controller.BaseController;
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.entity.QueryRequest;
|
import cc.mrbird.febs.mall.dto.MallNewsInfoDto;
|
import cc.mrbird.febs.mall.entity.MallNewsCategory;
|
import cc.mrbird.febs.mall.entity.MallNewsInfo;
|
import cc.mrbird.febs.mall.service.IMallNewsInfoService;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.management.Query;
|
import javax.validation.Valid;
|
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author wzy
|
* @date 2022-05-13
|
**/
|
@Slf4j
|
@Validated
|
@RestController
|
@RequiredArgsConstructor
|
@RequestMapping(value = "/admin/news")
|
public class AdminNewsInfoController extends BaseController {
|
|
private final IMallNewsInfoService mallNewsInfoService;
|
|
/**
|
* 新闻中心-列表
|
* @param mallNewsInfo
|
* @param request
|
* @return
|
*/
|
@GetMapping("getNewInfoList")
|
public FebsResponse getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) {
|
Map<String, Object> data = getDataTable(mallNewsInfoService.getNewInfoList(mallNewsInfo, request));
|
return new FebsResponse().success().data(data);
|
}
|
|
/**
|
* 新闻中心-新增
|
*/
|
@PostMapping("addNewsInfo")
|
@ControllerEndpoint(operation = " 新闻中心-新增", exceptionMessage = "操作失败")
|
public FebsResponse addNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
|
return mallNewsInfoService.addNewsInfo(mallNewsInfoDto);
|
}
|
|
/**
|
* 新闻中心-删除
|
*/
|
@GetMapping("delNewsInfo/{id}")
|
@ControllerEndpoint(operation = " 新闻中心-删除", exceptionMessage = "操作失败")
|
public FebsResponse delNewsInfo(@NotNull(message = "{required}") @PathVariable Long id) {
|
return mallNewsInfoService.delNewsInfo(id);
|
}
|
|
/**
|
* 新闻中心-更新
|
*/
|
@PostMapping("updateNewsInfo")
|
@ControllerEndpoint(operation = "新闻中心-更新", exceptionMessage = "操作失败")
|
public FebsResponse updateNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
|
return mallNewsInfoService.updateNewsInfo(mallNewsInfoDto);
|
}
|
|
|
@GetMapping("findNewsCategoryList")
|
@ControllerEndpoint(operation = "新闻分类列表", exceptionMessage = "获取失败")
|
public FebsResponse findNewsCategoryList(MallNewsCategory mallNewsCategory, QueryRequest request) {
|
return new FebsResponse().success().data(getDataTable(mallNewsInfoService.findNewsCategoryInPage(mallNewsCategory, request)));
|
}
|
|
@PostMapping("addOrModifyNewsCategory")
|
@ControllerEndpoint(operation = "新闻分类", exceptionMessage = "新增失败")
|
public FebsResponse addOrModifyNewsCategory(MallNewsCategory mallNewsCategory) {
|
mallNewsInfoService.addOrModifyNewsCategory(mallNewsCategory);
|
return new FebsResponse().success().message("新增成功");
|
}
|
|
@GetMapping(value = "findAllCategoryList")
|
public FebsResponse findAllCategoryList() {
|
List<MallNewsCategory> categories = mallNewsInfoService.findAllCategory();
|
return new FebsResponse().success().data(categories);
|
}
|
|
@PostMapping(value = "/topNews/{id}")
|
public FebsResponse topNews(@PathVariable Long id) {
|
MallNewsInfo mallNewsInfo = new MallNewsInfo();
|
mallNewsInfo.setIsTop(1);
|
mallNewsInfo.setId(id);
|
mallNewsInfoService.updateById(mallNewsInfo);
|
return new FebsResponse().success();
|
}
|
|
@PostMapping(value = "/unTopNews/{id}")
|
public FebsResponse unTopNews(@PathVariable Long id) {
|
MallNewsInfo mallNewsInfo = new MallNewsInfo();
|
mallNewsInfo.setIsTop(2);
|
mallNewsInfo.setId(id);
|
mallNewsInfoService.updateById(mallNewsInfo);
|
return new FebsResponse().success();
|
}
|
}
|