package com.springboot.cloud.sysadmin.organization.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.sysadmin.organization.exception.UserNotFoundException;
import com.springboot.cloud.sysadmin.organization.service.UserService;
import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/getUserByUsernameOrMobile")
    public Result getUserByUsername(@RequestParam("payload")String payload){
        Optional.ofNullable(payload).orElseThrow(UserNotFoundException::new);
        return Result.success(userService.getUserByUsernameOrMobile(payload));
    }

}