2025-03-15 21:49:52 +03:00

26 lines
883 B
Kotlin

package com.dowstats.controllers
import com.dowstats.data.entities.User
import com.dowstats.service.user.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import jakarta.servlet.http.HttpServletRequest
@RestController
@RequestMapping("api/v1/user")
@EnableWebSecurity
class UserController @Autowired constructor(
val userService: UserService,
) {
@GetMapping
@PreAuthorize("hasAnyAuthority('USER')")
fun getCurrentUser(req: HttpServletRequest): User {
return userService.getCurrentUser()
}
}