package com.Controller;

import com.Domain.User;
import com.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lqt
 */
@RestController
public class Controller {

    @Autowired
    UserService userService;

    @RequestMapping("insertUser")
    public void save(@RequestBody User user) {
        userService.insertUser(user);
    }

    @RequestMapping("insertUserNoObject")
    public void insertUserNoObject(@RequestBody User user) {
        userService.insertUserNoObject(user);
    }

    @GetMapping("insert")
    public void transactionTestWithInsert() {
        userService.insert();
    }

    @GetMapping("select")
    public ResponseEntity transactionTestWithSelect() {

        return ResponseEntity.ok(userService.findUser().size());

    }

    @GetMapping("selectByOne")
    public ResponseEntity transactionTestWithSelectByOne() {
        String name = "pop0";
        return ResponseEntity.ok(userService.selectUserByUsername(name).size());

    }


    @GetMapping("selectOne")
    public void selectUser() {
        String name = "username";
        String password = "123";
        User user = userService.selectUser(name, password);
        System.out.println(user);
    }
}
