fix Trackerservice
Change-Id: Id041d972cab72183d2677f98f95d72d9d7d83793
diff --git a/src/main/java/com/example/g8backend/controller/UserController.java b/src/main/java/com/example/g8backend/controller/UserController.java
index 4bffa3c..2665b4c 100644
--- a/src/main/java/com/example/g8backend/controller/UserController.java
+++ b/src/main/java/com/example/g8backend/controller/UserController.java
@@ -3,52 +3,25 @@
import com.example.g8backend.entity.User;
import com.example.g8backend.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
-import java.util.List;
-
@RestController
-@RequestMapping("/users")
+@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
- // 获取所有用户
+ // 获取已登录的用户信息
@GetMapping
- public List<User> getUsers() {
- return userService.list();
- }
-
- // 通过ID获取用户
- @GetMapping("/{id}")
- public User getUserById(@PathVariable Long id) {
- return userService.getById(id);
- }
-
- // 通过用户名获取用户
- @GetMapping("/name/{name}")
- public User getUserByName(@PathVariable String name) {
- return userService.getUserByName(name);
- }
-
- // 添加用户
- @PostMapping
- public void addUser(@RequestBody User user) {
-// return userService.save(user);
- userService.registerUser(user);
- }
-
- // 修改用户
- @PutMapping
- public boolean updateUser(@RequestBody User user) {
- return userService.updateById(user);
- }
-
- // 删除用户
- @DeleteMapping("/{id}")
- public boolean deleteUser(@PathVariable Long id) {
- return userService.removeById(id);
+ public ResponseEntity<?> getUserInfo(){
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ long userId = (long) authentication.getPrincipal();
+ User user = userService.getById(userId);
+ user.setPassword(null);
+ return ResponseEntity.ok(user);
}
}
-