package com.jsc.oscm.controller;

import com.alibaba.fastjson.JSON;
import com.jsc.oscm.model.ReturnT;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;


@RestController
public class UserController {

    @GetMapping("/user")
    public String getUserInfo(HttpServletRequest request) {
        ReturnT<String> returnT;
        Principal principal = request.getUserPrincipal();
        returnT = new ReturnT<>(200, "", principal.getName());
        return JSON.toJSONString(returnT);
    }

    @GetMapping("/user/alive")
    public String isUserAlive() {
        ReturnT<String> returnT;
        returnT = new ReturnT<>(200, "", "");
        return JSON.toJSONString(returnT);
    }
}
