package com.qmth.ops.aliyun.controller;

import com.qmth.ops.aliyun.utils.SlsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author luoshi
 * @date 2019/3/23 09:54
 */
@RestController
@RequestMapping("/api/sls")
@CrossOrigin
public class SlsController {

    @Autowired
    private SlsService slsService;

    @RequestMapping("/project")
    public Mono<Object> list() {
        return Mono.just(slsService.getProject());
    }

    @PostMapping("/view")
    public Mono<String> view(ServerWebExchange exchange) {
        return exchange.getFormData().flatMap(form -> {
            return slsService.view(form.getFirst("project"), form.getFirst("store"));
        });
    }
}
