| package com.example.g8backend.controller; |
| 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.*; |
| public class UserController { |
| private IUserService userService; |
| public ResponseEntity<?> getUserInfo(){ |
| Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| long userId = (long) authentication.getPrincipal(); |
| User user = userService.getById(userId); |
| return ResponseEntity.ok(user); |