All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.guerlab.smart.article.web.controller.user.ArticleConfigController Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2018-2021 guerlab.net and other contributors.
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.guerlab.smart.article.web.controller.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.guerlab.smart.article.core.PermissionConstants;
import net.guerlab.smart.article.service.service.ArticleConfigService;
import net.guerlab.smart.platform.commons.Constants;
import net.guerlab.smart.platform.commons.annotation.HasPermission;
import net.guerlab.smart.user.api.OperationLogApi;
import net.guerlab.smart.user.auth.UserContextHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Map;

/**
 * 文章配置
 *
 * @author guer
 */
@Tag(name = "文章配置")
@RestController("/user/articleConfig")
@RequestMapping("/user/articleConfig")
public class ArticleConfigController {

    private ArticleConfigService configService;

    private OperationLogApi operationLogApi;

    @Operation(description = "查询配置", security = @SecurityRequirement(name = Constants.TOKEN))
    @PostMapping
    public Map findMap(@RequestBody(required = false) Collection keys) {
        if (keys == null || keys.isEmpty()) {
            return configService.findAll();
        } else {
            return configService.findMap(keys);
        }
    }

    @HasPermission("hasKey(" + PermissionConstants.CONFIG_MANAGER + ")")
    @Operation(description = "保存配置", security = @SecurityRequirement(name = Constants.TOKEN))
    @PostMapping("/save")
    public Map save(@RequestBody Map configs) {
        configService.save(configs);
        Map result = configService.findMap(configs.keySet());
        operationLogApi.add("保存文章配置", UserContextHandler.getUserId(), configs);
        return result;
    }

    @Autowired
    public void setConfigService(ArticleConfigService configService) {
        this.configService = configService;
    }

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    public void setOperationLogApi(OperationLogApi operationLogApi) {
        this.operationLogApi = operationLogApi;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy