package com.sysu.admin.site;


import com.sysu.admin.controller.crop.images.CropImage;
import com.sysu.admin.controller.crop.images.CropImageService;
import com.xiesx.fastboot.base.result.BaseResult;
import com.xiesx.fastboot.base.result.R;
import com.xiesx.fastboot.core.token.annotation.GoToken;
import com.xiesx.fastboot.core.token.handle.CurrentToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/site/crop_image")
public class SiteCropImageController {

    @Autowired
    CropImageService cropImageService;

    @RequestMapping("/view")
    public BaseResult view(@RequestBody CommonVo commonVo, @GoToken CurrentToken currentToken){
        List<CropImage> cropImageList = cropImageService.findByCropId(commonVo.getId());
        Map<String ,CropImage> res = new HashMap(3);
        cropImageList.stream().forEach(cropImage -> {
            switch (CropImage.getImageType(cropImage.getType())){
                case fay:
                    res.put("fay",cropImage);
                    break;
                case center:
                    res.put("center",cropImage);
                    break;
                case near:
                    res.put("near",cropImage);
                    break;
            }
        });
        return R.succ(res);
    }


}
