|
| 1 | +package cn.iocoder.springboot.lab24.apidoc.controller; |
| 2 | + |
| 3 | +import cn.iocoder.springboot.lab24.apidoc.dto.UserAddDTO; |
| 4 | +import cn.iocoder.springboot.lab24.apidoc.dto.UserUpdateDTO; |
| 5 | +import cn.iocoder.springboot.lab24.apidoc.vo.UserVO; |
| 6 | +import io.swagger.annotations.Api; |
| 7 | +import io.swagger.annotations.ApiImplicitParam; |
| 8 | +import io.swagger.annotations.ApiOperation; |
| 9 | +import org.springframework.web.bind.annotation.*; |
| 10 | + |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.List; |
| 13 | +import java.util.UUID; |
| 14 | + |
| 15 | +@RestController |
| 16 | +@RequestMapping("/users") |
| 17 | +@Api(tags = "用户 API 接口") |
| 18 | +public class UserController { |
| 19 | + |
| 20 | + @GetMapping("/list") |
| 21 | + @ApiOperation(value = "查询用户列表", notes = "目前仅仅是作为测试,所以返回用户全列表") |
| 22 | + public List<UserVO> list() { |
| 23 | + // 查询列表 |
| 24 | + List<UserVO> result = new ArrayList<>(); |
| 25 | + result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); |
| 26 | + result.add(new UserVO().setId(2).setUsername("woshiyutou")); |
| 27 | + result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); |
| 28 | + // 返回列表 |
| 29 | + return result; |
| 30 | + } |
| 31 | + |
| 32 | + @GetMapping("/get") |
| 33 | + @ApiOperation("获得指定用户编号的用户") |
| 34 | + @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query", dataTypeClass = Integer.class, required = true, example = "1024") |
| 35 | + public UserVO get(@RequestParam("id") Integer id) { |
| 36 | + // 查询并返回用户 |
| 37 | + return new UserVO().setId(id).setUsername(UUID.randomUUID().toString()); |
| 38 | + } |
| 39 | + |
| 40 | + @PostMapping("add") |
| 41 | + @ApiOperation("添加用户") |
| 42 | + public Integer add(UserAddDTO addDTO) { |
| 43 | + // 插入用户记录,返回编号 |
| 44 | + Integer returnId = UUID.randomUUID().hashCode(); |
| 45 | + // 返回用户编号 |
| 46 | + return returnId; |
| 47 | + } |
| 48 | + |
| 49 | + @PostMapping("/update") |
| 50 | + @ApiOperation("更新指定用户编号的用户") |
| 51 | + public Boolean update(UserUpdateDTO updateDTO) { |
| 52 | + // 更新用户记录 |
| 53 | + Boolean success = true; |
| 54 | + // 返回更新是否成功 |
| 55 | + return success; |
| 56 | + } |
| 57 | + |
| 58 | + @PostMapping("/delete") |
| 59 | + @ApiOperation(value = "删除指定用户编号的用户") |
| 60 | + @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query", dataTypeClass = Integer.class, required = true, example = "1024") |
| 61 | + public Boolean delete(@RequestParam("id") Integer id) { |
| 62 | + // 删除用户记录 |
| 63 | + Boolean success = false; |
| 64 | + // 返回是否更新成功 |
| 65 | + return success; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments