package app.mealsmadeeasy.api;

import app.mealsmadeeasy.api.security.EndpointAuthConfigurator;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public final class GreetingController {

    @Component
    public static class GreetingEndpointAuthConfigurator implements EndpointAuthConfigurator {

        @Override
        public void configure(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
            registry.requestMatchers("/greeting").permitAll();
        }

    }

    @GetMapping("/greeting")
    @ResponseBody
    public String get() {
        return "Hello, World!";
    }

}
