完善项目结构,构建数据库,构建返回模板
This commit is contained in:
parent
7a562bea62
commit
0b53aceca1
@ -10,13 +10,19 @@
|
|||||||
<PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
|
<PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Controllers\" />
|
<Folder Include="Middleware\" />
|
||||||
|
<Folder Include="Models\DTOs\" />
|
||||||
|
<Folder Include="Utilities\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
33
AGSS/Controllers/User/UserInfoController.cs
Normal file
33
AGSS/Controllers/User/UserInfoController.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using AGSS.Models;
|
||||||
|
using AGSS.Models.Entities;
|
||||||
|
using AGSS.Models.Template;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AGSS.Controllers.User;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
public class UserInfoController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly DBContext _context;
|
||||||
|
|
||||||
|
public UserInfoController(DBContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> My()
|
||||||
|
{
|
||||||
|
UserModel user = new UserModel
|
||||||
|
{
|
||||||
|
AuthId = "123",
|
||||||
|
Email = "123",
|
||||||
|
Password = "111"
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.UserModels.Add(user);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Ok(user);
|
||||||
|
}
|
||||||
|
}
|
14
AGSS/Models/DBContext.cs
Normal file
14
AGSS/Models/DBContext.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using AGSS.Models.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AGSS.Models;
|
||||||
|
|
||||||
|
public class DBContext : DbContext
|
||||||
|
{
|
||||||
|
public DBContext(DbContextOptions<DBContext> options)
|
||||||
|
: base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<UserModel> UserModels { get; set; }
|
||||||
|
}
|
8
AGSS/Models/Entities/User.cs
Normal file
8
AGSS/Models/Entities/User.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace AGSS.Models.Entities;
|
||||||
|
|
||||||
|
public class UserModel
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public required string AuthId { get; set; }
|
||||||
|
|
||||||
|
}
|
8
AGSS/Models/Template/ReturnTemplate.cs
Normal file
8
AGSS/Models/Template/ReturnTemplate.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace AGSS.Models.Template;
|
||||||
|
|
||||||
|
public struct ReturnTemplate
|
||||||
|
{
|
||||||
|
public int Code{get;set;}
|
||||||
|
public string Msg{get;set;}
|
||||||
|
public object Data{get;set;}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
|
using AGSS.Models;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
|
||||||
@ -16,10 +18,11 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ¶ÁÈ¡ÅäÖÃ
|
|
||||||
var domain = builder.Configuration["Auth0:Domain"];
|
var domain = builder.Configuration["Auth0:Domain"];
|
||||||
var audience =builder.Configuration["Auth0:Audience"];
|
var audience =builder.Configuration["Auth0:Audience"];
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<DBContext>(opt =>
|
||||||
|
opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
|
||||||
|
|
||||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.AddJwtBearer(options =>
|
.AddJwtBearer(options =>
|
||||||
@ -59,10 +62,6 @@ app.UseAuthentication();
|
|||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
#pragma warning disable ASP0014 // Suggest using top level route registrations
|
|
||||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
|
||||||
#pragma warning restore ASP0014 // Suggest using top level route registrations
|
|
||||||
|
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
@ -4,5 +4,14 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"Auth0": {
|
||||||
|
"Domain": "",
|
||||||
|
"Audience": "",
|
||||||
|
"ClientId": ""
|
||||||
|
},
|
||||||
|
"DataBase": {
|
||||||
|
"ConnectionString": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,8 @@
|
|||||||
"Domain": "",
|
"Domain": "",
|
||||||
"Audience": "",
|
"Audience": "",
|
||||||
"ClientId": ""
|
"ClientId": ""
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DBContext": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user