package cc.ryanc.halo.web.controller.api;


import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.model.request.UserR;
import cc.ryanc.halo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * <pre>
 *     用户API
 * </pre>
 *
 * @author : RYAN0UP
 * @date : 2018/6/6
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/api/user")
public class ApiUserController {

    @Autowired
    private UserService userService;

    /**
     * 获取博主信息
     *
     * @return JsonResult
     */
    @GetMapping
    public JsonResult user() {
        final User user = userService.findUser();
        return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(),
                ResponseStatusEnum.SUCCESS.getMsg(), user);
    }

    @PostMapping("/login")
    public JsonResult login(@RequestBody UserR user) {
        return userService.login(user);
    }


    @GetMapping("/siteInfo")
    public JsonResult siteInfo() {
        return userService.getSiteInfo();
    }


}
