package com.nisemoe.nise.controller

import com.nisemoe.nise.service.AuthService
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class AuthController(
    private val authService: AuthService
) {

    @GetMapping("/auth", produces = [MediaType.APPLICATION_JSON_VALUE])
    fun getUser(): ResponseEntity<AuthService.UserInfo> {
        if(!this.authService.isLoggedIn())
            return ResponseEntity.status(401).build()

        val currentUser = this.authService.getCurrentUser()
        return ResponseEntity.ok(currentUser)
    }

}
