You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.aurora.controller;
import com.aurora.annotation.OptLog;
import com.aurora.model.dto.TalkAdminDTO;
import com.aurora.model.dto.TalkDTO;
import com.aurora.enums.FilePathEnum;
import com.aurora.model.vo.ResultVO;
import com.aurora.service.TalkService;
import com.aurora.strategy.context.UploadStrategyContext;
import com.aurora.model.vo.ConditionVO;
import com.aurora.model.dto.PageResultDTO;
import com.aurora.model.vo.TalkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
import static com.aurora.constant.OptTypeConstant.*;
@Api(tags = "说说模块")
@RestController
public class TalkController {
@Autowired
private TalkService talkService;//说说业务逻辑
@Autowired
private UploadStrategyContext uploadStrategyContext;//文件上传服务
@ApiOperation(value = "查看说说列表")//用于前端展示,普通用户可查看
@GetMapping("/talks")
public ResultVO<PageResultDTO<TalkDTO>> listTalks() {
return ResultVO.ok(talkService.listTalks());
}
@ApiOperation(value = "根据id查看说说")
@ApiImplicitParam(name = "talkId", value = "说说id", required = true, dataType = "Integer")
@GetMapping("/talks/{talkId}")
//返回指定ID的说说详情
public ResultVO<TalkDTO> getTalkById(@PathVariable("talkId") Integer talkId) {
return ResultVO.ok(talkService.getTalkById(talkId));
}
@OptLog(optType = UPLOAD)
@ApiOperation(value = "上传说说图片")
@ApiImplicitParam(name = "file", value = "说说图片", required = true, dataType = "MultipartFile")
@PostMapping("/admin/talks/images")
public ResultVO<String> saveTalkImages(MultipartFile file) {
//调用方法,传入图片文件和说说图片的存储路径枚举,完成上传后包装路径返回
return ResultVO.ok(uploadStrategyContext.executeUploadStrategy(file, FilePathEnum.TALK.getPath()));
}
@OptLog(optType = SAVE_OR_UPDATE)
@ApiOperation(value = "保存或修改说说")
@PostMapping("/admin/talks")
public ResultVO<?> saveOrUpdateTalk(@Valid @RequestBody TalkVO talkVO) {
talkService.saveOrUpdateTalk(talkVO);
return ResultVO.ok();
}
@OptLog(optType = DELETE)//记录删除说说的相关日志
@ApiOperation(value = "删除说说")
@DeleteMapping("/admin/talks")
public ResultVO<?> deleteTalks(@RequestBody List<Integer> talkIds) {
talkService.deleteTalks(talkIds);
return ResultVO.ok();
}
@ApiOperation(value = "查看后台说说")//获取后台管理用的说说分页列表
@GetMapping("/admin/talks")
public ResultVO<PageResultDTO<TalkAdminDTO>> listBackTalks(ConditionVO conditionVO) {
return ResultVO.ok(talkService.listBackTalks(conditionVO));
}
@ApiOperation(value = "根据id查看后台说说")//查看指定ID的后台说说详情包含管理相关的信息
@ApiImplicitParam(name = "talkId", value = "说说id", required = true, dataType = "Integer")
@GetMapping("/admin/talks/{talkId}")
public ResultVO<TalkAdminDTO> getBackTalkById(@PathVariable("talkId") Integer talkId) {
return ResultVO.ok(talkService.getBackTalkById(talkId));
}
}