package com.example.backend;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
@CrossOrigin(origins = "http://localhost:4200/")
public class Controller {

    @GetMapping()
    public List<User> allUsers(){
        List<User> allusers = new ArrayList<>();
        allusers.add(new User("pera", "peric"));
        allusers.add(new User("zika", "zikic"));
        return allusers;
    }

    @GetMapping("/getUser/{user}")
    public User getUser(@PathVariable String user){
        if(user.equals("pera")){
            return new User("pera", "peric");
        }
        else return null;
    }
}
