使用 PostgreSQL 数据库存储数据
This commit is contained in:
1 parent
5e74bc50a9
commit
14b419dbf7
12 files changed
+270
No files matched your search
@@ -0,0 +1,36 @@
|
||||
using HelloShop.IdentityService.Entities;
|
||||
using HelloShop.IdentityService.EntityFrameworks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace HelloShop.IdentityService.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class UsersController(IdentityServiceDbContext dbContext) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IEnumerable<User> Get()
|
||||
{
|
||||
return dbContext.Set<User>();
|
||||
}
|
||||
|
||||
// GET api/<UsersController>/5
|
||||
[HttpGet("{id}")]
|
||||
public User? Get(int id)
|
||||
{
|
||||
return dbContext.Set<User>().Find(id);
|
||||
}
|
||||
|
||||
// POST api/<UsersController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] User value)
|
||||
{
|
||||
value.CreationTime = DateTimeOffset.Now;
|
||||
|
||||
dbContext.Add(value);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user