package com.remy.user.controller;

import com.remy.user.entity.User;
import com.remy.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("users")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping
    public List<User> findAll(){
        return userService.findAll();
    }

    @PostMapping
    public User createUser(@RequestBody User user){
        return userService.save(user);
    }

    @GetMapping("{userId}")
    public User findById(@PathVariable("userId") Long userId){
        return userService.findByID(userId);
    }

    @GetMapping("query")
    public User query(@RequestParam("username") String username){
        return userService.findByUsername(username);
    }
}
