update
This commit is contained in:
@@ -4,9 +4,8 @@ import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.exception.BaseException;
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.json.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,16 +22,16 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user_api")
|
||||
@Api(value = "用户接口管理", tags = {"用户接口管理"})
|
||||
@Tag(name = "用户接口管理", description = "用户 CRUD API")
|
||||
public class RestUserController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RestUserController.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestUserController.class);
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
@PostMapping("/user")
|
||||
@ApiOperation("新增用户")
|
||||
@Operation(summary = "新增用户")
|
||||
public User save(@RequestBody User user) {
|
||||
User saveUser = usersService.insert(user);
|
||||
if (saveUser != null) {
|
||||
@@ -40,23 +39,17 @@ public class RestUserController {
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
@ApiOperation("删除用户")
|
||||
@Operation(summary = "删除用户")
|
||||
public Boolean delete(@PathVariable Integer id) {
|
||||
Boolean delete = true;
|
||||
usersService.remove(id);
|
||||
if (delete) {
|
||||
return delete;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@PutMapping("/user/{id}")
|
||||
@ApiOperation("修改用户")
|
||||
@Operation(summary = "修改用户")
|
||||
public User update(@RequestBody User user, @PathVariable Integer id) {
|
||||
User updateuser = usersService.update(user, id);
|
||||
if (updateuser != null) {
|
||||
@@ -67,19 +60,19 @@ public class RestUserController {
|
||||
}
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("获取用户")
|
||||
@Operation(summary = "获取用户")
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
User user = usersService.findOne(id);
|
||||
logger.info("获取用户==>:{}", JSONObject.valueToString(user));
|
||||
logger.info("获取用户==>:{}", user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("获取全部用户")
|
||||
public List<User> getUser(User user) {
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info("全部用户==>:{}", JSONObject.valueToString(userall));
|
||||
return userall;
|
||||
@Operation(summary = "获取全部用户")
|
||||
public List<User> getAllUsers() {
|
||||
return usersService.getAllList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user