This commit is contained in:
parent
0bb789cfb9
commit
d61c096f69
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ProjectGrid.Data;
|
||||||
|
|
||||||
|
namespace ProjectGrid.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
public class UsersController : ControllerBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly ILogger<UsersController> _logger;
|
||||||
|
|
||||||
|
//static readonly Models.IUserRepository repository = new Models.UserRepository();
|
||||||
|
private readonly Models.IUserRepository repository;
|
||||||
|
|
||||||
|
public UsersController(ILogger<UsersController> logger, DataAccessContext context)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
repository = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("api/users")]
|
||||||
|
public IEnumerable<Models.UserModel> GetAllUsers()
|
||||||
|
{
|
||||||
|
return repository.GetAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("api/user")]
|
||||||
|
[Consumes("application/json")]
|
||||||
|
public Models.UserModel PostUser(Models.UserModel item)
|
||||||
|
{
|
||||||
|
return repository.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
export async function getBoard() {
|
||||||
|
|
||||||
|
const response = await fetch('/api/');
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createUser(data) {
|
||||||
|
const response = await fetch(`/api/user`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
})
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue