package com.bocloud.ims.booter.controller.resource.storage;

import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.entity.resource.Disk;
import com.bocloud.ims.interfaces.resource.DiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author luyanchao
 * @since 2019/6/12
 */
@RestController
@RequestMapping("/v1/storages/disks")
@Api(value = "磁盘", tags = "磁盘")
public class DiskController {

	@Autowired
	private DiskService diskService;

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询磁盘列表",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "磁盘", operation = "查询磁盘列表")
	@GetMapping
	public BocloudResult<GridBean<Disk>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return diskService.list(pager, context);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改磁盘",  httpMethod = "PUT")
	@Log(module = BoCloudService.IMS, target = "磁盘", operation = "修改磁盘")
	@PutMapping("/{id}")
	public BocloudResult<Disk> modify(@PathVariable(value = Common.ID) long id, @RequestBody Disk disk,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		disk.setId(id);
		return diskService.modify(disk, context);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查看磁盘详情",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "磁盘", operation = "查看磁盘详情")
	@GetMapping("/{id}")
	public BocloudResult<Disk> detail(@PathVariable(value = Common.ID, required = true) Long diskId) {
		return diskService.detail(diskId);
	}

}
