develop #3

Merged
luolan merged 8 commits from develop into master 2025-07-09 02:01:12 +08:00
8 changed files with 79 additions and 6 deletions
Showing only changes of commit 2daa90af03 - Show all commits

View File

@ -10,13 +10,19 @@
<PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
<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="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Middleware\" />
<Folder Include="Models\DTOs\" />
<Folder Include="Utilities\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@
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"
};
_context.UserModels.Add(user);
await _context.SaveChangesAsync();
return Ok(new ReturnTemplate(200, "成功",user));
}
}

14
AGSS/Models/DBContext.cs Normal file
View 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; }
}

View File

@ -0,0 +1,8 @@
namespace AGSS.Models.Entities;
public class UserModel
{
public Guid Id { get; set; }
public required string AuthId { get; set; }
}

View File

@ -0,0 +1,3 @@
namespace AGSS.Models.Template;
public record ReturnTemplate(int Code, string Msg, object Data);

View File

@ -1,4 +1,6 @@
using AGSS.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
@ -16,10 +18,11 @@ var builder = WebApplication.CreateBuilder(args);
// ¶ÁÈ¡ÅäÖÃ
var domain = builder.Configuration["Auth0:Domain"];
var audience =builder.Configuration["Auth0:Audience"];
builder.Services.AddDbContext<DBContext>(opt =>
opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
@ -59,10 +62,6 @@ app.UseAuthentication();
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();

View File

@ -4,5 +4,14 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Auth0": {
"Domain": "",
"Audience": "",
"ClientId": ""
},
"DataBase": {
"ConnectionString": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
}
}

View File

@ -10,5 +10,8 @@
"Domain": "",
"Audience": "",
"ClientId": ""
},
"ConnectionStrings": {
"DBContext": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
}
}