package pl.sudra.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pl.sudra.domain.AppUser;
import pl.sudra.repository.AppUserRepository;

import java.util.List;

@RestController
@RequestMapping("appUserRest")
public class AppUserRESTController {
    private AppUserRepository appUserRepository;

    @Autowired
    public AppUserRESTController(AppUserRepository appUserRepository) {
        this.appUserRepository = appUserRepository;
    }

    @GetMapping(value = "/{login}", produces = MediaType.APPLICATION_JSON_VALUE)
    public AppUser getAppUserInJSON(@PathVariable String login) {
        return appUserRepository.findByLogin(login);
    }

    @GetMapping(value = "/{login}.xml", produces = MediaType.APPLICATION_XML_VALUE)
    public AppUser getAppUserInXML(@PathVariable String login) {
        return appUserRepository.findByLogin(login);
    }

    @GetMapping
    public ResponseEntity<List<AppUser>> getAll() {
        return new ResponseEntity<>(appUserRepository.findAll(), HttpStatus.OK);
    }
}
