package org.sky.core.log.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import org.sky.core.log.model.LogApi;
import org.sky.core.log.pojo.vo.LogApiVO;
import org.sky.core.log.service.ILogApiService;
import org.sky.core.log.wrapper.LogApiWrapper;
import org.sky.core.mp.support.Condition;
import org.sky.core.mp.support.Query;
import org.sky.core.tenant.annotation.NonDS;
import org.sky.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 控制器
 *
 */
@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("/api")
public class LogApiController {

	private final ILogApiService logService;

	/**
	 * 查询单条
	 */
//	@IsAdmin
	@GetMapping("/detail")
	public R<LogApi> detail(LogApi log) {
		return R.data(logService.getOne(Condition.getQueryWrapper(log)));
	}

	/**
	 * 查询多条(分页)
	 */
//	@IsAdmin
	@GetMapping("/list")
	public R<IPage<LogApiVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> log, Query query) {
		IPage<LogApi> pages = logService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(log, LogApi.class));
		return R.data(LogApiWrapper.build().pageVO(pages));
	}

}
