package com.hotent.uc.controller;

import com.alibaba.fastjson.JSONObject;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.util.BeanUtils;
import com.hotent.uc.manager.UcCustomManager;
import com.hotent.uc.model.CustomUser;
import com.hotent.uc.service.CustomManagerDetailsServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/custom/v1/")
@Api(tags="用户管理")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class CustomController extends BaseController<UcCustomManager, CustomUser> {

    @Autowired
    CustomManagerDetailsServiceImpl customManagerDetailsService;

    @RequestMapping(value="/loadCustomByCustomKey",method= RequestMethod.POST, produces = { "application/json; charset=utf-8" })
    public JSONObject loadCustomByCustomKey(@RequestParam(required=true) String customKey){
        if(BeanUtils.isEmpty(customManagerDetailsService.loadUserByUsername(customKey))){
            return JSONObject.parseObject("{\"code\":\"404\",\"msg\":\"用户不存在\"}");
        }
        return JSONObject.parseObject(JSONObject.toJSONString(customManagerDetailsService.loadUserByUsername(customKey)));
    }
}
