package com.ym.mec.web.controller.education;

import com.ym.mec.biz.dal.entity.PhotoAlbum;
import com.ym.mec.biz.dal.page.PhotoQueryInfo;
import com.ym.mec.biz.service.PhotoAlbumService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.List;

@RequestMapping("eduPhotoAlbum")
@Api(tags = "相册")
@RestController
public class EduPhotoAlbumController extends BaseController {

	@Autowired
	private PhotoAlbumService photoAlbumService;

	@ApiOperation("新增")
	@PostMapping(value = "add")
	public Object add(PhotoAlbum photoAlbum) {
		if(StringUtils.isEmpty(photoAlbum.getCoverUrl())){
			photoAlbum.setCoverUrl("https://daya.ks3-cn-beijing.ksyun.com/202107/Sdmx7vx.png");
		}
		return succeed(photoAlbumService.insert(photoAlbum));
	}

	@ApiOperation("修改")
	@PostMapping(value = "batchUpdate")
	public Object batchUpdate(@RequestBody List<PhotoAlbum> photoAlbumList) {
		photoAlbumService.batchUpdate(photoAlbumList);
		return succeed();
	}

	@ApiOperation("删除")
	@PostMapping(value = "del")
	public Object del(String ids) {
		photoAlbumService.batchDelete(ids);
		return succeed();
	}

	@ApiOperation("分页查询")
	@PostMapping(value = "queryPage")
	public Object queryPage(PhotoQueryInfo queryInfo) {
		return succeed(photoAlbumService.queryAlbumPage(queryInfo));
	}
}
