package io.github.qifan777.knowledge.config;


import io.github.qifan777.knowledge.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>
 *
 * </p>
 *
 * @author taohongrun
 * @since 2024/12/4
 */
@Configuration
public class MVCConfig implements WebMvcConfigurer {



    @Autowired
    RedisTemplate<String,String> redisTemplate;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ValueOperations<String,String> valueOperations = redisTemplate.opsForValue();

        registry.addInterceptor(new LoginInterceptor(valueOperations))
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .order(2);
//        registry.addInterceptor(new RefreshInterceptor(hashOperations,redisTemplate))
//                .addPathPatterns("/**")
//                .order(1);
    }
}
