package org.ta.resourceserver.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class BusinessController {

    // 示例接口：获取用户信息（从网关传递的请求头中获取）
    @GetMapping("/user/info")
    public String getUserInfo(
            @RequestHeader("X-User-Name") String userName,
            @RequestHeader("X-User-Roles") String roles
    ) {
        return String.format(
                "{\n" +
                        "  \"username\": \"%s\",\n" +
                        "  \"roles\": %s,\n" +
                        "  \"message\": \"请求通过网关鉴权，业务接口正常返回\"\n" +
                        "}",
                userName, roles
        );
    }
}