dev postgresql database integration
This commit is contained in:
@@ -1,40 +1,39 @@
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using agologumApi.Models;
|
||||
using agologumApi.Stores;
|
||||
using agologumApi.Services;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private readonly UserStore store_;
|
||||
private readonly UserService service_;
|
||||
|
||||
public UsersController(UserStore store)
|
||||
public UsersController(UserService service)
|
||||
{
|
||||
store_ = store;
|
||||
service_ = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult<List<User>> getUsers()
|
||||
public async Task<ActionResult<List<User>>> getUsers()
|
||||
{
|
||||
return Ok(store_.getUsers());
|
||||
return Ok(await service_.GetAll());
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public ActionResult<User> getUser(int id)
|
||||
public async Task<ActionResult<User>> getUser(int id)
|
||||
{
|
||||
var user = store_.getUser(id);
|
||||
var user = await service_.Get(id);
|
||||
|
||||
if (user == null)
|
||||
return NotFound();
|
||||
if (user == null) return NotFound();
|
||||
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult<User> createUser(User user)
|
||||
public async Task<ActionResult<User>> createUser(User user)
|
||||
{
|
||||
var created = store_.createUser(user);
|
||||
var created = await service_.Create(user);
|
||||
|
||||
return CreatedAtAction(
|
||||
nameof(getUser),
|
||||
@@ -44,23 +43,21 @@ public class UsersController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public ActionResult<User> updateUser(int id, User user)
|
||||
public async Task<ActionResult<User>> updateUser(int id, User user)
|
||||
{
|
||||
var updated = store_.updateUser(id, user);
|
||||
var updated = await service_.Update(user);
|
||||
|
||||
if (updated == null)
|
||||
return NotFound();
|
||||
if (updated == null) return NotFound();
|
||||
|
||||
return Ok(updated);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public ActionResult deleteUser(int id)
|
||||
public async Task<ActionResult> deleteUser(int id)
|
||||
{
|
||||
var success = store_.deleteUser(id);
|
||||
var success = await service_.Delete(id);
|
||||
|
||||
if (!success)
|
||||
return NotFound();
|
||||
if (success) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user