
package com.tmerclub.cloud.user.controller.app;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.user.model.UserExtension;
import com.tmerclub.cloud.user.service.UserExtensionService;
import com.tmerclub.cloud.user.vo.UserExtensionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户扩展信息
 *
 * @author YXF
 * @date 2020-12-08 10:16:53
 */
@RestController("appUserExtensionController")
@RequestMapping("/userExtension")
@Tag(name = "app-用户扩展信息")
public class UserExtensionController {

    @Autowired
    private UserExtensionService userExtensionService;


    @GetMapping("/page")
    @Operation(summary = "获取用户扩展信息列表", description = "分页获取用户扩展信息列表")
    public ServerResponseEntity<PageVO<UserExtensionVO>> page(@Valid PageDTO pageDTO) {
        PageVO<UserExtensionVO> userExtensionPage = userExtensionService.page(pageDTO);
        return ServerResponseEntity.success(userExtensionPage);
    }

    @GetMapping("/getInfo")
    @Operation(summary = "获取用户扩展信息", description = "获取用户扩展信息")
    public ServerResponseEntity<UserExtensionVO> getInfo() {
        Long userId = AuthUserContext.get().getUserId();
        UserExtension userExtension = userExtensionService.getByUserId(userId);
        UserExtensionVO userExtensionVO = new UserExtensionVO();
        BeanUtils.copyProperties(userExtension, userExtensionVO);
        return ServerResponseEntity.success(userExtensionVO);
    }
}
