78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
package com.example.springdemo.controller;
|
|
|
|
import com.example.springdemo.entities.Users;
|
|
import com.example.springdemo.entities.password.UsersPassword;
|
|
import com.example.springdemo.service.UsersService;
|
|
import com.example.springdemo.utils.RoleVerificationAnnotation;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Optional;
|
|
|
|
@RestController
|
|
@RequestMapping("/users")
|
|
public class UsersController {
|
|
|
|
@Resource
|
|
private UsersService usersService;
|
|
|
|
//添加新用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@PostMapping("/add")
|
|
public Users addUsers(@RequestBody UsersPassword usersPassword,
|
|
@RequestBody Users users) {
|
|
return usersService.addUsers(users, usersPassword);
|
|
}
|
|
|
|
//通过ID删除用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@DeleteMapping("/delete/{userID}")
|
|
public void deleteUsers(@PathVariable(name = "userID") Long userID) {
|
|
usersService.deleteUsersById(userID);
|
|
}
|
|
|
|
//通过姓名删除用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@DeleteMapping("/delete/{name}")
|
|
public void deleteUsers(@PathVariable(name = "name") String name) {
|
|
usersService.deleteUsersByName(name);
|
|
}
|
|
|
|
//更新用户信息
|
|
@RoleVerificationAnnotation(RoleIDList = {1, 3}, UserIDList = {1})
|
|
@PutMapping("/update/info")
|
|
public Users updateUsers(@RequestBody Users users) {
|
|
return usersService.updateUsers(users);
|
|
}
|
|
|
|
//查找全部用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@GetMapping("/find")
|
|
public Iterable<Users> getUsers() {
|
|
return usersService.findAllUsers();
|
|
}
|
|
|
|
//根据姓名查找用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@GetMapping("/find/{name}")
|
|
public Users getUsersByName(@PathVariable(name = "name") String name) {
|
|
return usersService.findByName(name);
|
|
}
|
|
|
|
//根据ID查找用户
|
|
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
|
|
@GetMapping("/find/{id}")
|
|
public Users getUsersById(@PathVariable(name = "id") Long userID) {
|
|
return usersService.findById(userID);
|
|
}
|
|
|
|
//更新用户密码
|
|
@RoleVerificationAnnotation(RoleIDList = {1, 3}, UserIDList = {1})
|
|
@PutMapping("/update/password")
|
|
public void updatePassword(@RequestParam(name = "password") String password,
|
|
@RequestParam(name = "userID") Long userID) {
|
|
usersService.updatePassword(password, userID);
|
|
}
|
|
|
|
}
|