1.uniform response status code for tag component

main
Gary 1 year ago
parent a29d8b9bc1
commit 91a8962550

@ -1,13 +1,12 @@
package com.luoo.tag.client;
import entity.Result;
import api.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
@FeignClient("luoo-user")
public interface UserClient {
@RequestMapping(value = "/admin",method= RequestMethod.GET)
@GetMapping("/admin")
public Result findAll();
}

@ -1,8 +1,8 @@
package com.luoo.tag.controller;
import exception.BizException;
import entity.Result;
import entity.StatusCode;
import api.Result;
import api.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ -16,15 +16,15 @@ public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result error(Exception e){
public Result<Void> error(Exception e){
log.error("执行出错", e);
return new Result(false, StatusCode.ERROR, "执行出错");
return Result.failed(StatusCode.TAG_COMMON_FAILED);
}
@ExceptionHandler(value = BizException.class)
@ResponseBody
public Result error(BizException e){
public Result<String> error(BizException e){
log.info("业务错误:{}", e.getMessage());
return new Result(false, StatusCode.ERROR, e.getMessage());
return Result.failed(StatusCode.TAG_COMMON_FAILED, e.getMessage());
}
}

@ -5,7 +5,7 @@ import com.luoo.tag.pojo.TagDTO;
import com.luoo.tag.pojo.TagQueryReq;
import com.luoo.tag.pojo.TagUpdateReq;
import com.luoo.tag.service.TagService;
import entity.ResultVO;
import api.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
@ -32,23 +32,23 @@ public class TagController {
@ApiImplicitParam(name = "pageNum", value = "页码", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页数", required = true) })
@GetMapping("/list")
public ResultVO<Page<TagDTO>> getById(@Validated TagQueryReq queryReq) {
return ResultVO.success(tagService.queryPage(queryReq));
public Result<Page<TagDTO>> getById(@Validated TagQueryReq queryReq) {
return Result.success(tagService.queryPage(queryReq));
}
@ApiOperation(value = "查询标签详情", notes = "查询标签详情")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@GetMapping("/{id}")
public ResultVO<TagDTO> getById(@PathVariable String id) {
return ResultVO.success(tagService.queryById(id));
public Result<TagDTO> getById(@PathVariable String id) {
return Result.success(tagService.queryById(id));
}
@ApiOperation(value = "新增标签信息", notes = "新增标签信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "createReq", value = "创建参数", required = true) })
@PostMapping
public ResultVO<Void> create(@Validated @RequestBody TagCreateReq createReq) {
public Result<Void> create(@Validated @RequestBody TagCreateReq createReq) {
tagService.create(createReq);
return ResultVO.success("创建成功");
return Result.success();
}
@ApiOperation(value = "更新标签信息", notes = "更新标签信息")
@ -56,10 +56,10 @@ public class TagController {
@ApiImplicitParam(name = "updateReq", value = "更新参数", required = true),
@ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@PutMapping("/{id}")
public ResultVO<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) {
public Result<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) {
updateReq.setId(id);
tagService.update(updateReq);
return ResultVO.success("更新成功");
return Result.success();
}
@ApiOperation(value = "更新标签状态", notes = "更新标签状态")
@ -67,16 +67,16 @@ public class TagController {
@ApiImplicitParam(name = "id", value = "标签ID", required = true),
@ApiImplicitParam(name = "state", value = "标签状态", required = true) })
@PutMapping("/status/{id}")
public ResultVO<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) {
public Result<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) {
tagService.updateState(id, state);
return ResultVO.success("状态更新成功");
return Result.success();
}
@ApiOperation(value = "删除标签", notes = "删除标签")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@DeleteMapping("/{id}")
public ResultVO<Void> delete(@PathVariable String id) {
public Result<Void> delete(@PathVariable String id) {
tagService.delete(id);
return ResultVO.success("删除成功");
return Result.success();
}
}

Loading…
Cancel
Save